@@ -13,191 +13,191 @@ |
||
| 13 | 13 | class EE_Admin_Table_Registration_Line_Item_Display_Strategy extends EE_Admin_Table_Line_Item_Display_Strategy |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Table header for display. |
|
| 18 | - * @since 4.8 |
|
| 19 | - * @param array $options |
|
| 20 | - * @return string |
|
| 21 | - */ |
|
| 22 | - protected function _table_header($options) |
|
| 23 | - { |
|
| 24 | - $html = EEH_HTML::table('', '', $options['table_css_class']); |
|
| 25 | - $html .= EEH_HTML::thead(); |
|
| 26 | - $html .= EEH_HTML::tr(); |
|
| 27 | - $html .= EEH_HTML::th(__('Name', 'event_espresso'), '', 'jst-left'); |
|
| 28 | - $html .= EEH_HTML::th(__('Type', 'event_espresso'), '', 'jst-left'); |
|
| 29 | - $html .= EEH_HTML::th(__('Date(s)', 'event_espresso'), '', 'jst-left'); |
|
| 30 | - $html .= EEH_HTML::th(__('Amount', 'event_espresso'), '', 'jst-cntr'); |
|
| 31 | - $html .= EEH_HTML::tbody(); |
|
| 32 | - return $html; |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * _item_row |
|
| 41 | - * |
|
| 42 | - * @param EE_Line_Item $line_item |
|
| 43 | - * @param array $options |
|
| 44 | - * @return mixed |
|
| 45 | - */ |
|
| 46 | - protected function _item_row(EE_Line_Item $line_item, $options = array()) |
|
| 47 | - { |
|
| 48 | - $line_item_related_object = $line_item->get_object(); |
|
| 49 | - $parent_line_item_related_object = $line_item->parent() instanceof EE_Line_Item |
|
| 50 | - ? $line_item->parent()->get_object() |
|
| 51 | - : null; |
|
| 52 | - // start of row |
|
| 53 | - $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
| 54 | - $html = EEH_HTML::tr('', '', $row_class); |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - // Name Column |
|
| 58 | - $name_link = $line_item_related_object instanceof EEI_Admin_Links ? $line_item_related_object->get_admin_details_link() : ''; |
|
| 59 | - |
|
| 60 | - // related object scope. |
|
| 61 | - $parent_related_object_name = $parent_line_item_related_object instanceof EEI_Line_Item_Object |
|
| 62 | - ? $parent_line_item_related_object->name() |
|
| 63 | - : ''; |
|
| 64 | - $parent_related_object_name = empty($parent_related_object_name) && $line_item->parent() instanceof EE_Line_Item |
|
| 65 | - ? $line_item->parent()->name() |
|
| 66 | - : $parent_related_object_name; |
|
| 67 | - $parent_related_object_link = $parent_line_item_related_object instanceof EEI_Admin_Links |
|
| 68 | - ? $parent_line_item_related_object->get_admin_details_link() |
|
| 69 | - : ''; |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - $name_html = $line_item_related_object instanceof EEI_Line_Item_Object |
|
| 73 | - ? $line_item_related_object->name() : $line_item->name(); |
|
| 74 | - $name_html = $name_link ? '<a href="' . $name_link . '">' . $name_html . '</a>' |
|
| 75 | - : $name_html; |
|
| 76 | - $name_html .= $line_item->is_taxable() ? ' *' : ''; |
|
| 77 | - // maybe preface with icon? |
|
| 78 | - $name_html = $line_item_related_object instanceof EEI_Has_Icon |
|
| 79 | - ? $line_item_related_object->get_icon() . $name_html |
|
| 80 | - : $name_html; |
|
| 81 | - $name_html = '<span class="ee-line-item-name linked">' . $name_html . '</span><br>'; |
|
| 82 | - $name_html .= sprintf( |
|
| 83 | - _x('%1$sfor the %2$s: %3$s%4$s', 'eg. "for the Event: My Cool Event"', 'event_espresso'), |
|
| 84 | - '<span class="ee-line-item-related-parent-object">', |
|
| 85 | - $line_item->parent() instanceof EE_Line_Item |
|
| 86 | - ? $line_item->parent()->OBJ_type_i18n() |
|
| 87 | - : __('Item:', 'event_espresso'), |
|
| 88 | - $parent_related_object_link |
|
| 89 | - ? '<a href="' . $parent_related_object_link . '">' . $parent_related_object_name . '</a>' |
|
| 90 | - : $parent_related_object_name, |
|
| 91 | - '</span>' |
|
| 92 | - ); |
|
| 93 | - |
|
| 94 | - $name_html = apply_filters( |
|
| 95 | - 'FHEE__EE_Admin_Table_Registration_Line_Item_Display_Strategy___item_row__name_html', |
|
| 96 | - $name_html, |
|
| 97 | - $line_item, |
|
| 98 | - $options |
|
| 99 | - ); |
|
| 16 | + /** |
|
| 17 | + * Table header for display. |
|
| 18 | + * @since 4.8 |
|
| 19 | + * @param array $options |
|
| 20 | + * @return string |
|
| 21 | + */ |
|
| 22 | + protected function _table_header($options) |
|
| 23 | + { |
|
| 24 | + $html = EEH_HTML::table('', '', $options['table_css_class']); |
|
| 25 | + $html .= EEH_HTML::thead(); |
|
| 26 | + $html .= EEH_HTML::tr(); |
|
| 27 | + $html .= EEH_HTML::th(__('Name', 'event_espresso'), '', 'jst-left'); |
|
| 28 | + $html .= EEH_HTML::th(__('Type', 'event_espresso'), '', 'jst-left'); |
|
| 29 | + $html .= EEH_HTML::th(__('Date(s)', 'event_espresso'), '', 'jst-left'); |
|
| 30 | + $html .= EEH_HTML::th(__('Amount', 'event_espresso'), '', 'jst-cntr'); |
|
| 31 | + $html .= EEH_HTML::tbody(); |
|
| 32 | + return $html; |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * _item_row |
|
| 41 | + * |
|
| 42 | + * @param EE_Line_Item $line_item |
|
| 43 | + * @param array $options |
|
| 44 | + * @return mixed |
|
| 45 | + */ |
|
| 46 | + protected function _item_row(EE_Line_Item $line_item, $options = array()) |
|
| 47 | + { |
|
| 48 | + $line_item_related_object = $line_item->get_object(); |
|
| 49 | + $parent_line_item_related_object = $line_item->parent() instanceof EE_Line_Item |
|
| 50 | + ? $line_item->parent()->get_object() |
|
| 51 | + : null; |
|
| 52 | + // start of row |
|
| 53 | + $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
| 54 | + $html = EEH_HTML::tr('', '', $row_class); |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + // Name Column |
|
| 58 | + $name_link = $line_item_related_object instanceof EEI_Admin_Links ? $line_item_related_object->get_admin_details_link() : ''; |
|
| 59 | + |
|
| 60 | + // related object scope. |
|
| 61 | + $parent_related_object_name = $parent_line_item_related_object instanceof EEI_Line_Item_Object |
|
| 62 | + ? $parent_line_item_related_object->name() |
|
| 63 | + : ''; |
|
| 64 | + $parent_related_object_name = empty($parent_related_object_name) && $line_item->parent() instanceof EE_Line_Item |
|
| 65 | + ? $line_item->parent()->name() |
|
| 66 | + : $parent_related_object_name; |
|
| 67 | + $parent_related_object_link = $parent_line_item_related_object instanceof EEI_Admin_Links |
|
| 68 | + ? $parent_line_item_related_object->get_admin_details_link() |
|
| 69 | + : ''; |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + $name_html = $line_item_related_object instanceof EEI_Line_Item_Object |
|
| 73 | + ? $line_item_related_object->name() : $line_item->name(); |
|
| 74 | + $name_html = $name_link ? '<a href="' . $name_link . '">' . $name_html . '</a>' |
|
| 75 | + : $name_html; |
|
| 76 | + $name_html .= $line_item->is_taxable() ? ' *' : ''; |
|
| 77 | + // maybe preface with icon? |
|
| 78 | + $name_html = $line_item_related_object instanceof EEI_Has_Icon |
|
| 79 | + ? $line_item_related_object->get_icon() . $name_html |
|
| 80 | + : $name_html; |
|
| 81 | + $name_html = '<span class="ee-line-item-name linked">' . $name_html . '</span><br>'; |
|
| 82 | + $name_html .= sprintf( |
|
| 83 | + _x('%1$sfor the %2$s: %3$s%4$s', 'eg. "for the Event: My Cool Event"', 'event_espresso'), |
|
| 84 | + '<span class="ee-line-item-related-parent-object">', |
|
| 85 | + $line_item->parent() instanceof EE_Line_Item |
|
| 86 | + ? $line_item->parent()->OBJ_type_i18n() |
|
| 87 | + : __('Item:', 'event_espresso'), |
|
| 88 | + $parent_related_object_link |
|
| 89 | + ? '<a href="' . $parent_related_object_link . '">' . $parent_related_object_name . '</a>' |
|
| 90 | + : $parent_related_object_name, |
|
| 91 | + '</span>' |
|
| 92 | + ); |
|
| 93 | + |
|
| 94 | + $name_html = apply_filters( |
|
| 95 | + 'FHEE__EE_Admin_Table_Registration_Line_Item_Display_Strategy___item_row__name_html', |
|
| 96 | + $name_html, |
|
| 97 | + $line_item, |
|
| 98 | + $options |
|
| 99 | + ); |
|
| 100 | 100 | |
| 101 | - $html .= EEH_HTML::td($name_html, '', 'jst-left'); |
|
| 102 | - // Type Column |
|
| 103 | - $type_html = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() : ''; |
|
| 104 | - $type_html .= $this->_get_cancellations($line_item); |
|
| 105 | - $type_html .= $line_item->OBJ_type() ? '<br />' : ''; |
|
| 106 | - $code = $line_item_related_object instanceof EEI_Has_Code ? $line_item_related_object->code() : ''; |
|
| 107 | - $type_html .= ! empty($code) ? '<span class="ee-line-item-id">' . sprintf(__('Code: %s', 'event_espresso'), $code) . '</span>' : ''; |
|
| 108 | - $html .= EEH_HTML::td($type_html, '', 'jst-left'); |
|
| 109 | - |
|
| 110 | - // Date column |
|
| 111 | - $datetime_content = ''; |
|
| 112 | - if ($line_item_related_object instanceof EE_Ticket) { |
|
| 113 | - $datetimes = $line_item_related_object->datetimes(); |
|
| 114 | - foreach ($datetimes as $datetime) { |
|
| 115 | - if ($datetime instanceof EE_Datetime) { |
|
| 116 | - $datetime_content .= $datetime->get_dtt_display_name() . '<br>'; |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - $html .= EEH_HTML::td($datetime_content, '', 'jst-left'); |
|
| 121 | - |
|
| 122 | - // Amount Column |
|
| 123 | - if ($line_item->is_percent()) { |
|
| 124 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', 'jst-rght'); |
|
| 125 | - } else { |
|
| 126 | - $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'jst-rght'); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - // finish things off and return |
|
| 131 | - $html .= EEH_HTML::trx(); |
|
| 132 | - return $html; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * _tax_row |
|
| 139 | - * |
|
| 140 | - * @param EE_Line_Item $line_item |
|
| 141 | - * @param array $options |
|
| 142 | - * @return mixed |
|
| 143 | - */ |
|
| 144 | - protected function _tax_row(EE_Line_Item $line_item, $options = array()) |
|
| 145 | - { |
|
| 146 | - // start of row |
|
| 147 | - $html = EEH_HTML::tr('', 'admin-primary-mbox-taxes-tr'); |
|
| 148 | - // name th |
|
| 149 | - $html .= EEH_HTML::th($line_item->name() . '(' . $line_item->get_pretty('LIN_percent') . '%)', '', 'jst-rght', '', ' colspan="3"'); |
|
| 150 | - // total th |
|
| 151 | - $html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght'); |
|
| 152 | - // end of row |
|
| 153 | - $html .= EEH_HTML::trx(); |
|
| 154 | - return $html; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - |
|
| 159 | - |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * _total_row |
|
| 163 | - * |
|
| 164 | - * @param EE_Line_Item $line_item |
|
| 165 | - * @param array $options |
|
| 166 | - * @return mixed |
|
| 167 | - */ |
|
| 168 | - protected function _total_row(EE_Line_Item $line_item, $options = array()) |
|
| 169 | - { |
|
| 170 | - |
|
| 171 | - $registration = isset($options['EE_Registration']) ? $options['EE_Registration'] : null; |
|
| 172 | - $registration_total = $registration instanceof EE_Registration ? $registration->pretty_final_price() : 0; |
|
| 173 | - // if no valid registration object then we're not going to show the approximate text. |
|
| 174 | - $total_match = $registration instanceof EE_Registration |
|
| 175 | - ? $registration->final_price() === $line_item->total() |
|
| 176 | - : true; |
|
| 177 | - |
|
| 178 | - // start of row |
|
| 179 | - $html = EEH_HTML::tr('', '', 'admin-primary-mbox-total-tr'); |
|
| 180 | - // Total th label |
|
| 181 | - if ($total_match) { |
|
| 182 | - $total_label = sprintf(__('This registration\'s total %s:', 'event_espresso'), '(' . EE_Registry::instance()->CFG->currency->code . ')'); |
|
| 183 | - } else { |
|
| 184 | - $total_label = sprintf(__('This registration\'s approximate total %s', 'event_espresso'), '(' . EE_Registry::instance()->CFG->currency->code . ')'); |
|
| 185 | - $total_label .= '<br>'; |
|
| 186 | - $total_label .= '<p class="ee-footnote-text">' |
|
| 187 | - . sprintf( |
|
| 188 | - __('The registrations\' share of the transaction total is approximate because it might not be possible to evenly divide the transaction total among each registration, and so some registrations may need to pay a penny more than others. This registration\'s final share is actually %1$s%2$s%3$s.', 'event_espresso'), |
|
| 189 | - '<strong>', |
|
| 190 | - $registration_total, |
|
| 191 | - '</strong>' |
|
| 192 | - ) |
|
| 193 | - . '</p>'; |
|
| 194 | - } |
|
| 195 | - $html .= EEH_HTML::th($total_label, '', 'jst-rght', '', ' colspan="3"'); |
|
| 196 | - // total th |
|
| 197 | - |
|
| 198 | - $html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght'); |
|
| 199 | - // end of row |
|
| 200 | - $html .= EEH_HTML::trx(); |
|
| 201 | - return $html; |
|
| 202 | - } |
|
| 101 | + $html .= EEH_HTML::td($name_html, '', 'jst-left'); |
|
| 102 | + // Type Column |
|
| 103 | + $type_html = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() : ''; |
|
| 104 | + $type_html .= $this->_get_cancellations($line_item); |
|
| 105 | + $type_html .= $line_item->OBJ_type() ? '<br />' : ''; |
|
| 106 | + $code = $line_item_related_object instanceof EEI_Has_Code ? $line_item_related_object->code() : ''; |
|
| 107 | + $type_html .= ! empty($code) ? '<span class="ee-line-item-id">' . sprintf(__('Code: %s', 'event_espresso'), $code) . '</span>' : ''; |
|
| 108 | + $html .= EEH_HTML::td($type_html, '', 'jst-left'); |
|
| 109 | + |
|
| 110 | + // Date column |
|
| 111 | + $datetime_content = ''; |
|
| 112 | + if ($line_item_related_object instanceof EE_Ticket) { |
|
| 113 | + $datetimes = $line_item_related_object->datetimes(); |
|
| 114 | + foreach ($datetimes as $datetime) { |
|
| 115 | + if ($datetime instanceof EE_Datetime) { |
|
| 116 | + $datetime_content .= $datetime->get_dtt_display_name() . '<br>'; |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + $html .= EEH_HTML::td($datetime_content, '', 'jst-left'); |
|
| 121 | + |
|
| 122 | + // Amount Column |
|
| 123 | + if ($line_item->is_percent()) { |
|
| 124 | + $html .= EEH_HTML::td($line_item->percent() . '%', '', 'jst-rght'); |
|
| 125 | + } else { |
|
| 126 | + $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'jst-rght'); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + // finish things off and return |
|
| 131 | + $html .= EEH_HTML::trx(); |
|
| 132 | + return $html; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * _tax_row |
|
| 139 | + * |
|
| 140 | + * @param EE_Line_Item $line_item |
|
| 141 | + * @param array $options |
|
| 142 | + * @return mixed |
|
| 143 | + */ |
|
| 144 | + protected function _tax_row(EE_Line_Item $line_item, $options = array()) |
|
| 145 | + { |
|
| 146 | + // start of row |
|
| 147 | + $html = EEH_HTML::tr('', 'admin-primary-mbox-taxes-tr'); |
|
| 148 | + // name th |
|
| 149 | + $html .= EEH_HTML::th($line_item->name() . '(' . $line_item->get_pretty('LIN_percent') . '%)', '', 'jst-rght', '', ' colspan="3"'); |
|
| 150 | + // total th |
|
| 151 | + $html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght'); |
|
| 152 | + // end of row |
|
| 153 | + $html .= EEH_HTML::trx(); |
|
| 154 | + return $html; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + |
|
| 159 | + |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * _total_row |
|
| 163 | + * |
|
| 164 | + * @param EE_Line_Item $line_item |
|
| 165 | + * @param array $options |
|
| 166 | + * @return mixed |
|
| 167 | + */ |
|
| 168 | + protected function _total_row(EE_Line_Item $line_item, $options = array()) |
|
| 169 | + { |
|
| 170 | + |
|
| 171 | + $registration = isset($options['EE_Registration']) ? $options['EE_Registration'] : null; |
|
| 172 | + $registration_total = $registration instanceof EE_Registration ? $registration->pretty_final_price() : 0; |
|
| 173 | + // if no valid registration object then we're not going to show the approximate text. |
|
| 174 | + $total_match = $registration instanceof EE_Registration |
|
| 175 | + ? $registration->final_price() === $line_item->total() |
|
| 176 | + : true; |
|
| 177 | + |
|
| 178 | + // start of row |
|
| 179 | + $html = EEH_HTML::tr('', '', 'admin-primary-mbox-total-tr'); |
|
| 180 | + // Total th label |
|
| 181 | + if ($total_match) { |
|
| 182 | + $total_label = sprintf(__('This registration\'s total %s:', 'event_espresso'), '(' . EE_Registry::instance()->CFG->currency->code . ')'); |
|
| 183 | + } else { |
|
| 184 | + $total_label = sprintf(__('This registration\'s approximate total %s', 'event_espresso'), '(' . EE_Registry::instance()->CFG->currency->code . ')'); |
|
| 185 | + $total_label .= '<br>'; |
|
| 186 | + $total_label .= '<p class="ee-footnote-text">' |
|
| 187 | + . sprintf( |
|
| 188 | + __('The registrations\' share of the transaction total is approximate because it might not be possible to evenly divide the transaction total among each registration, and so some registrations may need to pay a penny more than others. This registration\'s final share is actually %1$s%2$s%3$s.', 'event_espresso'), |
|
| 189 | + '<strong>', |
|
| 190 | + $registration_total, |
|
| 191 | + '</strong>' |
|
| 192 | + ) |
|
| 193 | + . '</p>'; |
|
| 194 | + } |
|
| 195 | + $html .= EEH_HTML::th($total_label, '', 'jst-rght', '', ' colspan="3"'); |
|
| 196 | + // total th |
|
| 197 | + |
|
| 198 | + $html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght'); |
|
| 199 | + // end of row |
|
| 200 | + $html .= EEH_HTML::trx(); |
|
| 201 | + return $html; |
|
| 202 | + } |
|
| 203 | 203 | } |
@@ -14,332 +14,332 @@ |
||
| 14 | 14 | { |
| 15 | 15 | |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * whether to display the taxes row or not |
|
| 19 | - * @type bool $_show_taxes |
|
| 20 | - */ |
|
| 21 | - protected $_show_taxes = false; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * html for any tax rows |
|
| 25 | - * @type string $_show_taxes |
|
| 26 | - */ |
|
| 27 | - protected $_taxes_html = ''; |
|
| 28 | - |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * total amount including tax we can bill for at this time |
|
| 32 | - * @type float $_grand_total |
|
| 33 | - */ |
|
| 34 | - protected $_grand_total = 0.00; |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @return float |
|
| 40 | - */ |
|
| 41 | - public function grand_total() |
|
| 42 | - { |
|
| 43 | - return $this->_grand_total; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * This is used to output a single |
|
| 50 | - * @param EE_Line_Item $line_item |
|
| 51 | - * @param array $options |
|
| 52 | - * @return mixed |
|
| 53 | - */ |
|
| 54 | - public function display_line_item(EE_Line_Item $line_item, $options = array()) |
|
| 55 | - { |
|
| 56 | - |
|
| 57 | - $html = ''; |
|
| 58 | - // set some default options and merge with incoming |
|
| 59 | - $default_options = array( |
|
| 60 | - 'odd' => true, |
|
| 61 | - 'use_table_wrapper' => true, |
|
| 62 | - 'table_css_class' => 'admin-primary-mbox-tbl', |
|
| 63 | - 'taxes_tr_css_class' => 'admin-primary-mbox-taxes-tr', |
|
| 64 | - 'total_tr_css_class' => 'admin-primary-mbox-total-tr' |
|
| 65 | - ); |
|
| 66 | - $options = array_merge($default_options, (array) $options); |
|
| 67 | - |
|
| 68 | - switch ($line_item->type()) { |
|
| 69 | - case EEM_Line_Item::type_line_item: |
|
| 70 | - // item row |
|
| 71 | - $html .= $this->_item_row($line_item, $options); |
|
| 72 | - break; |
|
| 73 | - |
|
| 74 | - case EEM_Line_Item::type_sub_line_item: |
|
| 75 | - $html .= $this->_sub_item_row($line_item, $options); |
|
| 76 | - break; |
|
| 77 | - |
|
| 78 | - case EEM_Line_Item::type_sub_total: |
|
| 79 | - if ($line_item->quantity() === 0) { |
|
| 80 | - return $html; |
|
| 81 | - } |
|
| 82 | - // loop through children |
|
| 83 | - $child_line_items = $line_item->children(); |
|
| 84 | - // loop through children |
|
| 85 | - foreach ($child_line_items as $child_line_item) { |
|
| 86 | - // recursively feed children back into this method |
|
| 87 | - $html .= $this->display_line_item($child_line_item, $options); |
|
| 88 | - } |
|
| 89 | - $html .= $this->_sub_total_row($line_item, $options); |
|
| 90 | - break; |
|
| 91 | - |
|
| 92 | - case EEM_Line_Item::type_tax: |
|
| 93 | - if ($this->_show_taxes) { |
|
| 94 | - $this->_taxes_html .= $this->_tax_row($line_item, $options); |
|
| 95 | - } |
|
| 96 | - break; |
|
| 97 | - |
|
| 98 | - case EEM_Line_Item::type_tax_sub_total: |
|
| 99 | - foreach ($line_item->children() as $child_line_item) { |
|
| 100 | - if ($child_line_item->type() == EEM_Line_Item::type_tax) { |
|
| 101 | - $this->display_line_item($child_line_item, $options); |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - break; |
|
| 105 | - |
|
| 106 | - case EEM_Line_Item::type_total: |
|
| 107 | - // determine whether to display taxes or not |
|
| 108 | - $this->_show_taxes = $line_item->get_total_tax() > 0 ? true : false; |
|
| 109 | - // get all child line items |
|
| 110 | - $children = $line_item->children(); |
|
| 111 | - |
|
| 112 | - // loop thru all non-tax child line items |
|
| 113 | - foreach ($children as $child_line_item) { |
|
| 114 | - $html .= $this->display_line_item($child_line_item, $options); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - $html .= $this->_taxes_html; |
|
| 118 | - $html .= $this->_total_row($line_item, $options); |
|
| 119 | - if ($options['use_table_wrapper']) { |
|
| 120 | - $html = $this->_table_header($options) . $html . $this->_table_footer($options); |
|
| 121 | - } |
|
| 122 | - break; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - return $html; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * Table header for display. |
|
| 132 | - * @since 4.8 |
|
| 133 | - * @param array $options |
|
| 134 | - * @return string |
|
| 135 | - */ |
|
| 136 | - protected function _table_header($options) |
|
| 137 | - { |
|
| 138 | - $html = EEH_HTML::table('', '', $options['table_css_class']); |
|
| 139 | - $html .= EEH_HTML::thead(); |
|
| 140 | - $html .= EEH_HTML::tr(); |
|
| 141 | - $html .= EEH_HTML::th(__('Name', 'event_espresso'), '', 'jst-left'); |
|
| 142 | - $html .= EEH_HTML::th(__('Type', 'event_espresso'), '', 'jst-left'); |
|
| 143 | - $html .= EEH_HTML::th(__('Amount', 'event_espresso'), '', 'jst-cntr'); |
|
| 144 | - $html .= EEH_HTML::th(__('Qty', 'event_espresso'), '', 'jst-cntr'); |
|
| 145 | - $html .= EEH_HTML::th(__('Line Total', 'event_espresso'), '', 'jst-cntr'); |
|
| 146 | - $html .= EEH_HTML::tbody(); |
|
| 147 | - return $html; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * Table footer for display |
|
| 153 | - * @since 4.8 |
|
| 154 | - * @param array $options array of options for the table. |
|
| 155 | - * @return string |
|
| 156 | - */ |
|
| 157 | - protected function _table_footer($options) |
|
| 158 | - { |
|
| 159 | - return EEH_HTML::tbodyx() . EEH_HTML::tablex(); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * _item_row |
|
| 166 | - * |
|
| 167 | - * @param EE_Line_Item $line_item |
|
| 168 | - * @param array $options |
|
| 169 | - * @return mixed |
|
| 170 | - */ |
|
| 171 | - protected function _item_row(EE_Line_Item $line_item, $options = array()) |
|
| 172 | - { |
|
| 173 | - $line_item_related_object = $line_item->get_object(); |
|
| 174 | - $parent_line_item_related_object = $line_item->parent() instanceof EE_Line_Item ? $line_item->parent()->get_object() : null; |
|
| 175 | - // start of row |
|
| 176 | - $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
| 177 | - $html = EEH_HTML::tr('', '', $row_class); |
|
| 178 | - |
|
| 179 | - |
|
| 180 | - // Name Column |
|
| 181 | - $name_link = $line_item_related_object instanceof EEI_Admin_Links ? $line_item_related_object->get_admin_details_link() : ''; |
|
| 182 | - |
|
| 183 | - // related object scope. |
|
| 184 | - $parent_related_object_name = $parent_line_item_related_object instanceof EEI_Line_Item_Object ? $parent_line_item_related_object->name() : ''; |
|
| 185 | - $parent_related_object_name = empty($parent_related_object_name) && $line_item->parent() instanceof EE_Line_Item ? $line_item->parent()->name() : $parent_related_object_name; |
|
| 186 | - $parent_related_object_link = $parent_line_item_related_object instanceof EEI_Admin_Links ? $parent_line_item_related_object->get_admin_details_link() : ''; |
|
| 187 | - |
|
| 188 | - |
|
| 189 | - $name_html = $line_item_related_object instanceof EEI_Line_Item_Object ? $line_item_related_object->name() : $line_item->name(); |
|
| 190 | - $name_html = $name_link ? '<a href="' . $name_link . '">' . $name_html . '</a>' : $name_html; |
|
| 191 | - $name_html .= $line_item->is_taxable() ? ' *' : ''; |
|
| 192 | - // maybe preface with icon? |
|
| 193 | - $name_html = $line_item_related_object instanceof EEI_Has_Icon ? $line_item_related_object->get_icon() . $name_html : $name_html; |
|
| 194 | - $name_html = '<span class="ee-line-item-name linked">' . $name_html . '</span><br>'; |
|
| 195 | - $name_html .= sprintf( |
|
| 196 | - _x('%1$sfor the %2$s: %3$s%4$s', 'eg. "for the Event: My Cool Event"', 'event_espresso'), |
|
| 197 | - '<span class="ee-line-item-related-parent-object">', |
|
| 198 | - $line_item->parent() instanceof EE_Line_Item ? $line_item->parent()->OBJ_type_i18n() : __('Item:', 'event_espresso'), |
|
| 199 | - $parent_related_object_link ? '<a href="' . $parent_related_object_link . '">' . $parent_related_object_name . '</a>' : $parent_related_object_name, |
|
| 200 | - '</span>' |
|
| 201 | - ); |
|
| 202 | - |
|
| 203 | - $name_html = apply_filters( |
|
| 204 | - 'FHEE__EE_Admin_Table_Line_Item_Display_Strategy___item_row__name_html', |
|
| 205 | - $name_html, |
|
| 206 | - $line_item, |
|
| 207 | - $options |
|
| 208 | - ); |
|
| 209 | - |
|
| 210 | - $html .= EEH_HTML::td($name_html, '', 'jst-left'); |
|
| 211 | - // Type Column |
|
| 212 | - $type_html = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() : ''; |
|
| 213 | - $type_html .= $this->_get_cancellations($line_item); |
|
| 214 | - $type_html .= $line_item->OBJ_type() ? '<br />' : ''; |
|
| 215 | - $code = $line_item_related_object instanceof EEI_Has_Code ? $line_item_related_object->code() : ''; |
|
| 216 | - $type_html .= ! empty($code) ? '<span class="ee-line-item-id">' . sprintf(__('Code: %s', 'event_espresso'), $code) . '</span>' : ''; |
|
| 217 | - $html .= EEH_HTML::td($type_html, '', 'jst-left'); |
|
| 218 | - |
|
| 219 | - |
|
| 220 | - // Amount Column |
|
| 221 | - if ($line_item->is_percent()) { |
|
| 222 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', 'jst-rght'); |
|
| 223 | - } else { |
|
| 224 | - $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'jst-rght'); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - // QTY column |
|
| 228 | - $html .= EEH_HTML::td($line_item->quantity(), '', 'jst-rght'); |
|
| 229 | - |
|
| 230 | - // total column |
|
| 231 | - $html .= EEH_HTML::td(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght'); |
|
| 232 | - |
|
| 233 | - // finish things off and return |
|
| 234 | - $html .= EEH_HTML::trx(); |
|
| 235 | - return $html; |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * _get_cancellations |
|
| 242 | - * |
|
| 243 | - * @param EE_Line_Item $line_item |
|
| 244 | - * @return string |
|
| 245 | - */ |
|
| 246 | - protected function _get_cancellations(EE_Line_Item $line_item) |
|
| 247 | - { |
|
| 248 | - $html = ''; |
|
| 249 | - $cancellations = $line_item->get_cancellations(); |
|
| 250 | - $cancellation = reset($cancellations); |
|
| 251 | - // \EEH_Debug_Tools::printr( $cancellation, '$cancellation', __FILE__, __LINE__ ); |
|
| 252 | - if ($cancellation instanceof EE_Line_Item) { |
|
| 253 | - $html .= ' <span class="ee-line-item-id">'; |
|
| 254 | - $html .= sprintf( |
|
| 255 | - _n( |
|
| 256 | - '(%1$s Cancellation)', |
|
| 257 | - '(%1$s Cancellations)', |
|
| 258 | - $cancellation->quantity(), |
|
| 259 | - 'event_espresso' |
|
| 260 | - ), |
|
| 261 | - $cancellation->quantity() |
|
| 262 | - ); |
|
| 263 | - $html .= '</span>'; |
|
| 264 | - } |
|
| 265 | - return $html; |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * _sub_item_row |
|
| 272 | - * |
|
| 273 | - * @param EE_Line_Item $line_item |
|
| 274 | - * @param array $options |
|
| 275 | - * @return mixed |
|
| 276 | - */ |
|
| 277 | - protected function _sub_item_row(EE_Line_Item $line_item, $options = array()) |
|
| 278 | - { |
|
| 279 | - // for now we're not showing sub-items |
|
| 280 | - return ''; |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * _tax_row |
|
| 287 | - * |
|
| 288 | - * @param EE_Line_Item $line_item |
|
| 289 | - * @param array $options |
|
| 290 | - * @return mixed |
|
| 291 | - */ |
|
| 292 | - protected function _tax_row(EE_Line_Item $line_item, $options = array()) |
|
| 293 | - { |
|
| 294 | - // start of row |
|
| 295 | - $html = EEH_HTML::tr('', 'admin-primary-mbox-taxes-tr'); |
|
| 296 | - // name th |
|
| 297 | - $html .= EEH_HTML::th($line_item->name() . '(' . $line_item->get_pretty('LIN_percent') . '%)', '', 'jst-rght', '', ' colspan="4"'); |
|
| 298 | - // total th |
|
| 299 | - $html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght'); |
|
| 300 | - // end of row |
|
| 301 | - $html .= EEH_HTML::trx(); |
|
| 302 | - return $html; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - |
|
| 306 | - |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * _total_row |
|
| 310 | - * |
|
| 311 | - * @param EE_Line_Item $line_item |
|
| 312 | - * @param string $text |
|
| 313 | - * @param array $options |
|
| 314 | - * @return mixed |
|
| 315 | - */ |
|
| 316 | - protected function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array()) |
|
| 317 | - { |
|
| 318 | - // currently not showing subtotal row |
|
| 319 | - return ''; |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - |
|
| 323 | - |
|
| 324 | - /** |
|
| 325 | - * _total_row |
|
| 326 | - * |
|
| 327 | - * @param EE_Line_Item $line_item |
|
| 328 | - * @param array $options |
|
| 329 | - * @return mixed |
|
| 330 | - */ |
|
| 331 | - protected function _total_row(EE_Line_Item $line_item, $options = array()) |
|
| 332 | - { |
|
| 333 | - // start of row |
|
| 334 | - $html = EEH_HTML::tr('', '', 'admin-primary-mbox-total-tr'); |
|
| 335 | - // Total th label |
|
| 336 | - $total_label = sprintf(__('Transaction Total %s', 'event_espresso'), '(' . EE_Registry::instance()->CFG->currency->code . ')'); |
|
| 337 | - $html .= EEH_HTML::th($total_label, '', 'jst-rght', '', ' colspan="4"'); |
|
| 338 | - // total th |
|
| 339 | - |
|
| 340 | - $html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght'); |
|
| 341 | - // end of row |
|
| 342 | - $html .= EEH_HTML::trx(); |
|
| 343 | - return $html; |
|
| 344 | - } |
|
| 17 | + /** |
|
| 18 | + * whether to display the taxes row or not |
|
| 19 | + * @type bool $_show_taxes |
|
| 20 | + */ |
|
| 21 | + protected $_show_taxes = false; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * html for any tax rows |
|
| 25 | + * @type string $_show_taxes |
|
| 26 | + */ |
|
| 27 | + protected $_taxes_html = ''; |
|
| 28 | + |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * total amount including tax we can bill for at this time |
|
| 32 | + * @type float $_grand_total |
|
| 33 | + */ |
|
| 34 | + protected $_grand_total = 0.00; |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @return float |
|
| 40 | + */ |
|
| 41 | + public function grand_total() |
|
| 42 | + { |
|
| 43 | + return $this->_grand_total; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * This is used to output a single |
|
| 50 | + * @param EE_Line_Item $line_item |
|
| 51 | + * @param array $options |
|
| 52 | + * @return mixed |
|
| 53 | + */ |
|
| 54 | + public function display_line_item(EE_Line_Item $line_item, $options = array()) |
|
| 55 | + { |
|
| 56 | + |
|
| 57 | + $html = ''; |
|
| 58 | + // set some default options and merge with incoming |
|
| 59 | + $default_options = array( |
|
| 60 | + 'odd' => true, |
|
| 61 | + 'use_table_wrapper' => true, |
|
| 62 | + 'table_css_class' => 'admin-primary-mbox-tbl', |
|
| 63 | + 'taxes_tr_css_class' => 'admin-primary-mbox-taxes-tr', |
|
| 64 | + 'total_tr_css_class' => 'admin-primary-mbox-total-tr' |
|
| 65 | + ); |
|
| 66 | + $options = array_merge($default_options, (array) $options); |
|
| 67 | + |
|
| 68 | + switch ($line_item->type()) { |
|
| 69 | + case EEM_Line_Item::type_line_item: |
|
| 70 | + // item row |
|
| 71 | + $html .= $this->_item_row($line_item, $options); |
|
| 72 | + break; |
|
| 73 | + |
|
| 74 | + case EEM_Line_Item::type_sub_line_item: |
|
| 75 | + $html .= $this->_sub_item_row($line_item, $options); |
|
| 76 | + break; |
|
| 77 | + |
|
| 78 | + case EEM_Line_Item::type_sub_total: |
|
| 79 | + if ($line_item->quantity() === 0) { |
|
| 80 | + return $html; |
|
| 81 | + } |
|
| 82 | + // loop through children |
|
| 83 | + $child_line_items = $line_item->children(); |
|
| 84 | + // loop through children |
|
| 85 | + foreach ($child_line_items as $child_line_item) { |
|
| 86 | + // recursively feed children back into this method |
|
| 87 | + $html .= $this->display_line_item($child_line_item, $options); |
|
| 88 | + } |
|
| 89 | + $html .= $this->_sub_total_row($line_item, $options); |
|
| 90 | + break; |
|
| 91 | + |
|
| 92 | + case EEM_Line_Item::type_tax: |
|
| 93 | + if ($this->_show_taxes) { |
|
| 94 | + $this->_taxes_html .= $this->_tax_row($line_item, $options); |
|
| 95 | + } |
|
| 96 | + break; |
|
| 97 | + |
|
| 98 | + case EEM_Line_Item::type_tax_sub_total: |
|
| 99 | + foreach ($line_item->children() as $child_line_item) { |
|
| 100 | + if ($child_line_item->type() == EEM_Line_Item::type_tax) { |
|
| 101 | + $this->display_line_item($child_line_item, $options); |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + break; |
|
| 105 | + |
|
| 106 | + case EEM_Line_Item::type_total: |
|
| 107 | + // determine whether to display taxes or not |
|
| 108 | + $this->_show_taxes = $line_item->get_total_tax() > 0 ? true : false; |
|
| 109 | + // get all child line items |
|
| 110 | + $children = $line_item->children(); |
|
| 111 | + |
|
| 112 | + // loop thru all non-tax child line items |
|
| 113 | + foreach ($children as $child_line_item) { |
|
| 114 | + $html .= $this->display_line_item($child_line_item, $options); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + $html .= $this->_taxes_html; |
|
| 118 | + $html .= $this->_total_row($line_item, $options); |
|
| 119 | + if ($options['use_table_wrapper']) { |
|
| 120 | + $html = $this->_table_header($options) . $html . $this->_table_footer($options); |
|
| 121 | + } |
|
| 122 | + break; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + return $html; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * Table header for display. |
|
| 132 | + * @since 4.8 |
|
| 133 | + * @param array $options |
|
| 134 | + * @return string |
|
| 135 | + */ |
|
| 136 | + protected function _table_header($options) |
|
| 137 | + { |
|
| 138 | + $html = EEH_HTML::table('', '', $options['table_css_class']); |
|
| 139 | + $html .= EEH_HTML::thead(); |
|
| 140 | + $html .= EEH_HTML::tr(); |
|
| 141 | + $html .= EEH_HTML::th(__('Name', 'event_espresso'), '', 'jst-left'); |
|
| 142 | + $html .= EEH_HTML::th(__('Type', 'event_espresso'), '', 'jst-left'); |
|
| 143 | + $html .= EEH_HTML::th(__('Amount', 'event_espresso'), '', 'jst-cntr'); |
|
| 144 | + $html .= EEH_HTML::th(__('Qty', 'event_espresso'), '', 'jst-cntr'); |
|
| 145 | + $html .= EEH_HTML::th(__('Line Total', 'event_espresso'), '', 'jst-cntr'); |
|
| 146 | + $html .= EEH_HTML::tbody(); |
|
| 147 | + return $html; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * Table footer for display |
|
| 153 | + * @since 4.8 |
|
| 154 | + * @param array $options array of options for the table. |
|
| 155 | + * @return string |
|
| 156 | + */ |
|
| 157 | + protected function _table_footer($options) |
|
| 158 | + { |
|
| 159 | + return EEH_HTML::tbodyx() . EEH_HTML::tablex(); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * _item_row |
|
| 166 | + * |
|
| 167 | + * @param EE_Line_Item $line_item |
|
| 168 | + * @param array $options |
|
| 169 | + * @return mixed |
|
| 170 | + */ |
|
| 171 | + protected function _item_row(EE_Line_Item $line_item, $options = array()) |
|
| 172 | + { |
|
| 173 | + $line_item_related_object = $line_item->get_object(); |
|
| 174 | + $parent_line_item_related_object = $line_item->parent() instanceof EE_Line_Item ? $line_item->parent()->get_object() : null; |
|
| 175 | + // start of row |
|
| 176 | + $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
| 177 | + $html = EEH_HTML::tr('', '', $row_class); |
|
| 178 | + |
|
| 179 | + |
|
| 180 | + // Name Column |
|
| 181 | + $name_link = $line_item_related_object instanceof EEI_Admin_Links ? $line_item_related_object->get_admin_details_link() : ''; |
|
| 182 | + |
|
| 183 | + // related object scope. |
|
| 184 | + $parent_related_object_name = $parent_line_item_related_object instanceof EEI_Line_Item_Object ? $parent_line_item_related_object->name() : ''; |
|
| 185 | + $parent_related_object_name = empty($parent_related_object_name) && $line_item->parent() instanceof EE_Line_Item ? $line_item->parent()->name() : $parent_related_object_name; |
|
| 186 | + $parent_related_object_link = $parent_line_item_related_object instanceof EEI_Admin_Links ? $parent_line_item_related_object->get_admin_details_link() : ''; |
|
| 187 | + |
|
| 188 | + |
|
| 189 | + $name_html = $line_item_related_object instanceof EEI_Line_Item_Object ? $line_item_related_object->name() : $line_item->name(); |
|
| 190 | + $name_html = $name_link ? '<a href="' . $name_link . '">' . $name_html . '</a>' : $name_html; |
|
| 191 | + $name_html .= $line_item->is_taxable() ? ' *' : ''; |
|
| 192 | + // maybe preface with icon? |
|
| 193 | + $name_html = $line_item_related_object instanceof EEI_Has_Icon ? $line_item_related_object->get_icon() . $name_html : $name_html; |
|
| 194 | + $name_html = '<span class="ee-line-item-name linked">' . $name_html . '</span><br>'; |
|
| 195 | + $name_html .= sprintf( |
|
| 196 | + _x('%1$sfor the %2$s: %3$s%4$s', 'eg. "for the Event: My Cool Event"', 'event_espresso'), |
|
| 197 | + '<span class="ee-line-item-related-parent-object">', |
|
| 198 | + $line_item->parent() instanceof EE_Line_Item ? $line_item->parent()->OBJ_type_i18n() : __('Item:', 'event_espresso'), |
|
| 199 | + $parent_related_object_link ? '<a href="' . $parent_related_object_link . '">' . $parent_related_object_name . '</a>' : $parent_related_object_name, |
|
| 200 | + '</span>' |
|
| 201 | + ); |
|
| 202 | + |
|
| 203 | + $name_html = apply_filters( |
|
| 204 | + 'FHEE__EE_Admin_Table_Line_Item_Display_Strategy___item_row__name_html', |
|
| 205 | + $name_html, |
|
| 206 | + $line_item, |
|
| 207 | + $options |
|
| 208 | + ); |
|
| 209 | + |
|
| 210 | + $html .= EEH_HTML::td($name_html, '', 'jst-left'); |
|
| 211 | + // Type Column |
|
| 212 | + $type_html = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() : ''; |
|
| 213 | + $type_html .= $this->_get_cancellations($line_item); |
|
| 214 | + $type_html .= $line_item->OBJ_type() ? '<br />' : ''; |
|
| 215 | + $code = $line_item_related_object instanceof EEI_Has_Code ? $line_item_related_object->code() : ''; |
|
| 216 | + $type_html .= ! empty($code) ? '<span class="ee-line-item-id">' . sprintf(__('Code: %s', 'event_espresso'), $code) . '</span>' : ''; |
|
| 217 | + $html .= EEH_HTML::td($type_html, '', 'jst-left'); |
|
| 218 | + |
|
| 219 | + |
|
| 220 | + // Amount Column |
|
| 221 | + if ($line_item->is_percent()) { |
|
| 222 | + $html .= EEH_HTML::td($line_item->percent() . '%', '', 'jst-rght'); |
|
| 223 | + } else { |
|
| 224 | + $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'jst-rght'); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + // QTY column |
|
| 228 | + $html .= EEH_HTML::td($line_item->quantity(), '', 'jst-rght'); |
|
| 229 | + |
|
| 230 | + // total column |
|
| 231 | + $html .= EEH_HTML::td(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght'); |
|
| 232 | + |
|
| 233 | + // finish things off and return |
|
| 234 | + $html .= EEH_HTML::trx(); |
|
| 235 | + return $html; |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * _get_cancellations |
|
| 242 | + * |
|
| 243 | + * @param EE_Line_Item $line_item |
|
| 244 | + * @return string |
|
| 245 | + */ |
|
| 246 | + protected function _get_cancellations(EE_Line_Item $line_item) |
|
| 247 | + { |
|
| 248 | + $html = ''; |
|
| 249 | + $cancellations = $line_item->get_cancellations(); |
|
| 250 | + $cancellation = reset($cancellations); |
|
| 251 | + // \EEH_Debug_Tools::printr( $cancellation, '$cancellation', __FILE__, __LINE__ ); |
|
| 252 | + if ($cancellation instanceof EE_Line_Item) { |
|
| 253 | + $html .= ' <span class="ee-line-item-id">'; |
|
| 254 | + $html .= sprintf( |
|
| 255 | + _n( |
|
| 256 | + '(%1$s Cancellation)', |
|
| 257 | + '(%1$s Cancellations)', |
|
| 258 | + $cancellation->quantity(), |
|
| 259 | + 'event_espresso' |
|
| 260 | + ), |
|
| 261 | + $cancellation->quantity() |
|
| 262 | + ); |
|
| 263 | + $html .= '</span>'; |
|
| 264 | + } |
|
| 265 | + return $html; |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * _sub_item_row |
|
| 272 | + * |
|
| 273 | + * @param EE_Line_Item $line_item |
|
| 274 | + * @param array $options |
|
| 275 | + * @return mixed |
|
| 276 | + */ |
|
| 277 | + protected function _sub_item_row(EE_Line_Item $line_item, $options = array()) |
|
| 278 | + { |
|
| 279 | + // for now we're not showing sub-items |
|
| 280 | + return ''; |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * _tax_row |
|
| 287 | + * |
|
| 288 | + * @param EE_Line_Item $line_item |
|
| 289 | + * @param array $options |
|
| 290 | + * @return mixed |
|
| 291 | + */ |
|
| 292 | + protected function _tax_row(EE_Line_Item $line_item, $options = array()) |
|
| 293 | + { |
|
| 294 | + // start of row |
|
| 295 | + $html = EEH_HTML::tr('', 'admin-primary-mbox-taxes-tr'); |
|
| 296 | + // name th |
|
| 297 | + $html .= EEH_HTML::th($line_item->name() . '(' . $line_item->get_pretty('LIN_percent') . '%)', '', 'jst-rght', '', ' colspan="4"'); |
|
| 298 | + // total th |
|
| 299 | + $html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght'); |
|
| 300 | + // end of row |
|
| 301 | + $html .= EEH_HTML::trx(); |
|
| 302 | + return $html; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + |
|
| 306 | + |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * _total_row |
|
| 310 | + * |
|
| 311 | + * @param EE_Line_Item $line_item |
|
| 312 | + * @param string $text |
|
| 313 | + * @param array $options |
|
| 314 | + * @return mixed |
|
| 315 | + */ |
|
| 316 | + protected function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array()) |
|
| 317 | + { |
|
| 318 | + // currently not showing subtotal row |
|
| 319 | + return ''; |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + |
|
| 323 | + |
|
| 324 | + /** |
|
| 325 | + * _total_row |
|
| 326 | + * |
|
| 327 | + * @param EE_Line_Item $line_item |
|
| 328 | + * @param array $options |
|
| 329 | + * @return mixed |
|
| 330 | + */ |
|
| 331 | + protected function _total_row(EE_Line_Item $line_item, $options = array()) |
|
| 332 | + { |
|
| 333 | + // start of row |
|
| 334 | + $html = EEH_HTML::tr('', '', 'admin-primary-mbox-total-tr'); |
|
| 335 | + // Total th label |
|
| 336 | + $total_label = sprintf(__('Transaction Total %s', 'event_espresso'), '(' . EE_Registry::instance()->CFG->currency->code . ')'); |
|
| 337 | + $html .= EEH_HTML::th($total_label, '', 'jst-rght', '', ' colspan="4"'); |
|
| 338 | + // total th |
|
| 339 | + |
|
| 340 | + $html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght'); |
|
| 341 | + // end of row |
|
| 342 | + $html .= EEH_HTML::trx(); |
|
| 343 | + return $html; |
|
| 344 | + } |
|
| 345 | 345 | } |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | $html .= $this->_taxes_html; |
| 118 | 118 | $html .= $this->_total_row($line_item, $options); |
| 119 | 119 | if ($options['use_table_wrapper']) { |
| 120 | - $html = $this->_table_header($options) . $html . $this->_table_footer($options); |
|
| 120 | + $html = $this->_table_header($options).$html.$this->_table_footer($options); |
|
| 121 | 121 | } |
| 122 | 122 | break; |
| 123 | 123 | } |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | */ |
| 157 | 157 | protected function _table_footer($options) |
| 158 | 158 | { |
| 159 | - return EEH_HTML::tbodyx() . EEH_HTML::tablex(); |
|
| 159 | + return EEH_HTML::tbodyx().EEH_HTML::tablex(); |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | |
@@ -187,16 +187,16 @@ discard block |
||
| 187 | 187 | |
| 188 | 188 | |
| 189 | 189 | $name_html = $line_item_related_object instanceof EEI_Line_Item_Object ? $line_item_related_object->name() : $line_item->name(); |
| 190 | - $name_html = $name_link ? '<a href="' . $name_link . '">' . $name_html . '</a>' : $name_html; |
|
| 190 | + $name_html = $name_link ? '<a href="'.$name_link.'">'.$name_html.'</a>' : $name_html; |
|
| 191 | 191 | $name_html .= $line_item->is_taxable() ? ' *' : ''; |
| 192 | 192 | // maybe preface with icon? |
| 193 | - $name_html = $line_item_related_object instanceof EEI_Has_Icon ? $line_item_related_object->get_icon() . $name_html : $name_html; |
|
| 194 | - $name_html = '<span class="ee-line-item-name linked">' . $name_html . '</span><br>'; |
|
| 195 | - $name_html .= sprintf( |
|
| 193 | + $name_html = $line_item_related_object instanceof EEI_Has_Icon ? $line_item_related_object->get_icon().$name_html : $name_html; |
|
| 194 | + $name_html = '<span class="ee-line-item-name linked">'.$name_html.'</span><br>'; |
|
| 195 | + $name_html .= sprintf( |
|
| 196 | 196 | _x('%1$sfor the %2$s: %3$s%4$s', 'eg. "for the Event: My Cool Event"', 'event_espresso'), |
| 197 | 197 | '<span class="ee-line-item-related-parent-object">', |
| 198 | 198 | $line_item->parent() instanceof EE_Line_Item ? $line_item->parent()->OBJ_type_i18n() : __('Item:', 'event_espresso'), |
| 199 | - $parent_related_object_link ? '<a href="' . $parent_related_object_link . '">' . $parent_related_object_name . '</a>' : $parent_related_object_name, |
|
| 199 | + $parent_related_object_link ? '<a href="'.$parent_related_object_link.'">'.$parent_related_object_name.'</a>' : $parent_related_object_name, |
|
| 200 | 200 | '</span>' |
| 201 | 201 | ); |
| 202 | 202 | |
@@ -213,13 +213,13 @@ discard block |
||
| 213 | 213 | $type_html .= $this->_get_cancellations($line_item); |
| 214 | 214 | $type_html .= $line_item->OBJ_type() ? '<br />' : ''; |
| 215 | 215 | $code = $line_item_related_object instanceof EEI_Has_Code ? $line_item_related_object->code() : ''; |
| 216 | - $type_html .= ! empty($code) ? '<span class="ee-line-item-id">' . sprintf(__('Code: %s', 'event_espresso'), $code) . '</span>' : ''; |
|
| 216 | + $type_html .= ! empty($code) ? '<span class="ee-line-item-id">'.sprintf(__('Code: %s', 'event_espresso'), $code).'</span>' : ''; |
|
| 217 | 217 | $html .= EEH_HTML::td($type_html, '', 'jst-left'); |
| 218 | 218 | |
| 219 | 219 | |
| 220 | 220 | // Amount Column |
| 221 | 221 | if ($line_item->is_percent()) { |
| 222 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', 'jst-rght'); |
|
| 222 | + $html .= EEH_HTML::td($line_item->percent().'%', '', 'jst-rght'); |
|
| 223 | 223 | } else { |
| 224 | 224 | $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'jst-rght'); |
| 225 | 225 | } |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | // start of row |
| 295 | 295 | $html = EEH_HTML::tr('', 'admin-primary-mbox-taxes-tr'); |
| 296 | 296 | // name th |
| 297 | - $html .= EEH_HTML::th($line_item->name() . '(' . $line_item->get_pretty('LIN_percent') . '%)', '', 'jst-rght', '', ' colspan="4"'); |
|
| 297 | + $html .= EEH_HTML::th($line_item->name().'('.$line_item->get_pretty('LIN_percent').'%)', '', 'jst-rght', '', ' colspan="4"'); |
|
| 298 | 298 | // total th |
| 299 | 299 | $html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght'); |
| 300 | 300 | // end of row |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | // start of row |
| 334 | 334 | $html = EEH_HTML::tr('', '', 'admin-primary-mbox-total-tr'); |
| 335 | 335 | // Total th label |
| 336 | - $total_label = sprintf(__('Transaction Total %s', 'event_espresso'), '(' . EE_Registry::instance()->CFG->currency->code . ')'); |
|
| 336 | + $total_label = sprintf(__('Transaction Total %s', 'event_espresso'), '('.EE_Registry::instance()->CFG->currency->code.')'); |
|
| 337 | 337 | $html .= EEH_HTML::th($total_label, '', 'jst-rght', '', ' colspan="4"'); |
| 338 | 338 | // total th |
| 339 | 339 | |
@@ -12,659 +12,659 @@ |
||
| 12 | 12 | class EE_SPCO_Line_Item_Display_Strategy implements EEI_Line_Item_Display |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * array of events |
|
| 17 | - * |
|
| 18 | - * @type EE_Line_Item[] $_events |
|
| 19 | - */ |
|
| 20 | - private $_events = array(); |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * whether to display the taxes row or not |
|
| 24 | - * |
|
| 25 | - * @type bool $_show_taxes |
|
| 26 | - */ |
|
| 27 | - private $_show_taxes = false; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * html for any tax rows |
|
| 31 | - * |
|
| 32 | - * @type string $_show_taxes |
|
| 33 | - */ |
|
| 34 | - private $_taxes_html = ''; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * total amount including tax we can bill for at this time |
|
| 38 | - * |
|
| 39 | - * @type float $_grand_total |
|
| 40 | - */ |
|
| 41 | - private $_grand_total = 0.00; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * total number of items being billed for |
|
| 45 | - * |
|
| 46 | - * @type int $_total_items |
|
| 47 | - */ |
|
| 48 | - private $_total_items = 0; |
|
| 49 | - |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @return float |
|
| 54 | - */ |
|
| 55 | - public function grand_total() |
|
| 56 | - { |
|
| 57 | - return $this->_grand_total; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @return int |
|
| 64 | - */ |
|
| 65 | - public function total_items() |
|
| 66 | - { |
|
| 67 | - return $this->_total_items; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @param EE_Line_Item $line_item |
|
| 74 | - * @param array $options |
|
| 75 | - * @param EE_Line_Item $parent_line_item |
|
| 76 | - * @return mixed |
|
| 77 | - * @throws EE_Error |
|
| 78 | - */ |
|
| 79 | - public function display_line_item( |
|
| 80 | - EE_Line_Item $line_item, |
|
| 81 | - $options = array(), |
|
| 82 | - EE_Line_Item $parent_line_item = null |
|
| 83 | - ) { |
|
| 84 | - $html = ''; |
|
| 85 | - // set some default options and merge with incoming |
|
| 86 | - $default_options = array( |
|
| 87 | - 'show_desc' => true, // true false |
|
| 88 | - 'odd' => false, |
|
| 89 | - ); |
|
| 90 | - $options = array_merge($default_options, (array) $options); |
|
| 91 | - switch ($line_item->type()) { |
|
| 92 | - case EEM_Line_Item::type_line_item: |
|
| 93 | - $this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes; |
|
| 94 | - if ($line_item->OBJ_type() === 'Ticket') { |
|
| 95 | - // item row |
|
| 96 | - $html .= $this->_ticket_row($line_item, $options); |
|
| 97 | - } else { |
|
| 98 | - // item row |
|
| 99 | - $html .= $this->_item_row($line_item, $options); |
|
| 100 | - } |
|
| 101 | - if (apply_filters( |
|
| 102 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__display_line_item__display_sub_line_items', |
|
| 103 | - true |
|
| 104 | - ) |
|
| 105 | - ) { |
|
| 106 | - // got any kids? |
|
| 107 | - foreach ($line_item->children() as $child_line_item) { |
|
| 108 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - break; |
|
| 112 | - case EEM_Line_Item::type_sub_line_item: |
|
| 113 | - $html .= $this->_sub_item_row($line_item, $options, $parent_line_item); |
|
| 114 | - break; |
|
| 115 | - case EEM_Line_Item::type_sub_total: |
|
| 116 | - static $sub_total = 0; |
|
| 117 | - $event_sub_total = 0; |
|
| 118 | - $text = esc_html__('Sub-Total', 'event_espresso'); |
|
| 119 | - if ($line_item->OBJ_type() === 'Event') { |
|
| 120 | - $options['event_id'] = $event_id = $line_item->OBJ_ID(); |
|
| 121 | - if (! isset($this->_events[ $options['event_id'] ])) { |
|
| 122 | - $event = EEM_Event::instance()->get_one_by_ID($options['event_id']); |
|
| 123 | - // if event has default reg status of Not Approved, then don't display info on it |
|
| 124 | - if ($event instanceof EE_Event |
|
| 125 | - && $event->default_registration_status() === EEM_Registration::status_id_not_approved |
|
| 126 | - ) { |
|
| 127 | - $display_event = false; |
|
| 128 | - // unless there are registrations for it that are returning to pay |
|
| 129 | - if (isset($options['registrations']) && is_array($options['registrations'])) { |
|
| 130 | - foreach ($options['registrations'] as $registration) { |
|
| 131 | - if (! $registration instanceof EE_Registration) { |
|
| 132 | - continue; |
|
| 133 | - } |
|
| 134 | - $display_event = $registration->event_ID() === $options['event_id'] |
|
| 135 | - && $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
| 136 | - ? true |
|
| 137 | - : $display_event; |
|
| 138 | - } |
|
| 139 | - } |
|
| 140 | - if (! $display_event) { |
|
| 141 | - return ''; |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - $this->_events[ $options['event_id'] ] = 0; |
|
| 145 | - $html .= $this->_event_row($line_item); |
|
| 146 | - $text = esc_html__('Event Sub-Total', 'event_espresso'); |
|
| 147 | - } |
|
| 148 | - } |
|
| 149 | - $child_line_items = $line_item->children(); |
|
| 150 | - // loop thru children |
|
| 151 | - foreach ($child_line_items as $child_line_item) { |
|
| 152 | - // recursively feed children back into this method |
|
| 153 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
| 154 | - } |
|
| 155 | - $event_sub_total += isset($options['event_id']) ? $this->_events[ $options['event_id'] ] : 0; |
|
| 156 | - $sub_total += $event_sub_total; |
|
| 157 | - if (( |
|
| 158 | - // event subtotals |
|
| 159 | - $line_item->code() !== 'pre-tax-subtotal' && count($child_line_items) > 1 |
|
| 160 | - ) |
|
| 161 | - || ( |
|
| 162 | - // pre-tax subtotals |
|
| 163 | - $line_item->code() === 'pre-tax-subtotal' && count($this->_events) > 1 |
|
| 164 | - ) |
|
| 165 | - ) { |
|
| 166 | - $options['sub_total'] = $line_item->OBJ_type() === 'Event' ? $event_sub_total : $sub_total; |
|
| 167 | - $html .= $this->_sub_total_row($line_item, $text, $options); |
|
| 168 | - } |
|
| 169 | - break; |
|
| 170 | - case EEM_Line_Item::type_tax: |
|
| 171 | - if ($this->_show_taxes) { |
|
| 172 | - $this->_taxes_html .= $this->_tax_row($line_item, $options); |
|
| 173 | - } |
|
| 174 | - break; |
|
| 175 | - case EEM_Line_Item::type_tax_sub_total: |
|
| 176 | - if ($this->_show_taxes) { |
|
| 177 | - $child_line_items = $line_item->children(); |
|
| 178 | - // loop thru children |
|
| 179 | - foreach ($child_line_items as $child_line_item) { |
|
| 180 | - // recursively feed children back into this method |
|
| 181 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
| 182 | - } |
|
| 183 | - if (count($child_line_items) > 1) { |
|
| 184 | - $this->_taxes_html .= $this->_total_tax_row($line_item, esc_html__('Tax Total', 'event_espresso')); |
|
| 185 | - } |
|
| 186 | - } |
|
| 187 | - break; |
|
| 188 | - case EEM_Line_Item::type_total: |
|
| 189 | - // get all child line items |
|
| 190 | - $children = $line_item->children(); |
|
| 191 | - // loop thru all non-tax child line items |
|
| 192 | - foreach ($children as $child_line_item) { |
|
| 193 | - if ($child_line_item->type() !== EEM_Line_Item::type_tax_sub_total) { |
|
| 194 | - // recursively feed children back into this method |
|
| 195 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - // now loop thru tax child line items |
|
| 199 | - foreach ($children as $child_line_item) { |
|
| 200 | - if ($child_line_item->type() === EEM_Line_Item::type_tax_sub_total) { |
|
| 201 | - // recursively feed children back into this method |
|
| 202 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - $html .= $this->_taxes_html; |
|
| 206 | - $html .= $this->_total_row($line_item, esc_html__('Total', 'event_espresso')); |
|
| 207 | - $html .= $this->_payments_and_amount_owing_rows($line_item, $options); |
|
| 208 | - break; |
|
| 209 | - } |
|
| 210 | - return $html; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * _event_row - basically a Heading row displayed once above each event's ticket rows |
|
| 217 | - * |
|
| 218 | - * @param EE_Line_Item $line_item |
|
| 219 | - * @return mixed |
|
| 220 | - */ |
|
| 221 | - private function _event_row(EE_Line_Item $line_item) |
|
| 222 | - { |
|
| 223 | - // start of row |
|
| 224 | - $html = EEH_HTML::tr('', 'event-cart-total-row', 'total_tr odd'); |
|
| 225 | - // event name td |
|
| 226 | - $html .= EEH_HTML::td( |
|
| 227 | - EEH_HTML::strong($line_item->name()), |
|
| 228 | - '', |
|
| 229 | - 'event-header', |
|
| 230 | - '', |
|
| 231 | - ' colspan="4"' |
|
| 232 | - ); |
|
| 233 | - // end of row |
|
| 234 | - $html .= EEH_HTML::trx(); |
|
| 235 | - return $html; |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * _ticket_row |
|
| 242 | - * |
|
| 243 | - * @param EE_Line_Item $line_item |
|
| 244 | - * @param array $options |
|
| 245 | - * @return mixed |
|
| 246 | - * @throws EE_Error |
|
| 247 | - */ |
|
| 248 | - private function _ticket_row(EE_Line_Item $line_item, $options = array()) |
|
| 249 | - { |
|
| 250 | - // start of row |
|
| 251 | - $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
| 252 | - $html = EEH_HTML::tr('', '', $row_class); |
|
| 253 | - // name && desc |
|
| 254 | - $name_and_desc = apply_filters( |
|
| 255 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
|
| 256 | - $line_item->name(), |
|
| 257 | - $line_item |
|
| 258 | - ); |
|
| 259 | - $name_and_desc .= apply_filters( |
|
| 260 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
|
| 261 | - ( |
|
| 262 | - $options['show_desc'] |
|
| 263 | - ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
| 264 | - : '' |
|
| 265 | - ), |
|
| 266 | - $line_item, |
|
| 267 | - $options |
|
| 268 | - ); |
|
| 269 | - $name_and_desc .= $line_item->is_taxable() ? ' * ' : ''; |
|
| 270 | - $name_and_desc = apply_filters( |
|
| 271 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__name_and_desc', |
|
| 272 | - $name_and_desc, |
|
| 273 | - $line_item, |
|
| 274 | - $options |
|
| 275 | - ); |
|
| 276 | - |
|
| 277 | - // name td |
|
| 278 | - $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
|
| 279 | - $name_and_desc, |
|
| 280 | - '', |
|
| 281 | - 'item_l' |
|
| 282 | - ); |
|
| 283 | - // price td |
|
| 284 | - $price = apply_filters( |
|
| 285 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__price', |
|
| 286 | - $line_item->unit_price_no_code(), |
|
| 287 | - $line_item |
|
| 288 | - ); |
|
| 289 | - $html .= EEH_HTML::td($price, '', 'item_c jst-rght'); |
|
| 290 | - // quantity td |
|
| 291 | - $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght'); |
|
| 292 | - $this->_total_items += $line_item->quantity(); |
|
| 293 | - // determine total for line item |
|
| 294 | - $total = apply_filters( |
|
| 295 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__total', |
|
| 296 | - $line_item->total(), |
|
| 297 | - $line_item |
|
| 298 | - ); |
|
| 299 | - $this->_events[ $options['event_id'] ] += $total; |
|
| 300 | - // total td |
|
| 301 | - $html .= EEH_HTML::td( |
|
| 302 | - EEH_Template::format_currency($total, false, false), |
|
| 303 | - '', |
|
| 304 | - 'item_r jst-rght' |
|
| 305 | - ); |
|
| 306 | - // end of row |
|
| 307 | - $html .= EEH_HTML::trx(); |
|
| 308 | - return $html; |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * _item_row |
|
| 315 | - * |
|
| 316 | - * @param EE_Line_Item $line_item |
|
| 317 | - * @param array $options |
|
| 318 | - * @return mixed |
|
| 319 | - * @throws EE_Error |
|
| 320 | - */ |
|
| 321 | - private function _item_row(EE_Line_Item $line_item, $options = array()) |
|
| 322 | - { |
|
| 323 | - // start of row |
|
| 324 | - $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
| 325 | - $html = EEH_HTML::tr('', '', $row_class); |
|
| 326 | - $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : ''; |
|
| 327 | - // name && desc |
|
| 328 | - $name_and_desc = apply_filters( |
|
| 329 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
|
| 330 | - $obj_name . $line_item->name(), |
|
| 331 | - $line_item |
|
| 332 | - ); |
|
| 333 | - $name_and_desc .= apply_filters( |
|
| 334 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
|
| 335 | - ( |
|
| 336 | - $options['show_desc'] |
|
| 337 | - ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
| 338 | - : '' |
|
| 339 | - ), |
|
| 340 | - $line_item, |
|
| 341 | - $options |
|
| 342 | - ); |
|
| 343 | - $name_and_desc .= $line_item->is_taxable() ? ' * ' : ''; |
|
| 344 | - $name_and_desc = apply_filters( |
|
| 345 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy___item_row__name_and_desc', |
|
| 346 | - $name_and_desc, |
|
| 347 | - $line_item, |
|
| 348 | - $options |
|
| 349 | - ); |
|
| 350 | - |
|
| 351 | - // name td |
|
| 352 | - $html .= EEH_HTML::td($name_and_desc, '', 'item_l'); |
|
| 353 | - // price td |
|
| 354 | - if ($line_item->is_percent()) { |
|
| 355 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c jst-rght'); |
|
| 356 | - } else { |
|
| 357 | - $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
|
| 358 | - } |
|
| 359 | - // quantity td |
|
| 360 | - $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght'); |
|
| 361 | - // $total = $line_item->total() * $line_item->quantity(); |
|
| 362 | - $total = $line_item->total(); |
|
| 363 | - if (isset($options['event_id'], $this->_events[ $options['event_id'] ])) { |
|
| 364 | - $this->_events[ $options['event_id'] ] += $total; |
|
| 365 | - } |
|
| 366 | - // total td |
|
| 367 | - $html .= EEH_HTML::td( |
|
| 368 | - EEH_Template::format_currency($total, false, false), |
|
| 369 | - '', |
|
| 370 | - 'item_r jst-rght' |
|
| 371 | - ); |
|
| 372 | - // end of row |
|
| 373 | - $html .= EEH_HTML::trx(); |
|
| 374 | - return $html; |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - |
|
| 378 | - |
|
| 379 | - /** |
|
| 380 | - * _sub_item_row |
|
| 381 | - * |
|
| 382 | - * @param EE_Line_Item $line_item |
|
| 383 | - * @param array $options |
|
| 384 | - * @param EE_Line_Item $parent_line_item |
|
| 385 | - * @return mixed |
|
| 386 | - * @throws EE_Error |
|
| 387 | - */ |
|
| 388 | - private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null) |
|
| 389 | - { |
|
| 390 | - if ($parent_line_item instanceof EE_Line_Item |
|
| 391 | - && $line_item->children() === array() |
|
| 392 | - && $line_item->name() === $parent_line_item->name() |
|
| 393 | - && apply_filters( |
|
| 394 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__hide_main_sub_line_item', |
|
| 395 | - true |
|
| 396 | - ) |
|
| 397 | - ) { |
|
| 398 | - return ''; |
|
| 399 | - } |
|
| 400 | - // start of row |
|
| 401 | - $html = EEH_HTML::tr('', '', 'item sub-item-row'); |
|
| 402 | - // name && desc |
|
| 403 | - $name_and_desc = EEH_HTML::span('', '', 'sub-item-row-bullet dashicons dashicons-arrow-right') |
|
| 404 | - . $line_item->name(); |
|
| 405 | - $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: ' |
|
| 406 | - . $line_item->desc() |
|
| 407 | - . '</span>' : ''; |
|
| 408 | - // name td |
|
| 409 | - $html .= EEH_HTML::td($name_and_desc, '', 'item_l sub-item'); |
|
| 410 | - $qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1; |
|
| 411 | - // discount/surcharge td |
|
| 412 | - if ($line_item->is_percent()) { |
|
| 413 | - $html .= EEH_HTML::td( |
|
| 414 | - EEH_Template::format_currency( |
|
| 415 | - $line_item->total() / $qty, |
|
| 416 | - false, |
|
| 417 | - false |
|
| 418 | - ), |
|
| 419 | - '', |
|
| 420 | - 'item_c jst-rght' |
|
| 421 | - ); |
|
| 422 | - } else { |
|
| 423 | - $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
|
| 424 | - } |
|
| 425 | - // no quantity td |
|
| 426 | - $html .= EEH_HTML::td(); |
|
| 427 | - // no total td |
|
| 428 | - $html .= EEH_HTML::td(); |
|
| 429 | - // end of row |
|
| 430 | - $html .= EEH_HTML::trx(); |
|
| 431 | - $html = apply_filters( |
|
| 432 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__html', |
|
| 433 | - $html, |
|
| 434 | - $line_item, |
|
| 435 | - $options, |
|
| 436 | - $parent_line_item |
|
| 437 | - ); |
|
| 438 | - return $html; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - |
|
| 442 | - |
|
| 443 | - /** |
|
| 444 | - * _tax_row |
|
| 445 | - * |
|
| 446 | - * @param EE_Line_Item $line_item |
|
| 447 | - * @param array $options |
|
| 448 | - * @return mixed |
|
| 449 | - * @throws EE_Error |
|
| 450 | - */ |
|
| 451 | - private function _tax_row(EE_Line_Item $line_item, $options = array()) |
|
| 452 | - { |
|
| 453 | - // start of row |
|
| 454 | - $html = EEH_HTML::tr('', 'item sub-item tax-total'); |
|
| 455 | - // name && desc |
|
| 456 | - $name_and_desc = $line_item->name(); |
|
| 457 | - $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">' |
|
| 458 | - . esc_html__(' * taxable items', 'event_espresso') . '</span>'; |
|
| 459 | - $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : ''; |
|
| 460 | - // name td |
|
| 461 | - $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
|
| 462 | - $name_and_desc, |
|
| 463 | - '', |
|
| 464 | - 'item_l sub-item' |
|
| 465 | - ); |
|
| 466 | - // percent td |
|
| 467 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', ''); |
|
| 468 | - // empty td (price) |
|
| 469 | - $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
|
| 470 | - // total td |
|
| 471 | - $html .= EEH_HTML::td( |
|
| 472 | - EEH_Template::format_currency( |
|
| 473 | - $line_item->total(), |
|
| 474 | - false, |
|
| 475 | - false |
|
| 476 | - ), |
|
| 477 | - '', |
|
| 478 | - 'item_r jst-rght' |
|
| 479 | - ); |
|
| 480 | - // end of row |
|
| 481 | - $html .= EEH_HTML::trx(); |
|
| 482 | - return $html; |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * _total_row |
|
| 489 | - * |
|
| 490 | - * @param EE_Line_Item $line_item |
|
| 491 | - * @param string $text |
|
| 492 | - * @return mixed |
|
| 493 | - * @throws EE_Error |
|
| 494 | - */ |
|
| 495 | - private function _total_tax_row(EE_Line_Item $line_item, $text = '') |
|
| 496 | - { |
|
| 497 | - $html = ''; |
|
| 498 | - if ($line_item->total()) { |
|
| 499 | - // start of row |
|
| 500 | - $html = EEH_HTML::tr('', '', 'total_tr odd'); |
|
| 501 | - // total td |
|
| 502 | - $html .= EEH_HTML::td( |
|
| 503 | - $text, |
|
| 504 | - '', |
|
| 505 | - 'total_currency total jst-rght', |
|
| 506 | - '', |
|
| 507 | - ' colspan="2"' |
|
| 508 | - ); |
|
| 509 | - // empty td (price) |
|
| 510 | - $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
|
| 511 | - // total td |
|
| 512 | - $html .= EEH_HTML::td( |
|
| 513 | - EEH_Template::format_currency($line_item->total(), false, false), |
|
| 514 | - '', |
|
| 515 | - 'total jst-rght' |
|
| 516 | - ); |
|
| 517 | - // end of row |
|
| 518 | - $html .= EEH_HTML::trx(); |
|
| 519 | - } |
|
| 520 | - return $html; |
|
| 521 | - } |
|
| 522 | - |
|
| 523 | - |
|
| 524 | - |
|
| 525 | - /** |
|
| 526 | - * _total_row |
|
| 527 | - * |
|
| 528 | - * @param EE_Line_Item $line_item |
|
| 529 | - * @param string $text |
|
| 530 | - * @param array $options |
|
| 531 | - * @return mixed |
|
| 532 | - * @throws EE_Error |
|
| 533 | - */ |
|
| 534 | - private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array()) |
|
| 535 | - { |
|
| 536 | - $html = ''; |
|
| 537 | - if ($line_item->total()) { |
|
| 538 | - // start of row |
|
| 539 | - $html = EEH_HTML::tr('', '', 'total_tr odd'); |
|
| 540 | - // total td |
|
| 541 | - $html .= EEH_HTML::td( |
|
| 542 | - $text, |
|
| 543 | - '', |
|
| 544 | - 'total_currency total jst-rght', |
|
| 545 | - '', |
|
| 546 | - ' colspan="3"' |
|
| 547 | - ); |
|
| 548 | - // total td |
|
| 549 | - $html .= EEH_HTML::td( |
|
| 550 | - EEH_Template::format_currency($options['sub_total'], false, false), |
|
| 551 | - '', |
|
| 552 | - 'total jst-rght' |
|
| 553 | - ); |
|
| 554 | - // end of row |
|
| 555 | - $html .= EEH_HTML::trx(); |
|
| 556 | - } |
|
| 557 | - return $html; |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - |
|
| 561 | - |
|
| 562 | - /** |
|
| 563 | - * _total_row |
|
| 564 | - * |
|
| 565 | - * @param EE_Line_Item $line_item |
|
| 566 | - * @param string $text |
|
| 567 | - * @return mixed |
|
| 568 | - * @throws EE_Error |
|
| 569 | - */ |
|
| 570 | - private function _total_row(EE_Line_Item $line_item, $text = '') |
|
| 571 | - { |
|
| 572 | - // start of row |
|
| 573 | - $html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd'); |
|
| 574 | - // total td |
|
| 575 | - $html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"'); |
|
| 576 | - // total td |
|
| 577 | - $html .= EEH_HTML::td( |
|
| 578 | - EEH_Template::format_currency($line_item->total(), false, false), |
|
| 579 | - '', |
|
| 580 | - 'total jst-rght' |
|
| 581 | - ); |
|
| 582 | - // end of row |
|
| 583 | - $html .= EEH_HTML::trx(); |
|
| 584 | - return $html; |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - |
|
| 588 | - |
|
| 589 | - /** |
|
| 590 | - * _payments_and_amount_owing_rows |
|
| 591 | - * |
|
| 592 | - * @param EE_Line_Item $line_item |
|
| 593 | - * @param array $options |
|
| 594 | - * @return mixed |
|
| 595 | - * @throws EE_Error |
|
| 596 | - */ |
|
| 597 | - private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array()) |
|
| 598 | - { |
|
| 599 | - $html = ''; |
|
| 600 | - $owing = $line_item->total(); |
|
| 601 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID()); |
|
| 602 | - if ($transaction instanceof EE_Transaction) { |
|
| 603 | - $registration_payments = array(); |
|
| 604 | - $registrations = ! empty($options['registrations']) |
|
| 605 | - ? $options['registrations'] |
|
| 606 | - : $transaction->registrations(); |
|
| 607 | - foreach ($registrations as $registration) { |
|
| 608 | - if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) { |
|
| 609 | - $registration_payments += $registration->registration_payments(); |
|
| 610 | - } |
|
| 611 | - } |
|
| 612 | - if (! empty($registration_payments)) { |
|
| 613 | - foreach ($registration_payments as $registration_payment) { |
|
| 614 | - if ($registration_payment instanceof EE_Registration_Payment) { |
|
| 615 | - $owing -= $registration_payment->amount(); |
|
| 616 | - $payment = $registration_payment->payment(); |
|
| 617 | - $payment_desc = ''; |
|
| 618 | - if ($payment instanceof EE_Payment) { |
|
| 619 | - $payment_desc = sprintf( |
|
| 620 | - esc_html__('Payment%1$s Received: %2$s', 'event_espresso'), |
|
| 621 | - $payment->txn_id_chq_nmbr() !== '' |
|
| 622 | - ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> ' |
|
| 623 | - : '', |
|
| 624 | - $payment->timestamp() |
|
| 625 | - ); |
|
| 626 | - } |
|
| 627 | - // start of row |
|
| 628 | - $html .= EEH_HTML::tr('', '', 'total_tr odd'); |
|
| 629 | - // payment desc |
|
| 630 | - $html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"'); |
|
| 631 | - // total td |
|
| 632 | - $html .= EEH_HTML::td( |
|
| 633 | - EEH_Template::format_currency( |
|
| 634 | - $registration_payment->amount(), |
|
| 635 | - false, |
|
| 636 | - false |
|
| 637 | - ), |
|
| 638 | - '', |
|
| 639 | - 'total jst-rght' |
|
| 640 | - ); |
|
| 641 | - // end of row |
|
| 642 | - $html .= EEH_HTML::trx(); |
|
| 643 | - } |
|
| 644 | - } |
|
| 645 | - if ($line_item->total()) { |
|
| 646 | - // start of row |
|
| 647 | - $html .= EEH_HTML::tr('', '', 'total_tr odd'); |
|
| 648 | - // total td |
|
| 649 | - $html .= EEH_HTML::td( |
|
| 650 | - esc_html__('Amount Owing', 'event_espresso'), |
|
| 651 | - '', |
|
| 652 | - 'total_currency total jst-rght', |
|
| 653 | - '', |
|
| 654 | - ' colspan="3"' |
|
| 655 | - ); |
|
| 656 | - // total td |
|
| 657 | - $html .= EEH_HTML::td( |
|
| 658 | - EEH_Template::format_currency($owing, false, false), |
|
| 659 | - '', |
|
| 660 | - 'total jst-rght' |
|
| 661 | - ); |
|
| 662 | - // end of row |
|
| 663 | - $html .= EEH_HTML::trx(); |
|
| 664 | - } |
|
| 665 | - } |
|
| 666 | - } |
|
| 667 | - $this->_grand_total = $owing; |
|
| 668 | - return $html; |
|
| 669 | - } |
|
| 15 | + /** |
|
| 16 | + * array of events |
|
| 17 | + * |
|
| 18 | + * @type EE_Line_Item[] $_events |
|
| 19 | + */ |
|
| 20 | + private $_events = array(); |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * whether to display the taxes row or not |
|
| 24 | + * |
|
| 25 | + * @type bool $_show_taxes |
|
| 26 | + */ |
|
| 27 | + private $_show_taxes = false; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * html for any tax rows |
|
| 31 | + * |
|
| 32 | + * @type string $_show_taxes |
|
| 33 | + */ |
|
| 34 | + private $_taxes_html = ''; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * total amount including tax we can bill for at this time |
|
| 38 | + * |
|
| 39 | + * @type float $_grand_total |
|
| 40 | + */ |
|
| 41 | + private $_grand_total = 0.00; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * total number of items being billed for |
|
| 45 | + * |
|
| 46 | + * @type int $_total_items |
|
| 47 | + */ |
|
| 48 | + private $_total_items = 0; |
|
| 49 | + |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @return float |
|
| 54 | + */ |
|
| 55 | + public function grand_total() |
|
| 56 | + { |
|
| 57 | + return $this->_grand_total; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @return int |
|
| 64 | + */ |
|
| 65 | + public function total_items() |
|
| 66 | + { |
|
| 67 | + return $this->_total_items; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @param EE_Line_Item $line_item |
|
| 74 | + * @param array $options |
|
| 75 | + * @param EE_Line_Item $parent_line_item |
|
| 76 | + * @return mixed |
|
| 77 | + * @throws EE_Error |
|
| 78 | + */ |
|
| 79 | + public function display_line_item( |
|
| 80 | + EE_Line_Item $line_item, |
|
| 81 | + $options = array(), |
|
| 82 | + EE_Line_Item $parent_line_item = null |
|
| 83 | + ) { |
|
| 84 | + $html = ''; |
|
| 85 | + // set some default options and merge with incoming |
|
| 86 | + $default_options = array( |
|
| 87 | + 'show_desc' => true, // true false |
|
| 88 | + 'odd' => false, |
|
| 89 | + ); |
|
| 90 | + $options = array_merge($default_options, (array) $options); |
|
| 91 | + switch ($line_item->type()) { |
|
| 92 | + case EEM_Line_Item::type_line_item: |
|
| 93 | + $this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes; |
|
| 94 | + if ($line_item->OBJ_type() === 'Ticket') { |
|
| 95 | + // item row |
|
| 96 | + $html .= $this->_ticket_row($line_item, $options); |
|
| 97 | + } else { |
|
| 98 | + // item row |
|
| 99 | + $html .= $this->_item_row($line_item, $options); |
|
| 100 | + } |
|
| 101 | + if (apply_filters( |
|
| 102 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__display_line_item__display_sub_line_items', |
|
| 103 | + true |
|
| 104 | + ) |
|
| 105 | + ) { |
|
| 106 | + // got any kids? |
|
| 107 | + foreach ($line_item->children() as $child_line_item) { |
|
| 108 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + break; |
|
| 112 | + case EEM_Line_Item::type_sub_line_item: |
|
| 113 | + $html .= $this->_sub_item_row($line_item, $options, $parent_line_item); |
|
| 114 | + break; |
|
| 115 | + case EEM_Line_Item::type_sub_total: |
|
| 116 | + static $sub_total = 0; |
|
| 117 | + $event_sub_total = 0; |
|
| 118 | + $text = esc_html__('Sub-Total', 'event_espresso'); |
|
| 119 | + if ($line_item->OBJ_type() === 'Event') { |
|
| 120 | + $options['event_id'] = $event_id = $line_item->OBJ_ID(); |
|
| 121 | + if (! isset($this->_events[ $options['event_id'] ])) { |
|
| 122 | + $event = EEM_Event::instance()->get_one_by_ID($options['event_id']); |
|
| 123 | + // if event has default reg status of Not Approved, then don't display info on it |
|
| 124 | + if ($event instanceof EE_Event |
|
| 125 | + && $event->default_registration_status() === EEM_Registration::status_id_not_approved |
|
| 126 | + ) { |
|
| 127 | + $display_event = false; |
|
| 128 | + // unless there are registrations for it that are returning to pay |
|
| 129 | + if (isset($options['registrations']) && is_array($options['registrations'])) { |
|
| 130 | + foreach ($options['registrations'] as $registration) { |
|
| 131 | + if (! $registration instanceof EE_Registration) { |
|
| 132 | + continue; |
|
| 133 | + } |
|
| 134 | + $display_event = $registration->event_ID() === $options['event_id'] |
|
| 135 | + && $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
| 136 | + ? true |
|
| 137 | + : $display_event; |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | + if (! $display_event) { |
|
| 141 | + return ''; |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + $this->_events[ $options['event_id'] ] = 0; |
|
| 145 | + $html .= $this->_event_row($line_item); |
|
| 146 | + $text = esc_html__('Event Sub-Total', 'event_espresso'); |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | + $child_line_items = $line_item->children(); |
|
| 150 | + // loop thru children |
|
| 151 | + foreach ($child_line_items as $child_line_item) { |
|
| 152 | + // recursively feed children back into this method |
|
| 153 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
| 154 | + } |
|
| 155 | + $event_sub_total += isset($options['event_id']) ? $this->_events[ $options['event_id'] ] : 0; |
|
| 156 | + $sub_total += $event_sub_total; |
|
| 157 | + if (( |
|
| 158 | + // event subtotals |
|
| 159 | + $line_item->code() !== 'pre-tax-subtotal' && count($child_line_items) > 1 |
|
| 160 | + ) |
|
| 161 | + || ( |
|
| 162 | + // pre-tax subtotals |
|
| 163 | + $line_item->code() === 'pre-tax-subtotal' && count($this->_events) > 1 |
|
| 164 | + ) |
|
| 165 | + ) { |
|
| 166 | + $options['sub_total'] = $line_item->OBJ_type() === 'Event' ? $event_sub_total : $sub_total; |
|
| 167 | + $html .= $this->_sub_total_row($line_item, $text, $options); |
|
| 168 | + } |
|
| 169 | + break; |
|
| 170 | + case EEM_Line_Item::type_tax: |
|
| 171 | + if ($this->_show_taxes) { |
|
| 172 | + $this->_taxes_html .= $this->_tax_row($line_item, $options); |
|
| 173 | + } |
|
| 174 | + break; |
|
| 175 | + case EEM_Line_Item::type_tax_sub_total: |
|
| 176 | + if ($this->_show_taxes) { |
|
| 177 | + $child_line_items = $line_item->children(); |
|
| 178 | + // loop thru children |
|
| 179 | + foreach ($child_line_items as $child_line_item) { |
|
| 180 | + // recursively feed children back into this method |
|
| 181 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
| 182 | + } |
|
| 183 | + if (count($child_line_items) > 1) { |
|
| 184 | + $this->_taxes_html .= $this->_total_tax_row($line_item, esc_html__('Tax Total', 'event_espresso')); |
|
| 185 | + } |
|
| 186 | + } |
|
| 187 | + break; |
|
| 188 | + case EEM_Line_Item::type_total: |
|
| 189 | + // get all child line items |
|
| 190 | + $children = $line_item->children(); |
|
| 191 | + // loop thru all non-tax child line items |
|
| 192 | + foreach ($children as $child_line_item) { |
|
| 193 | + if ($child_line_item->type() !== EEM_Line_Item::type_tax_sub_total) { |
|
| 194 | + // recursively feed children back into this method |
|
| 195 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + // now loop thru tax child line items |
|
| 199 | + foreach ($children as $child_line_item) { |
|
| 200 | + if ($child_line_item->type() === EEM_Line_Item::type_tax_sub_total) { |
|
| 201 | + // recursively feed children back into this method |
|
| 202 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + $html .= $this->_taxes_html; |
|
| 206 | + $html .= $this->_total_row($line_item, esc_html__('Total', 'event_espresso')); |
|
| 207 | + $html .= $this->_payments_and_amount_owing_rows($line_item, $options); |
|
| 208 | + break; |
|
| 209 | + } |
|
| 210 | + return $html; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * _event_row - basically a Heading row displayed once above each event's ticket rows |
|
| 217 | + * |
|
| 218 | + * @param EE_Line_Item $line_item |
|
| 219 | + * @return mixed |
|
| 220 | + */ |
|
| 221 | + private function _event_row(EE_Line_Item $line_item) |
|
| 222 | + { |
|
| 223 | + // start of row |
|
| 224 | + $html = EEH_HTML::tr('', 'event-cart-total-row', 'total_tr odd'); |
|
| 225 | + // event name td |
|
| 226 | + $html .= EEH_HTML::td( |
|
| 227 | + EEH_HTML::strong($line_item->name()), |
|
| 228 | + '', |
|
| 229 | + 'event-header', |
|
| 230 | + '', |
|
| 231 | + ' colspan="4"' |
|
| 232 | + ); |
|
| 233 | + // end of row |
|
| 234 | + $html .= EEH_HTML::trx(); |
|
| 235 | + return $html; |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * _ticket_row |
|
| 242 | + * |
|
| 243 | + * @param EE_Line_Item $line_item |
|
| 244 | + * @param array $options |
|
| 245 | + * @return mixed |
|
| 246 | + * @throws EE_Error |
|
| 247 | + */ |
|
| 248 | + private function _ticket_row(EE_Line_Item $line_item, $options = array()) |
|
| 249 | + { |
|
| 250 | + // start of row |
|
| 251 | + $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
| 252 | + $html = EEH_HTML::tr('', '', $row_class); |
|
| 253 | + // name && desc |
|
| 254 | + $name_and_desc = apply_filters( |
|
| 255 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
|
| 256 | + $line_item->name(), |
|
| 257 | + $line_item |
|
| 258 | + ); |
|
| 259 | + $name_and_desc .= apply_filters( |
|
| 260 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
|
| 261 | + ( |
|
| 262 | + $options['show_desc'] |
|
| 263 | + ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
| 264 | + : '' |
|
| 265 | + ), |
|
| 266 | + $line_item, |
|
| 267 | + $options |
|
| 268 | + ); |
|
| 269 | + $name_and_desc .= $line_item->is_taxable() ? ' * ' : ''; |
|
| 270 | + $name_and_desc = apply_filters( |
|
| 271 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__name_and_desc', |
|
| 272 | + $name_and_desc, |
|
| 273 | + $line_item, |
|
| 274 | + $options |
|
| 275 | + ); |
|
| 276 | + |
|
| 277 | + // name td |
|
| 278 | + $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
|
| 279 | + $name_and_desc, |
|
| 280 | + '', |
|
| 281 | + 'item_l' |
|
| 282 | + ); |
|
| 283 | + // price td |
|
| 284 | + $price = apply_filters( |
|
| 285 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__price', |
|
| 286 | + $line_item->unit_price_no_code(), |
|
| 287 | + $line_item |
|
| 288 | + ); |
|
| 289 | + $html .= EEH_HTML::td($price, '', 'item_c jst-rght'); |
|
| 290 | + // quantity td |
|
| 291 | + $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght'); |
|
| 292 | + $this->_total_items += $line_item->quantity(); |
|
| 293 | + // determine total for line item |
|
| 294 | + $total = apply_filters( |
|
| 295 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__total', |
|
| 296 | + $line_item->total(), |
|
| 297 | + $line_item |
|
| 298 | + ); |
|
| 299 | + $this->_events[ $options['event_id'] ] += $total; |
|
| 300 | + // total td |
|
| 301 | + $html .= EEH_HTML::td( |
|
| 302 | + EEH_Template::format_currency($total, false, false), |
|
| 303 | + '', |
|
| 304 | + 'item_r jst-rght' |
|
| 305 | + ); |
|
| 306 | + // end of row |
|
| 307 | + $html .= EEH_HTML::trx(); |
|
| 308 | + return $html; |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * _item_row |
|
| 315 | + * |
|
| 316 | + * @param EE_Line_Item $line_item |
|
| 317 | + * @param array $options |
|
| 318 | + * @return mixed |
|
| 319 | + * @throws EE_Error |
|
| 320 | + */ |
|
| 321 | + private function _item_row(EE_Line_Item $line_item, $options = array()) |
|
| 322 | + { |
|
| 323 | + // start of row |
|
| 324 | + $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
| 325 | + $html = EEH_HTML::tr('', '', $row_class); |
|
| 326 | + $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : ''; |
|
| 327 | + // name && desc |
|
| 328 | + $name_and_desc = apply_filters( |
|
| 329 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
|
| 330 | + $obj_name . $line_item->name(), |
|
| 331 | + $line_item |
|
| 332 | + ); |
|
| 333 | + $name_and_desc .= apply_filters( |
|
| 334 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
|
| 335 | + ( |
|
| 336 | + $options['show_desc'] |
|
| 337 | + ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
| 338 | + : '' |
|
| 339 | + ), |
|
| 340 | + $line_item, |
|
| 341 | + $options |
|
| 342 | + ); |
|
| 343 | + $name_and_desc .= $line_item->is_taxable() ? ' * ' : ''; |
|
| 344 | + $name_and_desc = apply_filters( |
|
| 345 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy___item_row__name_and_desc', |
|
| 346 | + $name_and_desc, |
|
| 347 | + $line_item, |
|
| 348 | + $options |
|
| 349 | + ); |
|
| 350 | + |
|
| 351 | + // name td |
|
| 352 | + $html .= EEH_HTML::td($name_and_desc, '', 'item_l'); |
|
| 353 | + // price td |
|
| 354 | + if ($line_item->is_percent()) { |
|
| 355 | + $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c jst-rght'); |
|
| 356 | + } else { |
|
| 357 | + $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
|
| 358 | + } |
|
| 359 | + // quantity td |
|
| 360 | + $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght'); |
|
| 361 | + // $total = $line_item->total() * $line_item->quantity(); |
|
| 362 | + $total = $line_item->total(); |
|
| 363 | + if (isset($options['event_id'], $this->_events[ $options['event_id'] ])) { |
|
| 364 | + $this->_events[ $options['event_id'] ] += $total; |
|
| 365 | + } |
|
| 366 | + // total td |
|
| 367 | + $html .= EEH_HTML::td( |
|
| 368 | + EEH_Template::format_currency($total, false, false), |
|
| 369 | + '', |
|
| 370 | + 'item_r jst-rght' |
|
| 371 | + ); |
|
| 372 | + // end of row |
|
| 373 | + $html .= EEH_HTML::trx(); |
|
| 374 | + return $html; |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + |
|
| 378 | + |
|
| 379 | + /** |
|
| 380 | + * _sub_item_row |
|
| 381 | + * |
|
| 382 | + * @param EE_Line_Item $line_item |
|
| 383 | + * @param array $options |
|
| 384 | + * @param EE_Line_Item $parent_line_item |
|
| 385 | + * @return mixed |
|
| 386 | + * @throws EE_Error |
|
| 387 | + */ |
|
| 388 | + private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null) |
|
| 389 | + { |
|
| 390 | + if ($parent_line_item instanceof EE_Line_Item |
|
| 391 | + && $line_item->children() === array() |
|
| 392 | + && $line_item->name() === $parent_line_item->name() |
|
| 393 | + && apply_filters( |
|
| 394 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__hide_main_sub_line_item', |
|
| 395 | + true |
|
| 396 | + ) |
|
| 397 | + ) { |
|
| 398 | + return ''; |
|
| 399 | + } |
|
| 400 | + // start of row |
|
| 401 | + $html = EEH_HTML::tr('', '', 'item sub-item-row'); |
|
| 402 | + // name && desc |
|
| 403 | + $name_and_desc = EEH_HTML::span('', '', 'sub-item-row-bullet dashicons dashicons-arrow-right') |
|
| 404 | + . $line_item->name(); |
|
| 405 | + $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: ' |
|
| 406 | + . $line_item->desc() |
|
| 407 | + . '</span>' : ''; |
|
| 408 | + // name td |
|
| 409 | + $html .= EEH_HTML::td($name_and_desc, '', 'item_l sub-item'); |
|
| 410 | + $qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1; |
|
| 411 | + // discount/surcharge td |
|
| 412 | + if ($line_item->is_percent()) { |
|
| 413 | + $html .= EEH_HTML::td( |
|
| 414 | + EEH_Template::format_currency( |
|
| 415 | + $line_item->total() / $qty, |
|
| 416 | + false, |
|
| 417 | + false |
|
| 418 | + ), |
|
| 419 | + '', |
|
| 420 | + 'item_c jst-rght' |
|
| 421 | + ); |
|
| 422 | + } else { |
|
| 423 | + $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
|
| 424 | + } |
|
| 425 | + // no quantity td |
|
| 426 | + $html .= EEH_HTML::td(); |
|
| 427 | + // no total td |
|
| 428 | + $html .= EEH_HTML::td(); |
|
| 429 | + // end of row |
|
| 430 | + $html .= EEH_HTML::trx(); |
|
| 431 | + $html = apply_filters( |
|
| 432 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__html', |
|
| 433 | + $html, |
|
| 434 | + $line_item, |
|
| 435 | + $options, |
|
| 436 | + $parent_line_item |
|
| 437 | + ); |
|
| 438 | + return $html; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + |
|
| 442 | + |
|
| 443 | + /** |
|
| 444 | + * _tax_row |
|
| 445 | + * |
|
| 446 | + * @param EE_Line_Item $line_item |
|
| 447 | + * @param array $options |
|
| 448 | + * @return mixed |
|
| 449 | + * @throws EE_Error |
|
| 450 | + */ |
|
| 451 | + private function _tax_row(EE_Line_Item $line_item, $options = array()) |
|
| 452 | + { |
|
| 453 | + // start of row |
|
| 454 | + $html = EEH_HTML::tr('', 'item sub-item tax-total'); |
|
| 455 | + // name && desc |
|
| 456 | + $name_and_desc = $line_item->name(); |
|
| 457 | + $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">' |
|
| 458 | + . esc_html__(' * taxable items', 'event_espresso') . '</span>'; |
|
| 459 | + $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : ''; |
|
| 460 | + // name td |
|
| 461 | + $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
|
| 462 | + $name_and_desc, |
|
| 463 | + '', |
|
| 464 | + 'item_l sub-item' |
|
| 465 | + ); |
|
| 466 | + // percent td |
|
| 467 | + $html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', ''); |
|
| 468 | + // empty td (price) |
|
| 469 | + $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
|
| 470 | + // total td |
|
| 471 | + $html .= EEH_HTML::td( |
|
| 472 | + EEH_Template::format_currency( |
|
| 473 | + $line_item->total(), |
|
| 474 | + false, |
|
| 475 | + false |
|
| 476 | + ), |
|
| 477 | + '', |
|
| 478 | + 'item_r jst-rght' |
|
| 479 | + ); |
|
| 480 | + // end of row |
|
| 481 | + $html .= EEH_HTML::trx(); |
|
| 482 | + return $html; |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + |
|
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * _total_row |
|
| 489 | + * |
|
| 490 | + * @param EE_Line_Item $line_item |
|
| 491 | + * @param string $text |
|
| 492 | + * @return mixed |
|
| 493 | + * @throws EE_Error |
|
| 494 | + */ |
|
| 495 | + private function _total_tax_row(EE_Line_Item $line_item, $text = '') |
|
| 496 | + { |
|
| 497 | + $html = ''; |
|
| 498 | + if ($line_item->total()) { |
|
| 499 | + // start of row |
|
| 500 | + $html = EEH_HTML::tr('', '', 'total_tr odd'); |
|
| 501 | + // total td |
|
| 502 | + $html .= EEH_HTML::td( |
|
| 503 | + $text, |
|
| 504 | + '', |
|
| 505 | + 'total_currency total jst-rght', |
|
| 506 | + '', |
|
| 507 | + ' colspan="2"' |
|
| 508 | + ); |
|
| 509 | + // empty td (price) |
|
| 510 | + $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
|
| 511 | + // total td |
|
| 512 | + $html .= EEH_HTML::td( |
|
| 513 | + EEH_Template::format_currency($line_item->total(), false, false), |
|
| 514 | + '', |
|
| 515 | + 'total jst-rght' |
|
| 516 | + ); |
|
| 517 | + // end of row |
|
| 518 | + $html .= EEH_HTML::trx(); |
|
| 519 | + } |
|
| 520 | + return $html; |
|
| 521 | + } |
|
| 522 | + |
|
| 523 | + |
|
| 524 | + |
|
| 525 | + /** |
|
| 526 | + * _total_row |
|
| 527 | + * |
|
| 528 | + * @param EE_Line_Item $line_item |
|
| 529 | + * @param string $text |
|
| 530 | + * @param array $options |
|
| 531 | + * @return mixed |
|
| 532 | + * @throws EE_Error |
|
| 533 | + */ |
|
| 534 | + private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array()) |
|
| 535 | + { |
|
| 536 | + $html = ''; |
|
| 537 | + if ($line_item->total()) { |
|
| 538 | + // start of row |
|
| 539 | + $html = EEH_HTML::tr('', '', 'total_tr odd'); |
|
| 540 | + // total td |
|
| 541 | + $html .= EEH_HTML::td( |
|
| 542 | + $text, |
|
| 543 | + '', |
|
| 544 | + 'total_currency total jst-rght', |
|
| 545 | + '', |
|
| 546 | + ' colspan="3"' |
|
| 547 | + ); |
|
| 548 | + // total td |
|
| 549 | + $html .= EEH_HTML::td( |
|
| 550 | + EEH_Template::format_currency($options['sub_total'], false, false), |
|
| 551 | + '', |
|
| 552 | + 'total jst-rght' |
|
| 553 | + ); |
|
| 554 | + // end of row |
|
| 555 | + $html .= EEH_HTML::trx(); |
|
| 556 | + } |
|
| 557 | + return $html; |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + |
|
| 561 | + |
|
| 562 | + /** |
|
| 563 | + * _total_row |
|
| 564 | + * |
|
| 565 | + * @param EE_Line_Item $line_item |
|
| 566 | + * @param string $text |
|
| 567 | + * @return mixed |
|
| 568 | + * @throws EE_Error |
|
| 569 | + */ |
|
| 570 | + private function _total_row(EE_Line_Item $line_item, $text = '') |
|
| 571 | + { |
|
| 572 | + // start of row |
|
| 573 | + $html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd'); |
|
| 574 | + // total td |
|
| 575 | + $html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"'); |
|
| 576 | + // total td |
|
| 577 | + $html .= EEH_HTML::td( |
|
| 578 | + EEH_Template::format_currency($line_item->total(), false, false), |
|
| 579 | + '', |
|
| 580 | + 'total jst-rght' |
|
| 581 | + ); |
|
| 582 | + // end of row |
|
| 583 | + $html .= EEH_HTML::trx(); |
|
| 584 | + return $html; |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + |
|
| 588 | + |
|
| 589 | + /** |
|
| 590 | + * _payments_and_amount_owing_rows |
|
| 591 | + * |
|
| 592 | + * @param EE_Line_Item $line_item |
|
| 593 | + * @param array $options |
|
| 594 | + * @return mixed |
|
| 595 | + * @throws EE_Error |
|
| 596 | + */ |
|
| 597 | + private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array()) |
|
| 598 | + { |
|
| 599 | + $html = ''; |
|
| 600 | + $owing = $line_item->total(); |
|
| 601 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID()); |
|
| 602 | + if ($transaction instanceof EE_Transaction) { |
|
| 603 | + $registration_payments = array(); |
|
| 604 | + $registrations = ! empty($options['registrations']) |
|
| 605 | + ? $options['registrations'] |
|
| 606 | + : $transaction->registrations(); |
|
| 607 | + foreach ($registrations as $registration) { |
|
| 608 | + if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) { |
|
| 609 | + $registration_payments += $registration->registration_payments(); |
|
| 610 | + } |
|
| 611 | + } |
|
| 612 | + if (! empty($registration_payments)) { |
|
| 613 | + foreach ($registration_payments as $registration_payment) { |
|
| 614 | + if ($registration_payment instanceof EE_Registration_Payment) { |
|
| 615 | + $owing -= $registration_payment->amount(); |
|
| 616 | + $payment = $registration_payment->payment(); |
|
| 617 | + $payment_desc = ''; |
|
| 618 | + if ($payment instanceof EE_Payment) { |
|
| 619 | + $payment_desc = sprintf( |
|
| 620 | + esc_html__('Payment%1$s Received: %2$s', 'event_espresso'), |
|
| 621 | + $payment->txn_id_chq_nmbr() !== '' |
|
| 622 | + ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> ' |
|
| 623 | + : '', |
|
| 624 | + $payment->timestamp() |
|
| 625 | + ); |
|
| 626 | + } |
|
| 627 | + // start of row |
|
| 628 | + $html .= EEH_HTML::tr('', '', 'total_tr odd'); |
|
| 629 | + // payment desc |
|
| 630 | + $html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"'); |
|
| 631 | + // total td |
|
| 632 | + $html .= EEH_HTML::td( |
|
| 633 | + EEH_Template::format_currency( |
|
| 634 | + $registration_payment->amount(), |
|
| 635 | + false, |
|
| 636 | + false |
|
| 637 | + ), |
|
| 638 | + '', |
|
| 639 | + 'total jst-rght' |
|
| 640 | + ); |
|
| 641 | + // end of row |
|
| 642 | + $html .= EEH_HTML::trx(); |
|
| 643 | + } |
|
| 644 | + } |
|
| 645 | + if ($line_item->total()) { |
|
| 646 | + // start of row |
|
| 647 | + $html .= EEH_HTML::tr('', '', 'total_tr odd'); |
|
| 648 | + // total td |
|
| 649 | + $html .= EEH_HTML::td( |
|
| 650 | + esc_html__('Amount Owing', 'event_espresso'), |
|
| 651 | + '', |
|
| 652 | + 'total_currency total jst-rght', |
|
| 653 | + '', |
|
| 654 | + ' colspan="3"' |
|
| 655 | + ); |
|
| 656 | + // total td |
|
| 657 | + $html .= EEH_HTML::td( |
|
| 658 | + EEH_Template::format_currency($owing, false, false), |
|
| 659 | + '', |
|
| 660 | + 'total jst-rght' |
|
| 661 | + ); |
|
| 662 | + // end of row |
|
| 663 | + $html .= EEH_HTML::trx(); |
|
| 664 | + } |
|
| 665 | + } |
|
| 666 | + } |
|
| 667 | + $this->_grand_total = $owing; |
|
| 668 | + return $html; |
|
| 669 | + } |
|
| 670 | 670 | } |
@@ -13,2558 +13,2558 @@ |
||
| 13 | 13 | class Transactions_Admin_Page extends EE_Admin_Page |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @var EE_Transaction |
|
| 18 | - */ |
|
| 19 | - private $_transaction; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * @var EE_Session |
|
| 23 | - */ |
|
| 24 | - private $_session; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @var array $_txn_status |
|
| 28 | - */ |
|
| 29 | - private static $_txn_status; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var array $_pay_status |
|
| 33 | - */ |
|
| 34 | - private static $_pay_status; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var array $_existing_reg_payment_REG_IDs |
|
| 38 | - */ |
|
| 39 | - protected $_existing_reg_payment_REG_IDs; |
|
| 40 | - |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * _init_page_props |
|
| 44 | - * |
|
| 45 | - * @return void |
|
| 46 | - */ |
|
| 47 | - protected function _init_page_props() |
|
| 48 | - { |
|
| 49 | - $this->page_slug = TXN_PG_SLUG; |
|
| 50 | - $this->page_label = esc_html__('Transactions', 'event_espresso'); |
|
| 51 | - $this->_admin_base_url = TXN_ADMIN_URL; |
|
| 52 | - $this->_admin_base_path = TXN_ADMIN; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * _ajax_hooks |
|
| 58 | - * |
|
| 59 | - * @return void |
|
| 60 | - */ |
|
| 61 | - protected function _ajax_hooks() |
|
| 62 | - { |
|
| 63 | - add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds')); |
|
| 64 | - add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds')); |
|
| 65 | - add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment')); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * _define_page_props |
|
| 71 | - * |
|
| 72 | - * @return void |
|
| 73 | - */ |
|
| 74 | - protected function _define_page_props() |
|
| 75 | - { |
|
| 76 | - $this->_admin_page_title = $this->page_label; |
|
| 77 | - $this->_labels = array( |
|
| 78 | - 'buttons' => array( |
|
| 79 | - 'add' => esc_html__('Add New Transaction', 'event_espresso'), |
|
| 80 | - 'edit' => esc_html__('Edit Transaction', 'event_espresso'), |
|
| 81 | - 'delete' => esc_html__('Delete Transaction', 'event_espresso'), |
|
| 82 | - ), |
|
| 83 | - ); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * grab url requests and route them |
|
| 89 | - * |
|
| 90 | - * @access private |
|
| 91 | - * @return void |
|
| 92 | - * @throws EE_Error |
|
| 93 | - * @throws InvalidArgumentException |
|
| 94 | - * @throws InvalidDataTypeException |
|
| 95 | - * @throws InvalidInterfaceException |
|
| 96 | - */ |
|
| 97 | - public function _set_page_routes() |
|
| 98 | - { |
|
| 99 | - |
|
| 100 | - $this->_set_transaction_status_array(); |
|
| 101 | - |
|
| 102 | - $txn_id = ! empty($this->_req_data['TXN_ID']) |
|
| 103 | - && ! is_array($this->_req_data['TXN_ID']) |
|
| 104 | - ? $this->_req_data['TXN_ID'] |
|
| 105 | - : 0; |
|
| 106 | - |
|
| 107 | - $this->_page_routes = array( |
|
| 108 | - |
|
| 109 | - 'default' => array( |
|
| 110 | - 'func' => '_transactions_overview_list_table', |
|
| 111 | - 'capability' => 'ee_read_transactions', |
|
| 112 | - ), |
|
| 113 | - |
|
| 114 | - 'view_transaction' => array( |
|
| 115 | - 'func' => '_transaction_details', |
|
| 116 | - 'capability' => 'ee_read_transaction', |
|
| 117 | - 'obj_id' => $txn_id, |
|
| 118 | - ), |
|
| 119 | - |
|
| 120 | - 'send_payment_reminder' => array( |
|
| 121 | - 'func' => '_send_payment_reminder', |
|
| 122 | - 'noheader' => true, |
|
| 123 | - 'capability' => 'ee_send_message', |
|
| 124 | - ), |
|
| 125 | - |
|
| 126 | - 'espresso_apply_payment' => array( |
|
| 127 | - 'func' => 'apply_payments_or_refunds', |
|
| 128 | - 'noheader' => true, |
|
| 129 | - 'capability' => 'ee_edit_payments', |
|
| 130 | - ), |
|
| 131 | - |
|
| 132 | - 'espresso_apply_refund' => array( |
|
| 133 | - 'func' => 'apply_payments_or_refunds', |
|
| 134 | - 'noheader' => true, |
|
| 135 | - 'capability' => 'ee_edit_payments', |
|
| 136 | - ), |
|
| 137 | - |
|
| 138 | - 'espresso_delete_payment' => array( |
|
| 139 | - 'func' => 'delete_payment', |
|
| 140 | - 'noheader' => true, |
|
| 141 | - 'capability' => 'ee_delete_payments', |
|
| 142 | - ), |
|
| 143 | - |
|
| 144 | - 'espresso_recalculate_line_items' => array( |
|
| 145 | - 'func' => 'recalculateLineItems', |
|
| 146 | - 'noheader' => true, |
|
| 147 | - 'capability' => 'ee_edit_payments', |
|
| 148 | - ), |
|
| 149 | - |
|
| 150 | - ); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - |
|
| 154 | - protected function _set_page_config() |
|
| 155 | - { |
|
| 156 | - $this->_page_config = array( |
|
| 157 | - 'default' => array( |
|
| 158 | - 'nav' => array( |
|
| 159 | - 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 160 | - 'order' => 10, |
|
| 161 | - ), |
|
| 162 | - 'list_table' => 'EE_Admin_Transactions_List_Table', |
|
| 163 | - 'help_tabs' => array( |
|
| 164 | - 'transactions_overview_help_tab' => array( |
|
| 165 | - 'title' => esc_html__('Transactions Overview', 'event_espresso'), |
|
| 166 | - 'filename' => 'transactions_overview', |
|
| 167 | - ), |
|
| 168 | - 'transactions_overview_table_column_headings_help_tab' => array( |
|
| 169 | - 'title' => esc_html__('Transactions Table Column Headings', 'event_espresso'), |
|
| 170 | - 'filename' => 'transactions_overview_table_column_headings', |
|
| 171 | - ), |
|
| 172 | - 'transactions_overview_views_filters_help_tab' => array( |
|
| 173 | - 'title' => esc_html__('Transaction Views & Filters & Search', 'event_espresso'), |
|
| 174 | - 'filename' => 'transactions_overview_views_filters_search', |
|
| 175 | - ), |
|
| 176 | - ), |
|
| 177 | - 'help_tour' => array('Transactions_Overview_Help_Tour'), |
|
| 178 | - /** |
|
| 179 | - * commented out because currently we are not displaying tips for transaction list table status but this |
|
| 180 | - * may change in a later iteration so want to keep the code for then. |
|
| 181 | - */ |
|
| 182 | - // 'qtips' => array( 'Transactions_List_Table_Tips' ), |
|
| 183 | - 'require_nonce' => false, |
|
| 184 | - ), |
|
| 185 | - 'view_transaction' => array( |
|
| 186 | - 'nav' => array( |
|
| 187 | - 'label' => esc_html__('View Transaction', 'event_espresso'), |
|
| 188 | - 'order' => 5, |
|
| 189 | - 'url' => isset($this->_req_data['TXN_ID']) |
|
| 190 | - ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']), $this->_current_page_view_url) |
|
| 191 | - : $this->_admin_base_url, |
|
| 192 | - 'persistent' => false, |
|
| 193 | - ), |
|
| 194 | - 'help_tabs' => array( |
|
| 195 | - 'transactions_view_transaction_help_tab' => array( |
|
| 196 | - 'title' => esc_html__('View Transaction', 'event_espresso'), |
|
| 197 | - 'filename' => 'transactions_view_transaction', |
|
| 198 | - ), |
|
| 199 | - 'transactions_view_transaction_transaction_details_table_help_tab' => array( |
|
| 200 | - 'title' => esc_html__('Transaction Details Table', 'event_espresso'), |
|
| 201 | - 'filename' => 'transactions_view_transaction_transaction_details_table', |
|
| 202 | - ), |
|
| 203 | - 'transactions_view_transaction_attendees_registered_help_tab' => array( |
|
| 204 | - 'title' => esc_html__('Attendees Registered', 'event_espresso'), |
|
| 205 | - 'filename' => 'transactions_view_transaction_attendees_registered', |
|
| 206 | - ), |
|
| 207 | - 'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array( |
|
| 208 | - 'title' => esc_html__('Primary Registrant & Billing Information', 'event_espresso'), |
|
| 209 | - 'filename' => 'transactions_view_transaction_primary_registrant_billing_information', |
|
| 210 | - ), |
|
| 211 | - ), |
|
| 212 | - 'qtips' => array('Transaction_Details_Tips'), |
|
| 213 | - 'help_tour' => array('Transaction_Details_Help_Tour'), |
|
| 214 | - 'metaboxes' => array('_transaction_details_metaboxes'), |
|
| 215 | - |
|
| 216 | - 'require_nonce' => false, |
|
| 217 | - ), |
|
| 218 | - ); |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * The below methods aren't used by this class currently |
|
| 224 | - */ |
|
| 225 | - protected function _add_screen_options() |
|
| 226 | - { |
|
| 227 | - // noop |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - protected function _add_feature_pointers() |
|
| 232 | - { |
|
| 233 | - // noop |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - |
|
| 237 | - public function admin_init() |
|
| 238 | - { |
|
| 239 | - // IF a registration was JUST added via the admin... |
|
| 240 | - if (isset( |
|
| 241 | - $this->_req_data['redirect_from'], |
|
| 242 | - $this->_req_data['EVT_ID'], |
|
| 243 | - $this->_req_data['event_name'] |
|
| 244 | - )) { |
|
| 245 | - // then set a cookie so that we can block any attempts to use |
|
| 246 | - // the back button as a way to enter another registration. |
|
| 247 | - setcookie( |
|
| 248 | - 'ee_registration_added', |
|
| 249 | - $this->_req_data['EVT_ID'], |
|
| 250 | - time() + WEEK_IN_SECONDS, |
|
| 251 | - '/' |
|
| 252 | - ); |
|
| 253 | - // and update the global |
|
| 254 | - $_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID']; |
|
| 255 | - } |
|
| 256 | - EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__( |
|
| 257 | - 'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.', |
|
| 258 | - 'event_espresso' |
|
| 259 | - ); |
|
| 260 | - EE_Registry::$i18n_js_strings['error_occurred'] = esc_html__( |
|
| 261 | - 'An error occurred! Please refresh the page and try again.', |
|
| 262 | - 'event_espresso' |
|
| 263 | - ); |
|
| 264 | - EE_Registry::$i18n_js_strings['txn_status_array'] = self::$_txn_status; |
|
| 265 | - EE_Registry::$i18n_js_strings['pay_status_array'] = self::$_pay_status; |
|
| 266 | - EE_Registry::$i18n_js_strings['payments_total'] = esc_html__('Payments Total', 'event_espresso'); |
|
| 267 | - EE_Registry::$i18n_js_strings['transaction_overpaid'] = esc_html__( |
|
| 268 | - 'This transaction has been overpaid ! Payments Total', |
|
| 269 | - 'event_espresso' |
|
| 270 | - ); |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - |
|
| 274 | - public function admin_notices() |
|
| 275 | - { |
|
| 276 | - // noop |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - |
|
| 280 | - public function admin_footer_scripts() |
|
| 281 | - { |
|
| 282 | - // noop |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * _set_transaction_status_array |
|
| 288 | - * sets list of transaction statuses |
|
| 289 | - * |
|
| 290 | - * @access private |
|
| 291 | - * @return void |
|
| 292 | - * @throws EE_Error |
|
| 293 | - * @throws InvalidArgumentException |
|
| 294 | - * @throws InvalidDataTypeException |
|
| 295 | - * @throws InvalidInterfaceException |
|
| 296 | - */ |
|
| 297 | - private function _set_transaction_status_array() |
|
| 298 | - { |
|
| 299 | - self::$_txn_status = EEM_Transaction::instance()->status_array(true); |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - |
|
| 303 | - /** |
|
| 304 | - * get_transaction_status_array |
|
| 305 | - * return the transaction status array for wp_list_table |
|
| 306 | - * |
|
| 307 | - * @access public |
|
| 308 | - * @return array |
|
| 309 | - */ |
|
| 310 | - public function get_transaction_status_array() |
|
| 311 | - { |
|
| 312 | - return self::$_txn_status; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * get list of payment statuses |
|
| 318 | - * |
|
| 319 | - * @access private |
|
| 320 | - * @return void |
|
| 321 | - * @throws EE_Error |
|
| 322 | - * @throws InvalidArgumentException |
|
| 323 | - * @throws InvalidDataTypeException |
|
| 324 | - * @throws InvalidInterfaceException |
|
| 325 | - */ |
|
| 326 | - private function _get_payment_status_array() |
|
| 327 | - { |
|
| 328 | - self::$_pay_status = EEM_Payment::instance()->status_array(true); |
|
| 329 | - $this->_template_args['payment_status'] = self::$_pay_status; |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - |
|
| 333 | - /** |
|
| 334 | - * _add_screen_options_default |
|
| 335 | - * |
|
| 336 | - * @access protected |
|
| 337 | - * @return void |
|
| 338 | - * @throws InvalidArgumentException |
|
| 339 | - * @throws InvalidDataTypeException |
|
| 340 | - * @throws InvalidInterfaceException |
|
| 341 | - */ |
|
| 342 | - protected function _add_screen_options_default() |
|
| 343 | - { |
|
| 344 | - $this->_per_page_screen_option(); |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - |
|
| 348 | - /** |
|
| 349 | - * load_scripts_styles |
|
| 350 | - * |
|
| 351 | - * @access public |
|
| 352 | - * @return void |
|
| 353 | - */ |
|
| 354 | - public function load_scripts_styles() |
|
| 355 | - { |
|
| 356 | - // enqueue style |
|
| 357 | - wp_register_style( |
|
| 358 | - 'espresso_txn', |
|
| 359 | - TXN_ASSETS_URL . 'espresso_transactions_admin.css', |
|
| 360 | - array(), |
|
| 361 | - EVENT_ESPRESSO_VERSION |
|
| 362 | - ); |
|
| 363 | - wp_enqueue_style('espresso_txn'); |
|
| 364 | - // scripts |
|
| 365 | - wp_register_script( |
|
| 366 | - 'espresso_txn', |
|
| 367 | - TXN_ASSETS_URL . 'espresso_transactions_admin.js', |
|
| 368 | - array( |
|
| 369 | - 'ee_admin_js', |
|
| 370 | - 'ee-datepicker', |
|
| 371 | - 'jquery-ui-datepicker', |
|
| 372 | - 'jquery-ui-draggable', |
|
| 373 | - 'ee-dialog', |
|
| 374 | - 'ee-accounting', |
|
| 375 | - 'ee-serialize-full-array', |
|
| 376 | - ), |
|
| 377 | - EVENT_ESPRESSO_VERSION, |
|
| 378 | - true |
|
| 379 | - ); |
|
| 380 | - wp_enqueue_script('espresso_txn'); |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * load_scripts_styles_view_transaction |
|
| 386 | - * |
|
| 387 | - * @access public |
|
| 388 | - * @return void |
|
| 389 | - */ |
|
| 390 | - public function load_scripts_styles_view_transaction() |
|
| 391 | - { |
|
| 392 | - // styles |
|
| 393 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * load_scripts_styles_default |
|
| 399 | - * |
|
| 400 | - * @access public |
|
| 401 | - * @return void |
|
| 402 | - */ |
|
| 403 | - public function load_scripts_styles_default() |
|
| 404 | - { |
|
| 405 | - // styles |
|
| 406 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * _set_list_table_views_default |
|
| 412 | - * |
|
| 413 | - * @access protected |
|
| 414 | - * @return void |
|
| 415 | - */ |
|
| 416 | - protected function _set_list_table_views_default() |
|
| 417 | - { |
|
| 418 | - $this->_views = array( |
|
| 419 | - 'all' => array( |
|
| 420 | - 'slug' => 'all', |
|
| 421 | - 'label' => esc_html__('View All Transactions', 'event_espresso'), |
|
| 422 | - 'count' => 0, |
|
| 423 | - ), |
|
| 424 | - 'abandoned' => array( |
|
| 425 | - 'slug' => 'abandoned', |
|
| 426 | - 'label' => esc_html__('Abandoned Transactions', 'event_espresso'), |
|
| 427 | - 'count' => 0, |
|
| 428 | - ), |
|
| 429 | - 'incomplete' => array( |
|
| 430 | - 'slug' => 'incomplete', |
|
| 431 | - 'label' => esc_html__('Incomplete Transactions', 'event_espresso'), |
|
| 432 | - 'count' => 0, |
|
| 433 | - ), |
|
| 434 | - ); |
|
| 435 | - if (/** |
|
| 436 | - * Filters whether a link to the "Failed Transactions" list table |
|
| 437 | - * appears on the Transactions Admin Page list table. |
|
| 438 | - * List display can be turned back on via the following: |
|
| 439 | - * add_filter( |
|
| 440 | - * 'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list', |
|
| 441 | - * '__return_true' |
|
| 442 | - * ); |
|
| 443 | - * |
|
| 444 | - * @since 4.9.70.p |
|
| 445 | - * @param boolean $display_failed_txns_list |
|
| 446 | - * @param Transactions_Admin_Page $this |
|
| 447 | - */ |
|
| 448 | - apply_filters( |
|
| 449 | - 'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list', |
|
| 450 | - false, |
|
| 451 | - $this |
|
| 452 | - ) |
|
| 453 | - ) { |
|
| 454 | - $this->_views['failed'] = array( |
|
| 455 | - 'slug' => 'failed', |
|
| 456 | - 'label' => esc_html__('Failed Transactions', 'event_espresso'), |
|
| 457 | - 'count' => 0, |
|
| 458 | - ); |
|
| 459 | - } |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * _set_transaction_object |
|
| 465 | - * This sets the _transaction property for the transaction details screen |
|
| 466 | - * |
|
| 467 | - * @access private |
|
| 468 | - * @return void |
|
| 469 | - * @throws EE_Error |
|
| 470 | - * @throws InvalidArgumentException |
|
| 471 | - * @throws RuntimeException |
|
| 472 | - * @throws InvalidDataTypeException |
|
| 473 | - * @throws InvalidInterfaceException |
|
| 474 | - * @throws ReflectionException |
|
| 475 | - */ |
|
| 476 | - private function _set_transaction_object() |
|
| 477 | - { |
|
| 478 | - if ($this->_transaction instanceof EE_Transaction) { |
|
| 479 | - return; |
|
| 480 | - } //get out we've already set the object |
|
| 481 | - |
|
| 482 | - $TXN_ID = ! empty($this->_req_data['TXN_ID']) |
|
| 483 | - ? absint($this->_req_data['TXN_ID']) |
|
| 484 | - : false; |
|
| 485 | - |
|
| 486 | - // get transaction object |
|
| 487 | - $this->_transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 488 | - $this->_session = $this->_transaction instanceof EE_Transaction |
|
| 489 | - ? $this->_transaction->session_data() |
|
| 490 | - : null; |
|
| 491 | - if ($this->_transaction instanceof EE_Transaction) { |
|
| 492 | - $this->_transaction->verify_abandoned_transaction_status(); |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - if (! $this->_transaction instanceof EE_Transaction) { |
|
| 496 | - $error_msg = sprintf( |
|
| 497 | - esc_html__( |
|
| 498 | - 'An error occurred and the details for the transaction with the ID # %d could not be retrieved.', |
|
| 499 | - 'event_espresso' |
|
| 500 | - ), |
|
| 501 | - $TXN_ID |
|
| 502 | - ); |
|
| 503 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 504 | - } |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - |
|
| 508 | - /** |
|
| 509 | - * _transaction_legend_items |
|
| 510 | - * |
|
| 511 | - * @access protected |
|
| 512 | - * @return array |
|
| 513 | - * @throws EE_Error |
|
| 514 | - * @throws InvalidArgumentException |
|
| 515 | - * @throws ReflectionException |
|
| 516 | - * @throws InvalidDataTypeException |
|
| 517 | - * @throws InvalidInterfaceException |
|
| 518 | - */ |
|
| 519 | - protected function _transaction_legend_items() |
|
| 520 | - { |
|
| 521 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 522 | - $items = array(); |
|
| 523 | - |
|
| 524 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 525 | - 'ee_read_global_messages', |
|
| 526 | - 'view_filtered_messages' |
|
| 527 | - )) { |
|
| 528 | - $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 529 | - if (is_array($related_for_icon) |
|
| 530 | - && isset($related_for_icon['css_class'], $related_for_icon['label']) |
|
| 531 | - ) { |
|
| 532 | - $items['view_related_messages'] = array( |
|
| 533 | - 'class' => $related_for_icon['css_class'], |
|
| 534 | - 'desc' => $related_for_icon['label'], |
|
| 535 | - ); |
|
| 536 | - } |
|
| 537 | - } |
|
| 538 | - |
|
| 539 | - $items = apply_filters( |
|
| 540 | - 'FHEE__Transactions_Admin_Page___transaction_legend_items__items', |
|
| 541 | - array_merge( |
|
| 542 | - $items, |
|
| 543 | - array( |
|
| 544 | - 'view_details' => array( |
|
| 545 | - 'class' => 'dashicons dashicons-cart', |
|
| 546 | - 'desc' => esc_html__('View Transaction Details', 'event_espresso'), |
|
| 547 | - ), |
|
| 548 | - 'view_invoice' => array( |
|
| 549 | - 'class' => 'dashicons dashicons-media-spreadsheet', |
|
| 550 | - 'desc' => esc_html__('View Transaction Invoice', 'event_espresso'), |
|
| 551 | - ), |
|
| 552 | - 'view_receipt' => array( |
|
| 553 | - 'class' => 'dashicons dashicons-media-default', |
|
| 554 | - 'desc' => esc_html__('View Transaction Receipt', 'event_espresso'), |
|
| 555 | - ), |
|
| 556 | - 'view_registration' => array( |
|
| 557 | - 'class' => 'dashicons dashicons-clipboard', |
|
| 558 | - 'desc' => esc_html__('View Registration Details', 'event_espresso'), |
|
| 559 | - ), |
|
| 560 | - 'payment_overview_link' => array( |
|
| 561 | - 'class' => 'dashicons dashicons-money', |
|
| 562 | - 'desc' => esc_html__('Make Payment on Frontend', 'event_espresso'), |
|
| 563 | - ), |
|
| 564 | - ) |
|
| 565 | - ) |
|
| 566 | - ); |
|
| 567 | - |
|
| 568 | - if (EEH_MSG_Template::is_mt_active('payment_reminder') |
|
| 569 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 570 | - 'ee_send_message', |
|
| 571 | - 'espresso_transactions_send_payment_reminder' |
|
| 572 | - ) |
|
| 573 | - ) { |
|
| 574 | - $items['send_payment_reminder'] = array( |
|
| 575 | - 'class' => 'dashicons dashicons-email-alt', |
|
| 576 | - 'desc' => esc_html__('Send Payment Reminder', 'event_espresso'), |
|
| 577 | - ); |
|
| 578 | - } else { |
|
| 579 | - $items['blank*'] = array( |
|
| 580 | - 'class' => '', |
|
| 581 | - 'desc' => '', |
|
| 582 | - ); |
|
| 583 | - } |
|
| 584 | - $more_items = apply_filters( |
|
| 585 | - 'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items', |
|
| 586 | - array( |
|
| 587 | - 'overpaid' => array( |
|
| 588 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code, |
|
| 589 | - 'desc' => EEH_Template::pretty_status( |
|
| 590 | - EEM_Transaction::overpaid_status_code, |
|
| 591 | - false, |
|
| 592 | - 'sentence' |
|
| 593 | - ), |
|
| 594 | - ), |
|
| 595 | - 'complete' => array( |
|
| 596 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code, |
|
| 597 | - 'desc' => EEH_Template::pretty_status( |
|
| 598 | - EEM_Transaction::complete_status_code, |
|
| 599 | - false, |
|
| 600 | - 'sentence' |
|
| 601 | - ), |
|
| 602 | - ), |
|
| 603 | - 'incomplete' => array( |
|
| 604 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code, |
|
| 605 | - 'desc' => EEH_Template::pretty_status( |
|
| 606 | - EEM_Transaction::incomplete_status_code, |
|
| 607 | - false, |
|
| 608 | - 'sentence' |
|
| 609 | - ), |
|
| 610 | - ), |
|
| 611 | - 'abandoned' => array( |
|
| 612 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code, |
|
| 613 | - 'desc' => EEH_Template::pretty_status( |
|
| 614 | - EEM_Transaction::abandoned_status_code, |
|
| 615 | - false, |
|
| 616 | - 'sentence' |
|
| 617 | - ), |
|
| 618 | - ), |
|
| 619 | - 'failed' => array( |
|
| 620 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code, |
|
| 621 | - 'desc' => EEH_Template::pretty_status( |
|
| 622 | - EEM_Transaction::failed_status_code, |
|
| 623 | - false, |
|
| 624 | - 'sentence' |
|
| 625 | - ), |
|
| 626 | - ), |
|
| 627 | - ) |
|
| 628 | - ); |
|
| 629 | - |
|
| 630 | - return array_merge($items, $more_items); |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - |
|
| 634 | - /** |
|
| 635 | - * _transactions_overview_list_table |
|
| 636 | - * |
|
| 637 | - * @access protected |
|
| 638 | - * @return void |
|
| 639 | - * @throws DomainException |
|
| 640 | - * @throws EE_Error |
|
| 641 | - * @throws InvalidArgumentException |
|
| 642 | - * @throws InvalidDataTypeException |
|
| 643 | - * @throws InvalidInterfaceException |
|
| 644 | - * @throws ReflectionException |
|
| 645 | - */ |
|
| 646 | - protected function _transactions_overview_list_table() |
|
| 647 | - { |
|
| 648 | - $this->_admin_page_title = esc_html__('Transactions', 'event_espresso'); |
|
| 649 | - $event = isset($this->_req_data['EVT_ID']) |
|
| 650 | - ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']) |
|
| 651 | - : null; |
|
| 652 | - $this->_template_args['admin_page_header'] = $event instanceof EE_Event |
|
| 653 | - ? sprintf( |
|
| 654 | - esc_html__( |
|
| 655 | - '%sViewing Transactions for the Event: %s%s', |
|
| 656 | - 'event_espresso' |
|
| 657 | - ), |
|
| 658 | - '<h3>', |
|
| 659 | - '<a href="' |
|
| 660 | - . EE_Admin_Page::add_query_args_and_nonce( |
|
| 661 | - array('action' => 'edit', 'post' => $event->ID()), |
|
| 662 | - EVENTS_ADMIN_URL |
|
| 663 | - ) |
|
| 664 | - . '" title="' |
|
| 665 | - . esc_attr__( |
|
| 666 | - 'Click to Edit event', |
|
| 667 | - 'event_espresso' |
|
| 668 | - ) |
|
| 669 | - . '">' . $event->name() . '</a>', |
|
| 670 | - '</h3>' |
|
| 671 | - ) |
|
| 672 | - : ''; |
|
| 673 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items()); |
|
| 674 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 675 | - } |
|
| 676 | - |
|
| 677 | - |
|
| 678 | - /** |
|
| 679 | - * _transaction_details |
|
| 680 | - * generates HTML for the View Transaction Details Admin page |
|
| 681 | - * |
|
| 682 | - * @access protected |
|
| 683 | - * @return void |
|
| 684 | - * @throws DomainException |
|
| 685 | - * @throws EE_Error |
|
| 686 | - * @throws InvalidArgumentException |
|
| 687 | - * @throws InvalidDataTypeException |
|
| 688 | - * @throws InvalidInterfaceException |
|
| 689 | - * @throws RuntimeException |
|
| 690 | - * @throws ReflectionException |
|
| 691 | - */ |
|
| 692 | - protected function _transaction_details() |
|
| 693 | - { |
|
| 694 | - do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction); |
|
| 695 | - |
|
| 696 | - $this->_set_transaction_status_array(); |
|
| 697 | - |
|
| 698 | - $this->_template_args = array(); |
|
| 699 | - $this->_template_args['transactions_page'] = $this->_wp_page_slug; |
|
| 700 | - |
|
| 701 | - $this->_set_transaction_object(); |
|
| 702 | - |
|
| 703 | - if (! $this->_transaction instanceof EE_Transaction) { |
|
| 704 | - return; |
|
| 705 | - } |
|
| 706 | - $primary_registration = $this->_transaction->primary_registration(); |
|
| 707 | - $attendee = $primary_registration instanceof EE_Registration |
|
| 708 | - ? $primary_registration->attendee() |
|
| 709 | - : null; |
|
| 710 | - |
|
| 711 | - $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID(); |
|
| 712 | - $this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso'); |
|
| 713 | - |
|
| 714 | - $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp'); |
|
| 715 | - $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso'); |
|
| 716 | - |
|
| 717 | - $this->_template_args['txn_status']['value'] = self::$_txn_status[ $this->_transaction->status_ID() ]; |
|
| 718 | - $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso'); |
|
| 719 | - $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->status_ID(); |
|
| 720 | - |
|
| 721 | - $this->_template_args['grand_total'] = $this->_transaction->total(); |
|
| 722 | - $this->_template_args['total_paid'] = $this->_transaction->paid(); |
|
| 723 | - |
|
| 724 | - $amount_due = $this->_transaction->total() - $this->_transaction->paid(); |
|
| 725 | - $this->_template_args['amount_due'] = EEH_Template::format_currency( |
|
| 726 | - $amount_due, |
|
| 727 | - true |
|
| 728 | - ); |
|
| 729 | - if (EE_Registry::instance()->CFG->currency->sign_b4) { |
|
| 730 | - $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign |
|
| 731 | - . $this->_template_args['amount_due']; |
|
| 732 | - } else { |
|
| 733 | - $this->_template_args['amount_due'] .= EE_Registry::instance()->CFG->currency->sign; |
|
| 734 | - } |
|
| 735 | - $this->_template_args['amount_due_class'] = ''; |
|
| 736 | - |
|
| 737 | - if ($this->_transaction->paid() === $this->_transaction->total()) { |
|
| 738 | - // paid in full |
|
| 739 | - $this->_template_args['amount_due'] = false; |
|
| 740 | - } elseif ($this->_transaction->paid() > $this->_transaction->total()) { |
|
| 741 | - // overpaid |
|
| 742 | - $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 743 | - } elseif ($this->_transaction->total() > (float) 0) { |
|
| 744 | - if ($this->_transaction->paid() > (float) 0) { |
|
| 745 | - // monies owing |
|
| 746 | - $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn'; |
|
| 747 | - } elseif ($this->_transaction->paid() === (float) 0) { |
|
| 748 | - // no payments made yet |
|
| 749 | - $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 750 | - } |
|
| 751 | - } elseif ($this->_transaction->total() === (float) 0) { |
|
| 752 | - // free event |
|
| 753 | - $this->_template_args['amount_due'] = false; |
|
| 754 | - } |
|
| 755 | - |
|
| 756 | - $payment_method = $this->_transaction->payment_method(); |
|
| 757 | - |
|
| 758 | - $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method |
|
| 759 | - ? $payment_method->admin_name() |
|
| 760 | - : esc_html__('Unknown', 'event_espresso'); |
|
| 761 | - |
|
| 762 | - $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 763 | - // link back to overview |
|
| 764 | - $this->_template_args['txn_overview_url'] = ! empty($_SERVER['HTTP_REFERER']) |
|
| 765 | - ? $_SERVER['HTTP_REFERER'] |
|
| 766 | - : TXN_ADMIN_URL; |
|
| 767 | - |
|
| 768 | - |
|
| 769 | - // next link |
|
| 770 | - $next_txn = $this->_transaction->next( |
|
| 771 | - null, |
|
| 772 | - array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
| 773 | - 'TXN_ID' |
|
| 774 | - ); |
|
| 775 | - $this->_template_args['next_transaction'] = $next_txn |
|
| 776 | - ? $this->_next_link( |
|
| 777 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 778 | - array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']), |
|
| 779 | - TXN_ADMIN_URL |
|
| 780 | - ), |
|
| 781 | - 'dashicons dashicons-arrow-right ee-icon-size-22' |
|
| 782 | - ) |
|
| 783 | - : ''; |
|
| 784 | - // previous link |
|
| 785 | - $previous_txn = $this->_transaction->previous( |
|
| 786 | - null, |
|
| 787 | - array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
| 788 | - 'TXN_ID' |
|
| 789 | - ); |
|
| 790 | - $this->_template_args['previous_transaction'] = $previous_txn |
|
| 791 | - ? $this->_previous_link( |
|
| 792 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 793 | - array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']), |
|
| 794 | - TXN_ADMIN_URL |
|
| 795 | - ), |
|
| 796 | - 'dashicons dashicons-arrow-left ee-icon-size-22' |
|
| 797 | - ) |
|
| 798 | - : ''; |
|
| 799 | - |
|
| 800 | - // were we just redirected here after adding a new registration ??? |
|
| 801 | - if (isset( |
|
| 802 | - $this->_req_data['redirect_from'], |
|
| 803 | - $this->_req_data['EVT_ID'], |
|
| 804 | - $this->_req_data['event_name'] |
|
| 805 | - )) { |
|
| 806 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 807 | - 'ee_edit_registrations', |
|
| 808 | - 'espresso_registrations_new_registration', |
|
| 809 | - $this->_req_data['EVT_ID'] |
|
| 810 | - )) { |
|
| 811 | - $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="'; |
|
| 812 | - $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce( |
|
| 813 | - array( |
|
| 814 | - 'page' => 'espresso_registrations', |
|
| 815 | - 'action' => 'new_registration', |
|
| 816 | - 'return' => 'default', |
|
| 817 | - 'TXN_ID' => $this->_transaction->ID(), |
|
| 818 | - 'event_id' => $this->_req_data['EVT_ID'], |
|
| 819 | - ), |
|
| 820 | - REG_ADMIN_URL |
|
| 821 | - ); |
|
| 822 | - $this->_admin_page_title .= '">'; |
|
| 823 | - |
|
| 824 | - $this->_admin_page_title .= sprintf( |
|
| 825 | - esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'), |
|
| 826 | - htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8') |
|
| 827 | - ); |
|
| 828 | - $this->_admin_page_title .= '</a>'; |
|
| 829 | - } |
|
| 830 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 831 | - } |
|
| 832 | - // grab messages at the last second |
|
| 833 | - $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 834 | - // path to template |
|
| 835 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php'; |
|
| 836 | - $this->_template_args['admin_page_header'] = EEH_Template::display_template( |
|
| 837 | - $template_path, |
|
| 838 | - $this->_template_args, |
|
| 839 | - true |
|
| 840 | - ); |
|
| 841 | - |
|
| 842 | - // the details template wrapper |
|
| 843 | - $this->display_admin_page_with_sidebar(); |
|
| 844 | - } |
|
| 845 | - |
|
| 846 | - |
|
| 847 | - /** |
|
| 848 | - * _transaction_details_metaboxes |
|
| 849 | - * |
|
| 850 | - * @access protected |
|
| 851 | - * @return void |
|
| 852 | - * @throws EE_Error |
|
| 853 | - * @throws InvalidArgumentException |
|
| 854 | - * @throws InvalidDataTypeException |
|
| 855 | - * @throws InvalidInterfaceException |
|
| 856 | - * @throws RuntimeException |
|
| 857 | - * @throws ReflectionException |
|
| 858 | - */ |
|
| 859 | - protected function _transaction_details_metaboxes() |
|
| 860 | - { |
|
| 861 | - |
|
| 862 | - $this->_set_transaction_object(); |
|
| 863 | - |
|
| 864 | - if (! $this->_transaction instanceof EE_Transaction) { |
|
| 865 | - return; |
|
| 866 | - } |
|
| 867 | - add_meta_box( |
|
| 868 | - 'edit-txn-details-mbox', |
|
| 869 | - esc_html__('Transaction Details', 'event_espresso'), |
|
| 870 | - array($this, 'txn_details_meta_box'), |
|
| 871 | - $this->_wp_page_slug, |
|
| 872 | - 'normal', |
|
| 873 | - 'high' |
|
| 874 | - ); |
|
| 875 | - add_meta_box( |
|
| 876 | - 'edit-txn-attendees-mbox', |
|
| 877 | - esc_html__('Attendees Registered in this Transaction', 'event_espresso'), |
|
| 878 | - array($this, 'txn_attendees_meta_box'), |
|
| 879 | - $this->_wp_page_slug, |
|
| 880 | - 'normal', |
|
| 881 | - 'high', |
|
| 882 | - array('TXN_ID' => $this->_transaction->ID()) |
|
| 883 | - ); |
|
| 884 | - add_meta_box( |
|
| 885 | - 'edit-txn-registrant-mbox', |
|
| 886 | - esc_html__('Primary Contact', 'event_espresso'), |
|
| 887 | - array($this, 'txn_registrant_side_meta_box'), |
|
| 888 | - $this->_wp_page_slug, |
|
| 889 | - 'side', |
|
| 890 | - 'high' |
|
| 891 | - ); |
|
| 892 | - add_meta_box( |
|
| 893 | - 'edit-txn-billing-info-mbox', |
|
| 894 | - esc_html__('Billing Information', 'event_espresso'), |
|
| 895 | - array($this, 'txn_billing_info_side_meta_box'), |
|
| 896 | - $this->_wp_page_slug, |
|
| 897 | - 'side', |
|
| 898 | - 'high' |
|
| 899 | - ); |
|
| 900 | - } |
|
| 901 | - |
|
| 902 | - |
|
| 903 | - /** |
|
| 904 | - * Callback for transaction actions metabox. |
|
| 905 | - * |
|
| 906 | - * @param EE_Transaction|null $transaction |
|
| 907 | - * @return string |
|
| 908 | - * @throws DomainException |
|
| 909 | - * @throws EE_Error |
|
| 910 | - * @throws InvalidArgumentException |
|
| 911 | - * @throws InvalidDataTypeException |
|
| 912 | - * @throws InvalidInterfaceException |
|
| 913 | - * @throws ReflectionException |
|
| 914 | - * @throws RuntimeException |
|
| 915 | - */ |
|
| 916 | - public function getActionButtons(EE_Transaction $transaction = null) |
|
| 917 | - { |
|
| 918 | - $content = ''; |
|
| 919 | - $actions = array(); |
|
| 920 | - if (! $transaction instanceof EE_Transaction) { |
|
| 921 | - return $content; |
|
| 922 | - } |
|
| 923 | - /** @var EE_Registration $primary_registration */ |
|
| 924 | - $primary_registration = $transaction->primary_registration(); |
|
| 925 | - $attendee = $primary_registration instanceof EE_Registration |
|
| 926 | - ? $primary_registration->attendee() |
|
| 927 | - : null; |
|
| 928 | - |
|
| 929 | - if ($attendee instanceof EE_Attendee |
|
| 930 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 931 | - 'ee_send_message', |
|
| 932 | - 'espresso_transactions_send_payment_reminder' |
|
| 933 | - ) |
|
| 934 | - ) { |
|
| 935 | - $actions['payment_reminder'] = |
|
| 936 | - EEH_MSG_Template::is_mt_active('payment_reminder') |
|
| 937 | - && $this->_transaction->status_ID() !== EEM_Transaction::complete_status_code |
|
| 938 | - && $this->_transaction->status_ID() !== EEM_Transaction::overpaid_status_code |
|
| 939 | - ? EEH_Template::get_button_or_link( |
|
| 940 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 941 | - array( |
|
| 942 | - 'action' => 'send_payment_reminder', |
|
| 943 | - 'TXN_ID' => $this->_transaction->ID(), |
|
| 944 | - 'redirect_to' => 'view_transaction', |
|
| 945 | - ), |
|
| 946 | - TXN_ADMIN_URL |
|
| 947 | - ), |
|
| 948 | - esc_html__(' Send Payment Reminder', 'event_espresso'), |
|
| 949 | - 'button secondary-button', |
|
| 950 | - 'dashicons dashicons-email-alt' |
|
| 951 | - ) |
|
| 952 | - : ''; |
|
| 953 | - } |
|
| 954 | - |
|
| 955 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 956 | - 'ee_edit_payments', |
|
| 957 | - 'espresso_transactions_recalculate_line_items' |
|
| 958 | - ) |
|
| 959 | - ) { |
|
| 960 | - $actions['recalculate_line_items'] = EEH_Template::get_button_or_link( |
|
| 961 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 962 | - array( |
|
| 963 | - 'action' => 'espresso_recalculate_line_items', |
|
| 964 | - 'TXN_ID' => $this->_transaction->ID(), |
|
| 965 | - 'redirect_to' => 'view_transaction', |
|
| 966 | - ), |
|
| 967 | - TXN_ADMIN_URL |
|
| 968 | - ), |
|
| 969 | - esc_html__(' Recalculate Taxes and Total', 'event_espresso'), |
|
| 970 | - 'button secondary-button', |
|
| 971 | - 'dashicons dashicons-update' |
|
| 972 | - ); |
|
| 973 | - } |
|
| 974 | - |
|
| 975 | - if ($primary_registration instanceof EE_Registration |
|
| 976 | - && EEH_MSG_Template::is_mt_active('receipt') |
|
| 977 | - ) { |
|
| 978 | - $actions['receipt'] = EEH_Template::get_button_or_link( |
|
| 979 | - $primary_registration->receipt_url(), |
|
| 980 | - esc_html__('View Receipt', 'event_espresso'), |
|
| 981 | - 'button secondary-button', |
|
| 982 | - 'dashicons dashicons-media-default' |
|
| 983 | - ); |
|
| 984 | - } |
|
| 985 | - |
|
| 986 | - if ($primary_registration instanceof EE_Registration |
|
| 987 | - && EEH_MSG_Template::is_mt_active('invoice') |
|
| 988 | - ) { |
|
| 989 | - $actions['invoice'] = EEH_Template::get_button_or_link( |
|
| 990 | - $primary_registration->invoice_url(), |
|
| 991 | - esc_html__('View Invoice', 'event_espresso'), |
|
| 992 | - 'button secondary-button', |
|
| 993 | - 'dashicons dashicons-media-spreadsheet' |
|
| 994 | - ); |
|
| 995 | - } |
|
| 996 | - $actions = array_filter( |
|
| 997 | - apply_filters('FHEE__Transactions_Admin_Page__getActionButtons__actions', $actions, $transaction) |
|
| 998 | - ); |
|
| 999 | - if ($actions) { |
|
| 1000 | - $content = '<ul>'; |
|
| 1001 | - $content .= '<li>' . implode('</li><li>', $actions) . '</li>'; |
|
| 1002 | - $content .= '</uL>'; |
|
| 1003 | - } |
|
| 1004 | - return $content; |
|
| 1005 | - } |
|
| 1006 | - |
|
| 1007 | - |
|
| 1008 | - /** |
|
| 1009 | - * txn_details_meta_box |
|
| 1010 | - * generates HTML for the Transaction main meta box |
|
| 1011 | - * |
|
| 1012 | - * @return void |
|
| 1013 | - * @throws DomainException |
|
| 1014 | - * @throws EE_Error |
|
| 1015 | - * @throws InvalidArgumentException |
|
| 1016 | - * @throws InvalidDataTypeException |
|
| 1017 | - * @throws InvalidInterfaceException |
|
| 1018 | - * @throws RuntimeException |
|
| 1019 | - * @throws ReflectionException |
|
| 1020 | - */ |
|
| 1021 | - public function txn_details_meta_box() |
|
| 1022 | - { |
|
| 1023 | - $this->_set_transaction_object(); |
|
| 1024 | - $this->_template_args['TXN_ID'] = $this->_transaction->ID(); |
|
| 1025 | - $this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration |
|
| 1026 | - ? $this->_transaction->primary_registration()->attendee() |
|
| 1027 | - : null; |
|
| 1028 | - $this->_template_args['can_edit_payments'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 1029 | - 'ee_edit_payments', |
|
| 1030 | - 'apply_payment_or_refund_from_registration_details' |
|
| 1031 | - ); |
|
| 1032 | - $this->_template_args['can_delete_payments'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 1033 | - 'ee_delete_payments', |
|
| 1034 | - 'delete_payment_from_registration_details' |
|
| 1035 | - ); |
|
| 1036 | - |
|
| 1037 | - // get line table |
|
| 1038 | - EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 1039 | - $Line_Item_Display = new EE_Line_Item_Display( |
|
| 1040 | - 'admin_table', |
|
| 1041 | - 'EE_Admin_Table_Line_Item_Display_Strategy' |
|
| 1042 | - ); |
|
| 1043 | - $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item( |
|
| 1044 | - $this->_transaction->total_line_item() |
|
| 1045 | - ); |
|
| 1046 | - $this->_template_args['REG_code'] = $this->_transaction->primary_registration()->reg_code(); |
|
| 1047 | - |
|
| 1048 | - // process taxes |
|
| 1049 | - $taxes = $this->_transaction->line_items(array(array('LIN_type' => EEM_Line_Item::type_tax))); |
|
| 1050 | - $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false; |
|
| 1051 | - |
|
| 1052 | - $this->_template_args['grand_total'] = EEH_Template::format_currency( |
|
| 1053 | - $this->_transaction->total(), |
|
| 1054 | - false, |
|
| 1055 | - false |
|
| 1056 | - ); |
|
| 1057 | - $this->_template_args['grand_raw_total'] = $this->_transaction->total(); |
|
| 1058 | - $this->_template_args['TXN_status'] = $this->_transaction->status_ID(); |
|
| 1059 | - |
|
| 1060 | - // process payment details |
|
| 1061 | - $payments = $this->_transaction->payments(); |
|
| 1062 | - if (! empty($payments)) { |
|
| 1063 | - $this->_template_args['payments'] = $payments; |
|
| 1064 | - $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments); |
|
| 1065 | - } else { |
|
| 1066 | - $this->_template_args['payments'] = false; |
|
| 1067 | - $this->_template_args['existing_reg_payments'] = array(); |
|
| 1068 | - } |
|
| 1069 | - |
|
| 1070 | - $this->_template_args['edit_payment_url'] = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL); |
|
| 1071 | - $this->_template_args['delete_payment_url'] = add_query_arg( |
|
| 1072 | - array('action' => 'espresso_delete_payment'), |
|
| 1073 | - TXN_ADMIN_URL |
|
| 1074 | - ); |
|
| 1075 | - |
|
| 1076 | - if (isset($txn_details['invoice_number'])) { |
|
| 1077 | - $this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code']; |
|
| 1078 | - $this->_template_args['txn_details']['invoice_number']['label'] = esc_html__( |
|
| 1079 | - 'Invoice Number', |
|
| 1080 | - 'event_espresso' |
|
| 1081 | - ); |
|
| 1082 | - } |
|
| 1083 | - |
|
| 1084 | - $this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction |
|
| 1085 | - ->primary_registration() |
|
| 1086 | - ->session_ID(); |
|
| 1087 | - $this->_template_args['txn_details']['registration_session']['label'] = esc_html__( |
|
| 1088 | - 'Registration Session', |
|
| 1089 | - 'event_espresso' |
|
| 1090 | - ); |
|
| 1091 | - |
|
| 1092 | - $this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address']) |
|
| 1093 | - ? $this->_session['ip_address'] |
|
| 1094 | - : ''; |
|
| 1095 | - $this->_template_args['txn_details']['ip_address']['label'] = esc_html__( |
|
| 1096 | - 'Transaction placed from IP', |
|
| 1097 | - 'event_espresso' |
|
| 1098 | - ); |
|
| 1099 | - |
|
| 1100 | - $this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent']) |
|
| 1101 | - ? $this->_session['user_agent'] |
|
| 1102 | - : ''; |
|
| 1103 | - $this->_template_args['txn_details']['user_agent']['label'] = esc_html__( |
|
| 1104 | - 'Registrant User Agent', |
|
| 1105 | - 'event_espresso' |
|
| 1106 | - ); |
|
| 1107 | - |
|
| 1108 | - $reg_steps = '<ul>'; |
|
| 1109 | - foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) { |
|
| 1110 | - if ($reg_step_status === true) { |
|
| 1111 | - $reg_steps .= '<li style="color:#70cc50">' |
|
| 1112 | - . sprintf( |
|
| 1113 | - esc_html__('%1$s : Completed', 'event_espresso'), |
|
| 1114 | - ucwords(str_replace('_', ' ', $reg_step)) |
|
| 1115 | - ) |
|
| 1116 | - . '</li>'; |
|
| 1117 | - } elseif (is_numeric($reg_step_status) && $reg_step_status !== false) { |
|
| 1118 | - $reg_steps .= '<li style="color:#2EA2CC">' |
|
| 1119 | - . sprintf( |
|
| 1120 | - esc_html__('%1$s : Initiated %2$s', 'event_espresso'), |
|
| 1121 | - ucwords(str_replace('_', ' ', $reg_step)), |
|
| 1122 | - date( |
|
| 1123 | - get_option('date_format') . ' ' . get_option('time_format'), |
|
| 1124 | - $reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
| 1125 | - ) |
|
| 1126 | - ) |
|
| 1127 | - . '</li>'; |
|
| 1128 | - } else { |
|
| 1129 | - $reg_steps .= '<li style="color:#E76700">' |
|
| 1130 | - . sprintf( |
|
| 1131 | - esc_html__('%1$s : Never Initiated', 'event_espresso'), |
|
| 1132 | - ucwords(str_replace('_', ' ', $reg_step)) |
|
| 1133 | - ) |
|
| 1134 | - . '</li>'; |
|
| 1135 | - } |
|
| 1136 | - } |
|
| 1137 | - $reg_steps .= '</ul>'; |
|
| 1138 | - $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps; |
|
| 1139 | - $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__( |
|
| 1140 | - 'Registration Step Progress', |
|
| 1141 | - 'event_espresso' |
|
| 1142 | - ); |
|
| 1143 | - |
|
| 1144 | - |
|
| 1145 | - $this->_get_registrations_to_apply_payment_to(); |
|
| 1146 | - $this->_get_payment_methods($payments); |
|
| 1147 | - $this->_get_payment_status_array(); |
|
| 1148 | - $this->_get_reg_status_selection(); // sets up the template args for the reg status array for the transaction. |
|
| 1149 | - |
|
| 1150 | - $this->_template_args['transaction_form_url'] = add_query_arg( |
|
| 1151 | - array( |
|
| 1152 | - 'action' => 'edit_transaction', |
|
| 1153 | - 'process' => 'transaction', |
|
| 1154 | - ), |
|
| 1155 | - TXN_ADMIN_URL |
|
| 1156 | - ); |
|
| 1157 | - $this->_template_args['apply_payment_form_url'] = add_query_arg( |
|
| 1158 | - array( |
|
| 1159 | - 'page' => 'espresso_transactions', |
|
| 1160 | - 'action' => 'espresso_apply_payment', |
|
| 1161 | - ), |
|
| 1162 | - WP_AJAX_URL |
|
| 1163 | - ); |
|
| 1164 | - $this->_template_args['delete_payment_form_url'] = add_query_arg( |
|
| 1165 | - array( |
|
| 1166 | - 'page' => 'espresso_transactions', |
|
| 1167 | - 'action' => 'espresso_delete_payment', |
|
| 1168 | - ), |
|
| 1169 | - WP_AJAX_URL |
|
| 1170 | - ); |
|
| 1171 | - |
|
| 1172 | - $this->_template_args['action_buttons'] = $this->getActionButtons($this->_transaction); |
|
| 1173 | - |
|
| 1174 | - // 'espresso_delete_payment_nonce' |
|
| 1175 | - |
|
| 1176 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
| 1177 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 1178 | - } |
|
| 1179 | - |
|
| 1180 | - |
|
| 1181 | - /** |
|
| 1182 | - * _get_registration_payment_IDs |
|
| 1183 | - * generates an array of Payment IDs and their corresponding Registration IDs |
|
| 1184 | - * |
|
| 1185 | - * @access protected |
|
| 1186 | - * @param EE_Payment[] $payments |
|
| 1187 | - * @return array |
|
| 1188 | - * @throws EE_Error |
|
| 1189 | - * @throws InvalidArgumentException |
|
| 1190 | - * @throws InvalidDataTypeException |
|
| 1191 | - * @throws InvalidInterfaceException |
|
| 1192 | - * @throws ReflectionException |
|
| 1193 | - */ |
|
| 1194 | - protected function _get_registration_payment_IDs($payments = array()) |
|
| 1195 | - { |
|
| 1196 | - $existing_reg_payments = array(); |
|
| 1197 | - // get all reg payments for these payments |
|
| 1198 | - $reg_payments = EEM_Registration_Payment::instance()->get_all( |
|
| 1199 | - array( |
|
| 1200 | - array( |
|
| 1201 | - 'PAY_ID' => array( |
|
| 1202 | - 'IN', |
|
| 1203 | - array_keys($payments), |
|
| 1204 | - ), |
|
| 1205 | - ), |
|
| 1206 | - ) |
|
| 1207 | - ); |
|
| 1208 | - if (! empty($reg_payments)) { |
|
| 1209 | - foreach ($payments as $payment) { |
|
| 1210 | - if (! $payment instanceof EE_Payment) { |
|
| 1211 | - continue; |
|
| 1212 | - } elseif (! isset($existing_reg_payments[ $payment->ID() ])) { |
|
| 1213 | - $existing_reg_payments[ $payment->ID() ] = array(); |
|
| 1214 | - } |
|
| 1215 | - foreach ($reg_payments as $reg_payment) { |
|
| 1216 | - if ($reg_payment instanceof EE_Registration_Payment |
|
| 1217 | - && $reg_payment->payment_ID() === $payment->ID() |
|
| 1218 | - ) { |
|
| 1219 | - $existing_reg_payments[ $payment->ID() ][] = $reg_payment->registration_ID(); |
|
| 1220 | - } |
|
| 1221 | - } |
|
| 1222 | - } |
|
| 1223 | - } |
|
| 1224 | - |
|
| 1225 | - return $existing_reg_payments; |
|
| 1226 | - } |
|
| 1227 | - |
|
| 1228 | - |
|
| 1229 | - /** |
|
| 1230 | - * _get_registrations_to_apply_payment_to |
|
| 1231 | - * generates HTML for displaying a series of checkboxes in the admin payment modal window |
|
| 1232 | - * which allows the admin to only apply the payment to the specific registrations |
|
| 1233 | - * |
|
| 1234 | - * @access protected |
|
| 1235 | - * @return void |
|
| 1236 | - * @throws EE_Error |
|
| 1237 | - * @throws InvalidArgumentException |
|
| 1238 | - * @throws InvalidDataTypeException |
|
| 1239 | - * @throws InvalidInterfaceException |
|
| 1240 | - * @throws ReflectionException |
|
| 1241 | - */ |
|
| 1242 | - protected function _get_registrations_to_apply_payment_to() |
|
| 1243 | - { |
|
| 1244 | - // we want any registration with an active status (ie: not deleted or cancelled) |
|
| 1245 | - $query_params = array( |
|
| 1246 | - array( |
|
| 1247 | - 'STS_ID' => array( |
|
| 1248 | - 'IN', |
|
| 1249 | - array( |
|
| 1250 | - EEM_Registration::status_id_approved, |
|
| 1251 | - EEM_Registration::status_id_pending_payment, |
|
| 1252 | - EEM_Registration::status_id_not_approved, |
|
| 1253 | - ), |
|
| 1254 | - ), |
|
| 1255 | - ), |
|
| 1256 | - ); |
|
| 1257 | - $registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div( |
|
| 1258 | - '', |
|
| 1259 | - 'txn-admin-apply-payment-to-registrations-dv', |
|
| 1260 | - '', |
|
| 1261 | - 'clear: both; margin: 1.5em 0 0; display: none;' |
|
| 1262 | - ); |
|
| 1263 | - $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
| 1264 | - $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl'); |
|
| 1265 | - $registrations_to_apply_payment_to .= EEH_HTML::thead( |
|
| 1266 | - EEH_HTML::tr( |
|
| 1267 | - EEH_HTML::th(esc_html__('ID', 'event_espresso')) . |
|
| 1268 | - EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) . |
|
| 1269 | - EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) . |
|
| 1270 | - EEH_HTML::th(esc_html__('Event', 'event_espresso')) . |
|
| 1271 | - EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 1272 | - EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
| 1273 | - EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr') |
|
| 1274 | - ) |
|
| 1275 | - ); |
|
| 1276 | - $registrations_to_apply_payment_to .= EEH_HTML::tbody(); |
|
| 1277 | - // get registrations for TXN |
|
| 1278 | - $registrations = $this->_transaction->registrations($query_params); |
|
| 1279 | - $existing_reg_payments = $this->_template_args['existing_reg_payments']; |
|
| 1280 | - foreach ($registrations as $registration) { |
|
| 1281 | - if ($registration instanceof EE_Registration) { |
|
| 1282 | - $attendee_name = $registration->attendee() instanceof EE_Attendee |
|
| 1283 | - ? $registration->attendee()->full_name() |
|
| 1284 | - : esc_html__('Unknown Attendee', 'event_espresso'); |
|
| 1285 | - $owing = $registration->final_price() - $registration->paid(); |
|
| 1286 | - $taxable = $registration->ticket()->taxable() |
|
| 1287 | - ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>' |
|
| 1288 | - : ''; |
|
| 1289 | - $checked = empty($existing_reg_payments) |
|
| 1290 | - || in_array($registration->ID(), $existing_reg_payments, true) |
|
| 1291 | - ? ' checked="checked"' |
|
| 1292 | - : ''; |
|
| 1293 | - $disabled = $registration->final_price() > 0 ? '' : ' disabled'; |
|
| 1294 | - $registrations_to_apply_payment_to .= EEH_HTML::tr( |
|
| 1295 | - EEH_HTML::td($registration->ID()) . |
|
| 1296 | - EEH_HTML::td($attendee_name) . |
|
| 1297 | - EEH_HTML::td( |
|
| 1298 | - $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable |
|
| 1299 | - ) . |
|
| 1300 | - EEH_HTML::td($registration->event_name()) . |
|
| 1301 | - EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 1302 | - EEH_HTML::td( |
|
| 1303 | - EEH_Template::format_currency($owing), |
|
| 1304 | - '', |
|
| 1305 | - 'txn-admin-payment-owing-td jst-cntr' |
|
| 1306 | - ) . |
|
| 1307 | - EEH_HTML::td( |
|
| 1308 | - '<input type="checkbox" value="' . $registration->ID() |
|
| 1309 | - . '" name="txn_admin_payment[registrations]"' |
|
| 1310 | - . $checked . $disabled . '>', |
|
| 1311 | - '', |
|
| 1312 | - 'jst-cntr' |
|
| 1313 | - ), |
|
| 1314 | - 'apply-payment-registration-row-' . $registration->ID() |
|
| 1315 | - ); |
|
| 1316 | - } |
|
| 1317 | - } |
|
| 1318 | - $registrations_to_apply_payment_to .= EEH_HTML::tbodyx(); |
|
| 1319 | - $registrations_to_apply_payment_to .= EEH_HTML::tablex(); |
|
| 1320 | - $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1321 | - $registrations_to_apply_payment_to .= EEH_HTML::p( |
|
| 1322 | - esc_html__( |
|
| 1323 | - 'The payment will only be applied to the registrations that have a check mark in their corresponding check box. Checkboxes for free registrations have been disabled.', |
|
| 1324 | - 'event_espresso' |
|
| 1325 | - ), |
|
| 1326 | - '', |
|
| 1327 | - 'clear description' |
|
| 1328 | - ); |
|
| 1329 | - $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1330 | - $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to; |
|
| 1331 | - } |
|
| 1332 | - |
|
| 1333 | - |
|
| 1334 | - /** |
|
| 1335 | - * _get_reg_status_selection |
|
| 1336 | - * |
|
| 1337 | - * @todo this will need to be adjusted either once MER comes along OR we move default reg status to tickets |
|
| 1338 | - * instead of events. |
|
| 1339 | - * @access protected |
|
| 1340 | - * @return void |
|
| 1341 | - * @throws EE_Error |
|
| 1342 | - */ |
|
| 1343 | - protected function _get_reg_status_selection() |
|
| 1344 | - { |
|
| 1345 | - // first get all possible statuses |
|
| 1346 | - $statuses = EEM_Registration::reg_status_array(array(), true); |
|
| 1347 | - // let's add a "don't change" option. |
|
| 1348 | - $status_array['NAN'] = esc_html__('Leave the Same', 'event_espresso'); |
|
| 1349 | - $status_array = array_merge($status_array, $statuses); |
|
| 1350 | - $this->_template_args['status_change_select'] = EEH_Form_Fields::select_input( |
|
| 1351 | - 'txn_reg_status_change[reg_status]', |
|
| 1352 | - $status_array, |
|
| 1353 | - 'NAN', |
|
| 1354 | - 'id="txn-admin-payment-reg-status-inp"', |
|
| 1355 | - 'txn-reg-status-change-reg-status' |
|
| 1356 | - ); |
|
| 1357 | - $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input( |
|
| 1358 | - 'delete_txn_reg_status_change[reg_status]', |
|
| 1359 | - $status_array, |
|
| 1360 | - 'NAN', |
|
| 1361 | - 'delete-txn-admin-payment-reg-status-inp', |
|
| 1362 | - 'delete-txn-reg-status-change-reg-status' |
|
| 1363 | - ); |
|
| 1364 | - } |
|
| 1365 | - |
|
| 1366 | - |
|
| 1367 | - /** |
|
| 1368 | - * _get_payment_methods |
|
| 1369 | - * Gets all the payment methods available generally, or the ones that are already |
|
| 1370 | - * selected on these payments (in case their payment methods are no longer active). |
|
| 1371 | - * Has the side-effect of updating the template args' payment_methods item |
|
| 1372 | - * |
|
| 1373 | - * @access private |
|
| 1374 | - * @param EE_Payment[] to show on this page |
|
| 1375 | - * @return void |
|
| 1376 | - * @throws EE_Error |
|
| 1377 | - * @throws InvalidArgumentException |
|
| 1378 | - * @throws InvalidDataTypeException |
|
| 1379 | - * @throws InvalidInterfaceException |
|
| 1380 | - * @throws ReflectionException |
|
| 1381 | - */ |
|
| 1382 | - private function _get_payment_methods($payments = array()) |
|
| 1383 | - { |
|
| 1384 | - $payment_methods_of_payments = array(); |
|
| 1385 | - foreach ($payments as $payment) { |
|
| 1386 | - if ($payment instanceof EE_Payment) { |
|
| 1387 | - $payment_methods_of_payments[] = $payment->ID(); |
|
| 1388 | - } |
|
| 1389 | - } |
|
| 1390 | - if ($payment_methods_of_payments) { |
|
| 1391 | - $query_args = array( |
|
| 1392 | - array( |
|
| 1393 | - 'OR*payment_method_for_payment' => array( |
|
| 1394 | - 'PMD_ID' => array('IN', $payment_methods_of_payments), |
|
| 1395 | - 'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'), |
|
| 1396 | - ), |
|
| 1397 | - ), |
|
| 1398 | - ); |
|
| 1399 | - } else { |
|
| 1400 | - $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'))); |
|
| 1401 | - } |
|
| 1402 | - $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args); |
|
| 1403 | - } |
|
| 1404 | - |
|
| 1405 | - |
|
| 1406 | - /** |
|
| 1407 | - * txn_attendees_meta_box |
|
| 1408 | - * generates HTML for the Attendees Transaction main meta box |
|
| 1409 | - * |
|
| 1410 | - * @access public |
|
| 1411 | - * @param WP_Post $post |
|
| 1412 | - * @param array $metabox |
|
| 1413 | - * @return void |
|
| 1414 | - * @throws DomainException |
|
| 1415 | - * @throws EE_Error |
|
| 1416 | - * @throws InvalidArgumentException |
|
| 1417 | - * @throws InvalidDataTypeException |
|
| 1418 | - * @throws InvalidInterfaceException |
|
| 1419 | - * @throws ReflectionException |
|
| 1420 | - */ |
|
| 1421 | - public function txn_attendees_meta_box($post, $metabox = array('args' => array())) |
|
| 1422 | - { |
|
| 1423 | - |
|
| 1424 | - /** @noinspection NonSecureExtractUsageInspection */ |
|
| 1425 | - extract($metabox['args']); |
|
| 1426 | - $this->_template_args['post'] = $post; |
|
| 1427 | - $this->_template_args['event_attendees'] = array(); |
|
| 1428 | - // process items in cart |
|
| 1429 | - $line_items = $this->_transaction->get_many_related( |
|
| 1430 | - 'Line_Item', |
|
| 1431 | - array(array('LIN_type' => 'line-item')) |
|
| 1432 | - ); |
|
| 1433 | - if (! empty($line_items)) { |
|
| 1434 | - foreach ($line_items as $item) { |
|
| 1435 | - if ($item instanceof EE_Line_Item) { |
|
| 1436 | - switch ($item->OBJ_type()) { |
|
| 1437 | - case 'Event': |
|
| 1438 | - break; |
|
| 1439 | - case 'Ticket': |
|
| 1440 | - $ticket = $item->ticket(); |
|
| 1441 | - // right now we're only handling tickets here. |
|
| 1442 | - // Cause its expected that only tickets will have attendees right? |
|
| 1443 | - if (! $ticket instanceof EE_Ticket) { |
|
| 1444 | - break; |
|
| 1445 | - } |
|
| 1446 | - try { |
|
| 1447 | - $event_name = $ticket->get_event_name(); |
|
| 1448 | - } catch (Exception $e) { |
|
| 1449 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1450 | - $event_name = esc_html__('Unknown Event', 'event_espresso'); |
|
| 1451 | - } |
|
| 1452 | - $event_name .= ' - ' . $item->name(); |
|
| 1453 | - $ticket_price = EEH_Template::format_currency($item->unit_price()); |
|
| 1454 | - // now get all of the registrations for this transaction that use this ticket |
|
| 1455 | - $registrations = $ticket->registrations( |
|
| 1456 | - array(array('TXN_ID' => $this->_transaction->ID())) |
|
| 1457 | - ); |
|
| 1458 | - foreach ($registrations as $registration) { |
|
| 1459 | - if (! $registration instanceof EE_Registration) { |
|
| 1460 | - break; |
|
| 1461 | - } |
|
| 1462 | - $this->_template_args['event_attendees'][ $registration->ID() ]['STS_ID'] |
|
| 1463 | - = $registration->status_ID(); |
|
| 1464 | - $this->_template_args['event_attendees'][ $registration->ID() ]['att_num'] |
|
| 1465 | - = $registration->count(); |
|
| 1466 | - $this->_template_args['event_attendees'][ $registration->ID() ]['event_ticket_name'] |
|
| 1467 | - = $event_name; |
|
| 1468 | - $this->_template_args['event_attendees'][ $registration->ID() ]['ticket_price'] |
|
| 1469 | - = $ticket_price; |
|
| 1470 | - // attendee info |
|
| 1471 | - $attendee = $registration->get_first_related('Attendee'); |
|
| 1472 | - if ($attendee instanceof EE_Attendee) { |
|
| 1473 | - $this->_template_args['event_attendees'][ $registration->ID() ]['att_id'] |
|
| 1474 | - = $attendee->ID(); |
|
| 1475 | - $this->_template_args['event_attendees'][ $registration->ID() ]['attendee'] |
|
| 1476 | - = $attendee->full_name(); |
|
| 1477 | - $this->_template_args['event_attendees'][ $registration->ID() ]['email'] |
|
| 1478 | - = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name |
|
| 1479 | - . esc_html__( |
|
| 1480 | - ' Event', |
|
| 1481 | - 'event_espresso' |
|
| 1482 | - ) |
|
| 1483 | - . '">' . $attendee->email() . '</a>'; |
|
| 1484 | - $this->_template_args['event_attendees'][ $registration->ID() ]['address'] |
|
| 1485 | - = EEH_Address::format($attendee, 'inline', false, false); |
|
| 1486 | - } else { |
|
| 1487 | - $this->_template_args['event_attendees'][ $registration->ID() ]['att_id'] = ''; |
|
| 1488 | - $this->_template_args['event_attendees'][ $registration->ID() ]['attendee'] = ''; |
|
| 1489 | - $this->_template_args['event_attendees'][ $registration->ID() ]['email'] = ''; |
|
| 1490 | - $this->_template_args['event_attendees'][ $registration->ID() ]['address'] = ''; |
|
| 1491 | - } |
|
| 1492 | - } |
|
| 1493 | - break; |
|
| 1494 | - } |
|
| 1495 | - } |
|
| 1496 | - } |
|
| 1497 | - |
|
| 1498 | - $this->_template_args['transaction_form_url'] = add_query_arg( |
|
| 1499 | - array( |
|
| 1500 | - 'action' => 'edit_transaction', |
|
| 1501 | - 'process' => 'attendees', |
|
| 1502 | - ), |
|
| 1503 | - TXN_ADMIN_URL |
|
| 1504 | - ); |
|
| 1505 | - echo EEH_Template::display_template( |
|
| 1506 | - TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php', |
|
| 1507 | - $this->_template_args, |
|
| 1508 | - true |
|
| 1509 | - ); |
|
| 1510 | - } else { |
|
| 1511 | - echo sprintf( |
|
| 1512 | - esc_html__( |
|
| 1513 | - '%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s', |
|
| 1514 | - 'event_espresso' |
|
| 1515 | - ), |
|
| 1516 | - '<p class="important-notice">', |
|
| 1517 | - '</p>' |
|
| 1518 | - ); |
|
| 1519 | - } |
|
| 1520 | - } |
|
| 1521 | - |
|
| 1522 | - |
|
| 1523 | - /** |
|
| 1524 | - * txn_registrant_side_meta_box |
|
| 1525 | - * generates HTML for the Edit Transaction side meta box |
|
| 1526 | - * |
|
| 1527 | - * @access public |
|
| 1528 | - * @return void |
|
| 1529 | - * @throws DomainException |
|
| 1530 | - * @throws EE_Error |
|
| 1531 | - * @throws InvalidArgumentException |
|
| 1532 | - * @throws InvalidDataTypeException |
|
| 1533 | - * @throws InvalidInterfaceException |
|
| 1534 | - * @throws ReflectionException |
|
| 1535 | - */ |
|
| 1536 | - public function txn_registrant_side_meta_box() |
|
| 1537 | - { |
|
| 1538 | - $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration |
|
| 1539 | - ? $this->_transaction->primary_registration()->get_first_related('Attendee') |
|
| 1540 | - : null; |
|
| 1541 | - if (! $primary_att instanceof EE_Attendee) { |
|
| 1542 | - $this->_template_args['no_attendee_message'] = esc_html__( |
|
| 1543 | - 'There is no attached contact for this transaction. The transaction either failed due to an error or was abandoned.', |
|
| 1544 | - 'event_espresso' |
|
| 1545 | - ); |
|
| 1546 | - $primary_att = EEM_Attendee::instance()->create_default_object(); |
|
| 1547 | - } |
|
| 1548 | - $this->_template_args['ATT_ID'] = $primary_att->ID(); |
|
| 1549 | - $this->_template_args['prime_reg_fname'] = $primary_att->fname(); |
|
| 1550 | - $this->_template_args['prime_reg_lname'] = $primary_att->lname(); |
|
| 1551 | - $this->_template_args['prime_reg_email'] = $primary_att->email(); |
|
| 1552 | - $this->_template_args['prime_reg_phone'] = $primary_att->phone(); |
|
| 1553 | - $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1554 | - array( |
|
| 1555 | - 'action' => 'edit_attendee', |
|
| 1556 | - 'post' => $primary_att->ID(), |
|
| 1557 | - ), |
|
| 1558 | - REG_ADMIN_URL |
|
| 1559 | - ); |
|
| 1560 | - // get formatted address for registrant |
|
| 1561 | - $this->_template_args['formatted_address'] = EEH_Address::format($primary_att); |
|
| 1562 | - echo EEH_Template::display_template( |
|
| 1563 | - TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php', |
|
| 1564 | - $this->_template_args, |
|
| 1565 | - true |
|
| 1566 | - ); |
|
| 1567 | - } |
|
| 1568 | - |
|
| 1569 | - |
|
| 1570 | - /** |
|
| 1571 | - * txn_billing_info_side_meta_box |
|
| 1572 | - * generates HTML for the Edit Transaction side meta box |
|
| 1573 | - * |
|
| 1574 | - * @access public |
|
| 1575 | - * @return void |
|
| 1576 | - * @throws DomainException |
|
| 1577 | - * @throws EE_Error |
|
| 1578 | - */ |
|
| 1579 | - public function txn_billing_info_side_meta_box() |
|
| 1580 | - { |
|
| 1581 | - |
|
| 1582 | - $this->_template_args['billing_form'] = $this->_transaction->billing_info(); |
|
| 1583 | - $this->_template_args['billing_form_url'] = add_query_arg( |
|
| 1584 | - array('action' => 'edit_transaction', 'process' => 'billing'), |
|
| 1585 | - TXN_ADMIN_URL |
|
| 1586 | - ); |
|
| 1587 | - |
|
| 1588 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
| 1589 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 1590 | - } |
|
| 1591 | - |
|
| 1592 | - |
|
| 1593 | - /** |
|
| 1594 | - * apply_payments_or_refunds |
|
| 1595 | - * registers a payment or refund made towards a transaction |
|
| 1596 | - * |
|
| 1597 | - * @access public |
|
| 1598 | - * @return void |
|
| 1599 | - * @throws EE_Error |
|
| 1600 | - * @throws InvalidArgumentException |
|
| 1601 | - * @throws ReflectionException |
|
| 1602 | - * @throws RuntimeException |
|
| 1603 | - * @throws InvalidDataTypeException |
|
| 1604 | - * @throws InvalidInterfaceException |
|
| 1605 | - */ |
|
| 1606 | - public function apply_payments_or_refunds() |
|
| 1607 | - { |
|
| 1608 | - $json_response_data = array('return_data' => false); |
|
| 1609 | - $valid_data = $this->_validate_payment_request_data(); |
|
| 1610 | - $has_access = EE_Registry::instance()->CAP->current_user_can( |
|
| 1611 | - 'ee_edit_payments', |
|
| 1612 | - 'apply_payment_or_refund_from_registration_details' |
|
| 1613 | - ); |
|
| 1614 | - if (! empty($valid_data) && $has_access) { |
|
| 1615 | - $PAY_ID = $valid_data['PAY_ID']; |
|
| 1616 | - // save the new payment |
|
| 1617 | - $payment = $this->_create_payment_from_request_data($valid_data); |
|
| 1618 | - // get the TXN for this payment |
|
| 1619 | - $transaction = $payment->transaction(); |
|
| 1620 | - // verify transaction |
|
| 1621 | - if ($transaction instanceof EE_Transaction) { |
|
| 1622 | - // calculate_total_payments_and_update_status |
|
| 1623 | - $this->_process_transaction_payments($transaction); |
|
| 1624 | - $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment); |
|
| 1625 | - $this->_remove_existing_registration_payments($payment, $PAY_ID); |
|
| 1626 | - // apply payment to registrations (if applicable) |
|
| 1627 | - if (! empty($REG_IDs)) { |
|
| 1628 | - $this->_update_registration_payments($transaction, $payment, $REG_IDs); |
|
| 1629 | - $this->_maybe_send_notifications(); |
|
| 1630 | - // now process status changes for the same registrations |
|
| 1631 | - $this->_process_registration_status_change($transaction, $REG_IDs); |
|
| 1632 | - } |
|
| 1633 | - $this->_maybe_send_notifications($payment); |
|
| 1634 | - // prepare to render page |
|
| 1635 | - $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs); |
|
| 1636 | - do_action( |
|
| 1637 | - 'AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording', |
|
| 1638 | - $transaction, |
|
| 1639 | - $payment |
|
| 1640 | - ); |
|
| 1641 | - } else { |
|
| 1642 | - EE_Error::add_error( |
|
| 1643 | - esc_html__( |
|
| 1644 | - 'A valid Transaction for this payment could not be retrieved.', |
|
| 1645 | - 'event_espresso' |
|
| 1646 | - ), |
|
| 1647 | - __FILE__, |
|
| 1648 | - __FUNCTION__, |
|
| 1649 | - __LINE__ |
|
| 1650 | - ); |
|
| 1651 | - } |
|
| 1652 | - } elseif ($has_access) { |
|
| 1653 | - EE_Error::add_error( |
|
| 1654 | - esc_html__( |
|
| 1655 | - 'The payment form data could not be processed. Please try again.', |
|
| 1656 | - 'event_espresso' |
|
| 1657 | - ), |
|
| 1658 | - __FILE__, |
|
| 1659 | - __FUNCTION__, |
|
| 1660 | - __LINE__ |
|
| 1661 | - ); |
|
| 1662 | - } else { |
|
| 1663 | - EE_Error::add_error( |
|
| 1664 | - esc_html__( |
|
| 1665 | - 'You do not have access to apply payments or refunds to a registration.', |
|
| 1666 | - 'event_espresso' |
|
| 1667 | - ), |
|
| 1668 | - __FILE__, |
|
| 1669 | - __FUNCTION__, |
|
| 1670 | - __LINE__ |
|
| 1671 | - ); |
|
| 1672 | - } |
|
| 1673 | - $notices = EE_Error::get_notices( |
|
| 1674 | - false, |
|
| 1675 | - false, |
|
| 1676 | - false |
|
| 1677 | - ); |
|
| 1678 | - $this->_template_args = array( |
|
| 1679 | - 'data' => $json_response_data, |
|
| 1680 | - 'error' => $notices['errors'], |
|
| 1681 | - 'success' => $notices['success'], |
|
| 1682 | - ); |
|
| 1683 | - $this->_return_json(); |
|
| 1684 | - } |
|
| 1685 | - |
|
| 1686 | - |
|
| 1687 | - /** |
|
| 1688 | - * _validate_payment_request_data |
|
| 1689 | - * |
|
| 1690 | - * @return array |
|
| 1691 | - * @throws EE_Error |
|
| 1692 | - * @throws InvalidArgumentException |
|
| 1693 | - * @throws InvalidDataTypeException |
|
| 1694 | - * @throws InvalidInterfaceException |
|
| 1695 | - */ |
|
| 1696 | - protected function _validate_payment_request_data() |
|
| 1697 | - { |
|
| 1698 | - if (! isset($this->_req_data['txn_admin_payment'])) { |
|
| 1699 | - return array(); |
|
| 1700 | - } |
|
| 1701 | - $payment_form = $this->_generate_payment_form_section(); |
|
| 1702 | - try { |
|
| 1703 | - if ($payment_form->was_submitted()) { |
|
| 1704 | - $payment_form->receive_form_submission(); |
|
| 1705 | - if (! $payment_form->is_valid()) { |
|
| 1706 | - $submission_error_messages = array(); |
|
| 1707 | - foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) { |
|
| 1708 | - if ($validation_error instanceof EE_Validation_Error) { |
|
| 1709 | - $submission_error_messages[] = sprintf( |
|
| 1710 | - _x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'), |
|
| 1711 | - $validation_error->get_form_section()->html_label_text(), |
|
| 1712 | - $validation_error->getMessage() |
|
| 1713 | - ); |
|
| 1714 | - } |
|
| 1715 | - } |
|
| 1716 | - EE_Error::add_error( |
|
| 1717 | - implode('<br />', $submission_error_messages), |
|
| 1718 | - __FILE__, |
|
| 1719 | - __FUNCTION__, |
|
| 1720 | - __LINE__ |
|
| 1721 | - ); |
|
| 1722 | - return array(); |
|
| 1723 | - } |
|
| 1724 | - } |
|
| 1725 | - } catch (EE_Error $e) { |
|
| 1726 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1727 | - return array(); |
|
| 1728 | - } |
|
| 1729 | - |
|
| 1730 | - return $payment_form->valid_data(); |
|
| 1731 | - } |
|
| 1732 | - |
|
| 1733 | - |
|
| 1734 | - /** |
|
| 1735 | - * _generate_payment_form_section |
|
| 1736 | - * |
|
| 1737 | - * @return EE_Form_Section_Proper |
|
| 1738 | - * @throws EE_Error |
|
| 1739 | - */ |
|
| 1740 | - protected function _generate_payment_form_section() |
|
| 1741 | - { |
|
| 1742 | - return new EE_Form_Section_Proper( |
|
| 1743 | - array( |
|
| 1744 | - 'name' => 'txn_admin_payment', |
|
| 1745 | - 'subsections' => array( |
|
| 1746 | - 'PAY_ID' => new EE_Text_Input( |
|
| 1747 | - array( |
|
| 1748 | - 'default' => 0, |
|
| 1749 | - 'required' => false, |
|
| 1750 | - 'html_label_text' => esc_html__('Payment ID', 'event_espresso'), |
|
| 1751 | - 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1752 | - ) |
|
| 1753 | - ), |
|
| 1754 | - 'TXN_ID' => new EE_Text_Input( |
|
| 1755 | - array( |
|
| 1756 | - 'default' => 0, |
|
| 1757 | - 'required' => true, |
|
| 1758 | - 'html_label_text' => esc_html__('Transaction ID', 'event_espresso'), |
|
| 1759 | - 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1760 | - ) |
|
| 1761 | - ), |
|
| 1762 | - 'type' => new EE_Text_Input( |
|
| 1763 | - array( |
|
| 1764 | - 'default' => 1, |
|
| 1765 | - 'required' => true, |
|
| 1766 | - 'html_label_text' => esc_html__('Payment or Refund', 'event_espresso'), |
|
| 1767 | - 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1768 | - ) |
|
| 1769 | - ), |
|
| 1770 | - 'amount' => new EE_Text_Input( |
|
| 1771 | - array( |
|
| 1772 | - 'default' => 0, |
|
| 1773 | - 'required' => true, |
|
| 1774 | - 'html_label_text' => esc_html__('Payment amount', 'event_espresso'), |
|
| 1775 | - 'validation_strategies' => array(new EE_Float_Normalization()), |
|
| 1776 | - ) |
|
| 1777 | - ), |
|
| 1778 | - 'status' => new EE_Text_Input( |
|
| 1779 | - array( |
|
| 1780 | - 'default' => EEM_Payment::status_id_approved, |
|
| 1781 | - 'required' => true, |
|
| 1782 | - 'html_label_text' => esc_html__('Payment status', 'event_espresso'), |
|
| 1783 | - ) |
|
| 1784 | - ), |
|
| 1785 | - 'PMD_ID' => new EE_Text_Input( |
|
| 1786 | - array( |
|
| 1787 | - 'default' => 2, |
|
| 1788 | - 'required' => true, |
|
| 1789 | - 'html_label_text' => esc_html__('Payment Method', 'event_espresso'), |
|
| 1790 | - 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1791 | - ) |
|
| 1792 | - ), |
|
| 1793 | - 'date' => new EE_Text_Input( |
|
| 1794 | - array( |
|
| 1795 | - 'default' => time(), |
|
| 1796 | - 'required' => true, |
|
| 1797 | - 'html_label_text' => esc_html__('Payment date', 'event_espresso'), |
|
| 1798 | - ) |
|
| 1799 | - ), |
|
| 1800 | - 'txn_id_chq_nmbr' => new EE_Text_Input( |
|
| 1801 | - array( |
|
| 1802 | - 'default' => '', |
|
| 1803 | - 'required' => false, |
|
| 1804 | - 'html_label_text' => esc_html__('Transaction or Cheque Number', 'event_espresso'), |
|
| 1805 | - 'validation_strategies' => array( |
|
| 1806 | - new EE_Max_Length_Validation_Strategy( |
|
| 1807 | - esc_html__('Input too long', 'event_espresso'), |
|
| 1808 | - 100 |
|
| 1809 | - ), |
|
| 1810 | - ), |
|
| 1811 | - ) |
|
| 1812 | - ), |
|
| 1813 | - 'po_number' => new EE_Text_Input( |
|
| 1814 | - array( |
|
| 1815 | - 'default' => '', |
|
| 1816 | - 'required' => false, |
|
| 1817 | - 'html_label_text' => esc_html__('Purchase Order Number', 'event_espresso'), |
|
| 1818 | - 'validation_strategies' => array( |
|
| 1819 | - new EE_Max_Length_Validation_Strategy( |
|
| 1820 | - esc_html__('Input too long', 'event_espresso'), |
|
| 1821 | - 100 |
|
| 1822 | - ), |
|
| 1823 | - ), |
|
| 1824 | - ) |
|
| 1825 | - ), |
|
| 1826 | - 'accounting' => new EE_Text_Input( |
|
| 1827 | - array( |
|
| 1828 | - 'default' => '', |
|
| 1829 | - 'required' => false, |
|
| 1830 | - 'html_label_text' => esc_html__('Extra Field for Accounting', 'event_espresso'), |
|
| 1831 | - 'validation_strategies' => array( |
|
| 1832 | - new EE_Max_Length_Validation_Strategy( |
|
| 1833 | - esc_html__('Input too long', 'event_espresso'), |
|
| 1834 | - 100 |
|
| 1835 | - ), |
|
| 1836 | - ), |
|
| 1837 | - ) |
|
| 1838 | - ), |
|
| 1839 | - ), |
|
| 1840 | - ) |
|
| 1841 | - ); |
|
| 1842 | - } |
|
| 1843 | - |
|
| 1844 | - |
|
| 1845 | - /** |
|
| 1846 | - * _create_payment_from_request_data |
|
| 1847 | - * |
|
| 1848 | - * @param array $valid_data |
|
| 1849 | - * @return EE_Payment |
|
| 1850 | - * @throws EE_Error |
|
| 1851 | - * @throws InvalidArgumentException |
|
| 1852 | - * @throws InvalidDataTypeException |
|
| 1853 | - * @throws InvalidInterfaceException |
|
| 1854 | - * @throws ReflectionException |
|
| 1855 | - */ |
|
| 1856 | - protected function _create_payment_from_request_data($valid_data) |
|
| 1857 | - { |
|
| 1858 | - $PAY_ID = $valid_data['PAY_ID']; |
|
| 1859 | - // get payment amount |
|
| 1860 | - $amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0; |
|
| 1861 | - // payments have a type value of 1 and refunds have a type value of -1 |
|
| 1862 | - // so multiplying amount by type will give a positive value for payments, and negative values for refunds |
|
| 1863 | - $amount = $valid_data['type'] < 0 ? $amount * -1 : $amount; |
|
| 1864 | - // for some reason the date string coming in has extra spaces between the date and time. This fixes that. |
|
| 1865 | - $date = $valid_data['date'] |
|
| 1866 | - ? preg_replace('/\s+/', ' ', $valid_data['date']) |
|
| 1867 | - : date('Y-m-d g:i a', current_time('timestamp')); |
|
| 1868 | - $payment = EE_Payment::new_instance( |
|
| 1869 | - array( |
|
| 1870 | - 'TXN_ID' => $valid_data['TXN_ID'], |
|
| 1871 | - 'STS_ID' => $valid_data['status'], |
|
| 1872 | - 'PAY_timestamp' => $date, |
|
| 1873 | - 'PAY_source' => EEM_Payment_Method::scope_admin, |
|
| 1874 | - 'PMD_ID' => $valid_data['PMD_ID'], |
|
| 1875 | - 'PAY_amount' => $amount, |
|
| 1876 | - 'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'], |
|
| 1877 | - 'PAY_po_number' => $valid_data['po_number'], |
|
| 1878 | - 'PAY_extra_accntng' => $valid_data['accounting'], |
|
| 1879 | - 'PAY_details' => $valid_data, |
|
| 1880 | - 'PAY_ID' => $PAY_ID, |
|
| 1881 | - ), |
|
| 1882 | - '', |
|
| 1883 | - array('Y-m-d', 'g:i a') |
|
| 1884 | - ); |
|
| 1885 | - |
|
| 1886 | - if (! $payment->save()) { |
|
| 1887 | - EE_Error::add_error( |
|
| 1888 | - sprintf( |
|
| 1889 | - esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'), |
|
| 1890 | - $payment->ID() |
|
| 1891 | - ), |
|
| 1892 | - __FILE__, |
|
| 1893 | - __FUNCTION__, |
|
| 1894 | - __LINE__ |
|
| 1895 | - ); |
|
| 1896 | - } |
|
| 1897 | - |
|
| 1898 | - return $payment; |
|
| 1899 | - } |
|
| 1900 | - |
|
| 1901 | - |
|
| 1902 | - /** |
|
| 1903 | - * _process_transaction_payments |
|
| 1904 | - * |
|
| 1905 | - * @param \EE_Transaction $transaction |
|
| 1906 | - * @return void |
|
| 1907 | - * @throws EE_Error |
|
| 1908 | - * @throws InvalidArgumentException |
|
| 1909 | - * @throws ReflectionException |
|
| 1910 | - * @throws InvalidDataTypeException |
|
| 1911 | - * @throws InvalidInterfaceException |
|
| 1912 | - */ |
|
| 1913 | - protected function _process_transaction_payments(EE_Transaction $transaction) |
|
| 1914 | - { |
|
| 1915 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 1916 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 1917 | - // update the transaction with this payment |
|
| 1918 | - if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) { |
|
| 1919 | - EE_Error::add_success( |
|
| 1920 | - esc_html__( |
|
| 1921 | - 'The payment has been processed successfully.', |
|
| 1922 | - 'event_espresso' |
|
| 1923 | - ), |
|
| 1924 | - __FILE__, |
|
| 1925 | - __FUNCTION__, |
|
| 1926 | - __LINE__ |
|
| 1927 | - ); |
|
| 1928 | - } else { |
|
| 1929 | - EE_Error::add_error( |
|
| 1930 | - esc_html__( |
|
| 1931 | - 'The payment was processed successfully but the amount paid for the transaction was not updated.', |
|
| 1932 | - 'event_espresso' |
|
| 1933 | - ), |
|
| 1934 | - __FILE__, |
|
| 1935 | - __FUNCTION__, |
|
| 1936 | - __LINE__ |
|
| 1937 | - ); |
|
| 1938 | - } |
|
| 1939 | - } |
|
| 1940 | - |
|
| 1941 | - |
|
| 1942 | - /** |
|
| 1943 | - * _get_REG_IDs_to_apply_payment_to |
|
| 1944 | - * returns a list of registration IDs that the payment will apply to |
|
| 1945 | - * |
|
| 1946 | - * @param \EE_Payment $payment |
|
| 1947 | - * @return array |
|
| 1948 | - * @throws EE_Error |
|
| 1949 | - * @throws InvalidArgumentException |
|
| 1950 | - * @throws InvalidDataTypeException |
|
| 1951 | - * @throws InvalidInterfaceException |
|
| 1952 | - * @throws ReflectionException |
|
| 1953 | - */ |
|
| 1954 | - protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment) |
|
| 1955 | - { |
|
| 1956 | - $REG_IDs = array(); |
|
| 1957 | - // grab array of IDs for specific registrations to apply changes to |
|
| 1958 | - if (isset($this->_req_data['txn_admin_payment']['registrations'])) { |
|
| 1959 | - $REG_IDs = (array) $this->_req_data['txn_admin_payment']['registrations']; |
|
| 1960 | - } |
|
| 1961 | - // nothing specified ? then get all reg IDs |
|
| 1962 | - if (empty($REG_IDs)) { |
|
| 1963 | - $registrations = $payment->transaction()->registrations(); |
|
| 1964 | - $REG_IDs = ! empty($registrations) |
|
| 1965 | - ? array_keys($registrations) |
|
| 1966 | - : $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 1967 | - } |
|
| 1968 | - |
|
| 1969 | - // ensure that REG_IDs are integers and NOT strings |
|
| 1970 | - return array_map('intval', $REG_IDs); |
|
| 1971 | - } |
|
| 1972 | - |
|
| 1973 | - |
|
| 1974 | - /** |
|
| 1975 | - * @return array |
|
| 1976 | - */ |
|
| 1977 | - public function existing_reg_payment_REG_IDs() |
|
| 1978 | - { |
|
| 1979 | - return $this->_existing_reg_payment_REG_IDs; |
|
| 1980 | - } |
|
| 1981 | - |
|
| 1982 | - |
|
| 1983 | - /** |
|
| 1984 | - * @param array $existing_reg_payment_REG_IDs |
|
| 1985 | - */ |
|
| 1986 | - public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null) |
|
| 1987 | - { |
|
| 1988 | - $this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs; |
|
| 1989 | - } |
|
| 1990 | - |
|
| 1991 | - |
|
| 1992 | - /** |
|
| 1993 | - * _get_existing_reg_payment_REG_IDs |
|
| 1994 | - * returns a list of registration IDs that the payment is currently related to |
|
| 1995 | - * as recorded in the database |
|
| 1996 | - * |
|
| 1997 | - * @param \EE_Payment $payment |
|
| 1998 | - * @return array |
|
| 1999 | - * @throws EE_Error |
|
| 2000 | - * @throws InvalidArgumentException |
|
| 2001 | - * @throws InvalidDataTypeException |
|
| 2002 | - * @throws InvalidInterfaceException |
|
| 2003 | - * @throws ReflectionException |
|
| 2004 | - */ |
|
| 2005 | - protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment) |
|
| 2006 | - { |
|
| 2007 | - if ($this->existing_reg_payment_REG_IDs() === null) { |
|
| 2008 | - // let's get any existing reg payment records for this payment |
|
| 2009 | - $existing_reg_payment_REG_IDs = $payment->get_many_related('Registration'); |
|
| 2010 | - // but we only want the REG IDs, so grab the array keys |
|
| 2011 | - $existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs) |
|
| 2012 | - ? array_keys($existing_reg_payment_REG_IDs) |
|
| 2013 | - : array(); |
|
| 2014 | - $this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs); |
|
| 2015 | - } |
|
| 2016 | - |
|
| 2017 | - return $this->existing_reg_payment_REG_IDs(); |
|
| 2018 | - } |
|
| 2019 | - |
|
| 2020 | - |
|
| 2021 | - /** |
|
| 2022 | - * _remove_existing_registration_payments |
|
| 2023 | - * this calculates the difference between existing relations |
|
| 2024 | - * to the supplied payment and the new list registration IDs, |
|
| 2025 | - * removes any related registrations that no longer apply, |
|
| 2026 | - * and then updates the registration paid fields |
|
| 2027 | - * |
|
| 2028 | - * @param \EE_Payment $payment |
|
| 2029 | - * @param int $PAY_ID |
|
| 2030 | - * @return bool; |
|
| 2031 | - * @throws EE_Error |
|
| 2032 | - * @throws InvalidArgumentException |
|
| 2033 | - * @throws ReflectionException |
|
| 2034 | - * @throws InvalidDataTypeException |
|
| 2035 | - * @throws InvalidInterfaceException |
|
| 2036 | - */ |
|
| 2037 | - protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0) |
|
| 2038 | - { |
|
| 2039 | - // newly created payments will have nothing recorded for $PAY_ID |
|
| 2040 | - if (absint($PAY_ID) === 0) { |
|
| 2041 | - return false; |
|
| 2042 | - } |
|
| 2043 | - $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 2044 | - if (empty($existing_reg_payment_REG_IDs)) { |
|
| 2045 | - return false; |
|
| 2046 | - } |
|
| 2047 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 2048 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 2049 | - |
|
| 2050 | - return $transaction_payments->delete_registration_payments_and_update_registrations( |
|
| 2051 | - $payment, |
|
| 2052 | - array( |
|
| 2053 | - array( |
|
| 2054 | - 'PAY_ID' => $payment->ID(), |
|
| 2055 | - 'REG_ID' => array('IN', $existing_reg_payment_REG_IDs), |
|
| 2056 | - ), |
|
| 2057 | - ) |
|
| 2058 | - ); |
|
| 2059 | - } |
|
| 2060 | - |
|
| 2061 | - |
|
| 2062 | - /** |
|
| 2063 | - * _update_registration_payments |
|
| 2064 | - * this applies the payments to the selected registrations |
|
| 2065 | - * but only if they have not already been paid for |
|
| 2066 | - * |
|
| 2067 | - * @param EE_Transaction $transaction |
|
| 2068 | - * @param \EE_Payment $payment |
|
| 2069 | - * @param array $REG_IDs |
|
| 2070 | - * @return void |
|
| 2071 | - * @throws EE_Error |
|
| 2072 | - * @throws InvalidArgumentException |
|
| 2073 | - * @throws ReflectionException |
|
| 2074 | - * @throws RuntimeException |
|
| 2075 | - * @throws InvalidDataTypeException |
|
| 2076 | - * @throws InvalidInterfaceException |
|
| 2077 | - */ |
|
| 2078 | - protected function _update_registration_payments( |
|
| 2079 | - EE_Transaction $transaction, |
|
| 2080 | - EE_Payment $payment, |
|
| 2081 | - $REG_IDs = array() |
|
| 2082 | - ) { |
|
| 2083 | - // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments() |
|
| 2084 | - // so let's do that using our set of REG_IDs from the form |
|
| 2085 | - $registration_query_where_params = array( |
|
| 2086 | - 'REG_ID' => array('IN', $REG_IDs), |
|
| 2087 | - ); |
|
| 2088 | - // but add in some conditions regarding payment, |
|
| 2089 | - // so that we don't apply payments to registrations that are free or have already been paid for |
|
| 2090 | - // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative ) |
|
| 2091 | - if (! $payment->is_a_refund()) { |
|
| 2092 | - $registration_query_where_params['REG_final_price'] = array('!=', 0); |
|
| 2093 | - $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true); |
|
| 2094 | - } |
|
| 2095 | - $registrations = $transaction->registrations(array($registration_query_where_params)); |
|
| 2096 | - if (! empty($registrations)) { |
|
| 2097 | - /** @type EE_Payment_Processor $payment_processor */ |
|
| 2098 | - $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 2099 | - $payment_processor->process_registration_payments($transaction, $payment, $registrations); |
|
| 2100 | - } |
|
| 2101 | - } |
|
| 2102 | - |
|
| 2103 | - |
|
| 2104 | - /** |
|
| 2105 | - * _process_registration_status_change |
|
| 2106 | - * This processes requested registration status changes for all the registrations |
|
| 2107 | - * on a given transaction and (optionally) sends out notifications for the changes. |
|
| 2108 | - * |
|
| 2109 | - * @param EE_Transaction $transaction |
|
| 2110 | - * @param array $REG_IDs |
|
| 2111 | - * @return bool |
|
| 2112 | - * @throws EE_Error |
|
| 2113 | - * @throws InvalidArgumentException |
|
| 2114 | - * @throws ReflectionException |
|
| 2115 | - * @throws InvalidDataTypeException |
|
| 2116 | - * @throws InvalidInterfaceException |
|
| 2117 | - */ |
|
| 2118 | - protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array()) |
|
| 2119 | - { |
|
| 2120 | - // first if there is no change in status then we get out. |
|
| 2121 | - if (! isset($this->_req_data['txn_reg_status_change']['reg_status']) |
|
| 2122 | - || $this->_req_data['txn_reg_status_change']['reg_status'] === 'NAN' |
|
| 2123 | - ) { |
|
| 2124 | - // no error message, no change requested, just nothing to do man. |
|
| 2125 | - return false; |
|
| 2126 | - } |
|
| 2127 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 2128 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 2129 | - |
|
| 2130 | - // made it here dude? Oh WOW. K, let's take care of changing the statuses |
|
| 2131 | - return $transaction_processor->manually_update_registration_statuses( |
|
| 2132 | - $transaction, |
|
| 2133 | - sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']), |
|
| 2134 | - array(array('REG_ID' => array('IN', $REG_IDs))) |
|
| 2135 | - ); |
|
| 2136 | - } |
|
| 2137 | - |
|
| 2138 | - |
|
| 2139 | - /** |
|
| 2140 | - * _build_payment_json_response |
|
| 2141 | - * |
|
| 2142 | - * @access public |
|
| 2143 | - * @param \EE_Payment $payment |
|
| 2144 | - * @param array $REG_IDs |
|
| 2145 | - * @param bool | null $delete_txn_reg_status_change |
|
| 2146 | - * @return array |
|
| 2147 | - * @throws EE_Error |
|
| 2148 | - * @throws InvalidArgumentException |
|
| 2149 | - * @throws InvalidDataTypeException |
|
| 2150 | - * @throws InvalidInterfaceException |
|
| 2151 | - * @throws ReflectionException |
|
| 2152 | - */ |
|
| 2153 | - protected function _build_payment_json_response( |
|
| 2154 | - EE_Payment $payment, |
|
| 2155 | - $REG_IDs = array(), |
|
| 2156 | - $delete_txn_reg_status_change = null |
|
| 2157 | - ) { |
|
| 2158 | - // was the payment deleted ? |
|
| 2159 | - if (is_bool($delete_txn_reg_status_change)) { |
|
| 2160 | - return array( |
|
| 2161 | - 'PAY_ID' => $payment->ID(), |
|
| 2162 | - 'amount' => $payment->amount(), |
|
| 2163 | - 'total_paid' => $payment->transaction()->paid(), |
|
| 2164 | - 'txn_status' => $payment->transaction()->status_ID(), |
|
| 2165 | - 'pay_status' => $payment->STS_ID(), |
|
| 2166 | - 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
| 2167 | - 'delete_txn_reg_status_change' => $delete_txn_reg_status_change, |
|
| 2168 | - ); |
|
| 2169 | - } else { |
|
| 2170 | - $this->_get_payment_status_array(); |
|
| 2171 | - |
|
| 2172 | - return array( |
|
| 2173 | - 'amount' => $payment->amount(), |
|
| 2174 | - 'total_paid' => $payment->transaction()->paid(), |
|
| 2175 | - 'txn_status' => $payment->transaction()->status_ID(), |
|
| 2176 | - 'pay_status' => $payment->STS_ID(), |
|
| 2177 | - 'PAY_ID' => $payment->ID(), |
|
| 2178 | - 'STS_ID' => $payment->STS_ID(), |
|
| 2179 | - 'status' => self::$_pay_status[ $payment->STS_ID() ], |
|
| 2180 | - 'date' => $payment->timestamp('Y-m-d', 'h:i a'), |
|
| 2181 | - 'method' => strtoupper($payment->source()), |
|
| 2182 | - 'PM_ID' => $payment->payment_method() ? $payment->payment_method()->ID() : 1, |
|
| 2183 | - 'gateway' => $payment->payment_method() |
|
| 2184 | - ? $payment->payment_method()->admin_name() |
|
| 2185 | - : esc_html__('Unknown', 'event_espresso'), |
|
| 2186 | - 'gateway_response' => $payment->gateway_response(), |
|
| 2187 | - 'txn_id_chq_nmbr' => $payment->txn_id_chq_nmbr(), |
|
| 2188 | - 'po_number' => $payment->po_number(), |
|
| 2189 | - 'extra_accntng' => $payment->extra_accntng(), |
|
| 2190 | - 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
| 2191 | - ); |
|
| 2192 | - } |
|
| 2193 | - } |
|
| 2194 | - |
|
| 2195 | - |
|
| 2196 | - /** |
|
| 2197 | - * delete_payment |
|
| 2198 | - * delete a payment or refund made towards a transaction |
|
| 2199 | - * |
|
| 2200 | - * @access public |
|
| 2201 | - * @return void |
|
| 2202 | - * @throws EE_Error |
|
| 2203 | - * @throws InvalidArgumentException |
|
| 2204 | - * @throws ReflectionException |
|
| 2205 | - * @throws InvalidDataTypeException |
|
| 2206 | - * @throws InvalidInterfaceException |
|
| 2207 | - */ |
|
| 2208 | - public function delete_payment() |
|
| 2209 | - { |
|
| 2210 | - $json_response_data = array('return_data' => false); |
|
| 2211 | - $PAY_ID = isset($this->_req_data['delete_txn_admin_payment']['PAY_ID']) |
|
| 2212 | - ? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID']) |
|
| 2213 | - : 0; |
|
| 2214 | - $can_delete = EE_Registry::instance()->CAP->current_user_can( |
|
| 2215 | - 'ee_delete_payments', |
|
| 2216 | - 'delete_payment_from_registration_details' |
|
| 2217 | - ); |
|
| 2218 | - if ($PAY_ID && $can_delete) { |
|
| 2219 | - $delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change']) |
|
| 2220 | - ? $this->_req_data['delete_txn_reg_status_change'] |
|
| 2221 | - : false; |
|
| 2222 | - $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
| 2223 | - if ($payment instanceof EE_Payment) { |
|
| 2224 | - $REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 2225 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 2226 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 2227 | - if ($transaction_payments->delete_payment_and_update_transaction($payment)) { |
|
| 2228 | - $json_response_data['return_data'] = $this->_build_payment_json_response( |
|
| 2229 | - $payment, |
|
| 2230 | - $REG_IDs, |
|
| 2231 | - $delete_txn_reg_status_change |
|
| 2232 | - ); |
|
| 2233 | - if ($delete_txn_reg_status_change) { |
|
| 2234 | - $this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
| 2235 | - // MAKE sure we also add the delete_txn_req_status_change to the |
|
| 2236 | - // $_REQUEST global because that's how messages will be looking for it. |
|
| 2237 | - $_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
| 2238 | - $this->_maybe_send_notifications(); |
|
| 2239 | - $this->_process_registration_status_change($payment->transaction(), $REG_IDs); |
|
| 2240 | - } |
|
| 2241 | - } |
|
| 2242 | - } else { |
|
| 2243 | - EE_Error::add_error( |
|
| 2244 | - esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'), |
|
| 2245 | - __FILE__, |
|
| 2246 | - __FUNCTION__, |
|
| 2247 | - __LINE__ |
|
| 2248 | - ); |
|
| 2249 | - } |
|
| 2250 | - } elseif ($can_delete) { |
|
| 2251 | - EE_Error::add_error( |
|
| 2252 | - esc_html__( |
|
| 2253 | - 'A valid Payment ID was not received, therefore payment form data could not be loaded.', |
|
| 2254 | - 'event_espresso' |
|
| 2255 | - ), |
|
| 2256 | - __FILE__, |
|
| 2257 | - __FUNCTION__, |
|
| 2258 | - __LINE__ |
|
| 2259 | - ); |
|
| 2260 | - } else { |
|
| 2261 | - EE_Error::add_error( |
|
| 2262 | - esc_html__( |
|
| 2263 | - 'You do not have access to delete a payment.', |
|
| 2264 | - 'event_espresso' |
|
| 2265 | - ), |
|
| 2266 | - __FILE__, |
|
| 2267 | - __FUNCTION__, |
|
| 2268 | - __LINE__ |
|
| 2269 | - ); |
|
| 2270 | - } |
|
| 2271 | - $notices = EE_Error::get_notices(false, false, false); |
|
| 2272 | - $this->_template_args = array( |
|
| 2273 | - 'data' => $json_response_data, |
|
| 2274 | - 'success' => $notices['success'], |
|
| 2275 | - 'error' => $notices['errors'], |
|
| 2276 | - 'attention' => $notices['attention'], |
|
| 2277 | - ); |
|
| 2278 | - $this->_return_json(); |
|
| 2279 | - } |
|
| 2280 | - |
|
| 2281 | - |
|
| 2282 | - /** |
|
| 2283 | - * _registration_payment_data_array |
|
| 2284 | - * adds info for 'owing' and 'paid' for each registration to the json response |
|
| 2285 | - * |
|
| 2286 | - * @access protected |
|
| 2287 | - * @param array $REG_IDs |
|
| 2288 | - * @return array |
|
| 2289 | - * @throws EE_Error |
|
| 2290 | - * @throws InvalidArgumentException |
|
| 2291 | - * @throws InvalidDataTypeException |
|
| 2292 | - * @throws InvalidInterfaceException |
|
| 2293 | - * @throws ReflectionException |
|
| 2294 | - */ |
|
| 2295 | - protected function _registration_payment_data_array($REG_IDs) |
|
| 2296 | - { |
|
| 2297 | - $registration_payment_data = array(); |
|
| 2298 | - // if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows. |
|
| 2299 | - if (! empty($REG_IDs)) { |
|
| 2300 | - $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs)))); |
|
| 2301 | - foreach ($registrations as $registration) { |
|
| 2302 | - if ($registration instanceof EE_Registration) { |
|
| 2303 | - $registration_payment_data[ $registration->ID() ] = array( |
|
| 2304 | - 'paid' => $registration->pretty_paid(), |
|
| 2305 | - 'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()), |
|
| 2306 | - ); |
|
| 2307 | - } |
|
| 2308 | - } |
|
| 2309 | - } |
|
| 2310 | - |
|
| 2311 | - return $registration_payment_data; |
|
| 2312 | - } |
|
| 2313 | - |
|
| 2314 | - |
|
| 2315 | - /** |
|
| 2316 | - * _maybe_send_notifications |
|
| 2317 | - * determines whether or not the admin has indicated that notifications should be sent. |
|
| 2318 | - * If so, will toggle a filter switch for delivering registration notices. |
|
| 2319 | - * If passed an EE_Payment object, then it will trigger payment notifications instead. |
|
| 2320 | - * |
|
| 2321 | - * @access protected |
|
| 2322 | - * @param \EE_Payment | null $payment |
|
| 2323 | - */ |
|
| 2324 | - protected function _maybe_send_notifications($payment = null) |
|
| 2325 | - { |
|
| 2326 | - switch ($payment instanceof EE_Payment) { |
|
| 2327 | - // payment notifications |
|
| 2328 | - case true: |
|
| 2329 | - if (isset($this->_req_data['txn_payments']['send_notifications']) |
|
| 2330 | - && filter_var( |
|
| 2331 | - $this->_req_data['txn_payments']['send_notifications'], |
|
| 2332 | - FILTER_VALIDATE_BOOLEAN |
|
| 2333 | - ) |
|
| 2334 | - ) { |
|
| 2335 | - $this->_process_payment_notification($payment); |
|
| 2336 | - } |
|
| 2337 | - break; |
|
| 2338 | - // registration notifications |
|
| 2339 | - case false: |
|
| 2340 | - if (isset($this->_req_data['txn_reg_status_change']['send_notifications']) |
|
| 2341 | - && filter_var( |
|
| 2342 | - $this->_req_data['txn_reg_status_change']['send_notifications'], |
|
| 2343 | - FILTER_VALIDATE_BOOLEAN |
|
| 2344 | - ) |
|
| 2345 | - ) { |
|
| 2346 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
| 2347 | - } |
|
| 2348 | - break; |
|
| 2349 | - } |
|
| 2350 | - } |
|
| 2351 | - |
|
| 2352 | - |
|
| 2353 | - /** |
|
| 2354 | - * _send_payment_reminder |
|
| 2355 | - * generates HTML for the View Transaction Details Admin page |
|
| 2356 | - * |
|
| 2357 | - * @access protected |
|
| 2358 | - * @return void |
|
| 2359 | - * @throws EE_Error |
|
| 2360 | - * @throws InvalidArgumentException |
|
| 2361 | - * @throws InvalidDataTypeException |
|
| 2362 | - * @throws InvalidInterfaceException |
|
| 2363 | - */ |
|
| 2364 | - protected function _send_payment_reminder() |
|
| 2365 | - { |
|
| 2366 | - $TXN_ID = ! empty($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : false; |
|
| 2367 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 2368 | - $query_args = isset($this->_req_data['redirect_to']) ? array( |
|
| 2369 | - 'action' => $this->_req_data['redirect_to'], |
|
| 2370 | - 'TXN_ID' => $this->_req_data['TXN_ID'], |
|
| 2371 | - ) : array(); |
|
| 2372 | - do_action( |
|
| 2373 | - 'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
| 2374 | - $transaction |
|
| 2375 | - ); |
|
| 2376 | - $this->_redirect_after_action( |
|
| 2377 | - false, |
|
| 2378 | - esc_html__('payment reminder', 'event_espresso'), |
|
| 2379 | - esc_html__('sent', 'event_espresso'), |
|
| 2380 | - $query_args, |
|
| 2381 | - true |
|
| 2382 | - ); |
|
| 2383 | - } |
|
| 2384 | - |
|
| 2385 | - |
|
| 2386 | - /** |
|
| 2387 | - * get_transactions |
|
| 2388 | - * get transactions for given parameters (used by list table) |
|
| 2389 | - * |
|
| 2390 | - * @param int $perpage how many transactions displayed per page |
|
| 2391 | - * @param boolean $count return the count or objects |
|
| 2392 | - * @param string $view |
|
| 2393 | - * @return mixed int = count || array of transaction objects |
|
| 2394 | - * @throws EE_Error |
|
| 2395 | - * @throws InvalidArgumentException |
|
| 2396 | - * @throws InvalidDataTypeException |
|
| 2397 | - * @throws InvalidInterfaceException |
|
| 2398 | - */ |
|
| 2399 | - public function get_transactions($perpage, $count = false, $view = '') |
|
| 2400 | - { |
|
| 2401 | - |
|
| 2402 | - $TXN = EEM_Transaction::instance(); |
|
| 2403 | - |
|
| 2404 | - $start_date = isset($this->_req_data['txn-filter-start-date']) |
|
| 2405 | - ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) |
|
| 2406 | - : date( |
|
| 2407 | - 'm/d/Y', |
|
| 2408 | - strtotime('-10 year') |
|
| 2409 | - ); |
|
| 2410 | - $end_date = isset($this->_req_data['txn-filter-end-date']) |
|
| 2411 | - ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) |
|
| 2412 | - : date('m/d/Y'); |
|
| 2413 | - |
|
| 2414 | - // make sure our timestamps start and end right at the boundaries for each day |
|
| 2415 | - $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
| 2416 | - $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
| 2417 | - |
|
| 2418 | - |
|
| 2419 | - // convert to timestamps |
|
| 2420 | - $start_date = strtotime($start_date); |
|
| 2421 | - $end_date = strtotime($end_date); |
|
| 2422 | - |
|
| 2423 | - // makes sure start date is the lowest value and vice versa |
|
| 2424 | - $start_date = min($start_date, $end_date); |
|
| 2425 | - $end_date = max($start_date, $end_date); |
|
| 2426 | - |
|
| 2427 | - // convert to correct format for query |
|
| 2428 | - $start_date = EEM_Transaction::instance()->convert_datetime_for_query( |
|
| 2429 | - 'TXN_timestamp', |
|
| 2430 | - date('Y-m-d H:i:s', $start_date), |
|
| 2431 | - 'Y-m-d H:i:s' |
|
| 2432 | - ); |
|
| 2433 | - $end_date = EEM_Transaction::instance()->convert_datetime_for_query( |
|
| 2434 | - 'TXN_timestamp', |
|
| 2435 | - date('Y-m-d H:i:s', $end_date), |
|
| 2436 | - 'Y-m-d H:i:s' |
|
| 2437 | - ); |
|
| 2438 | - |
|
| 2439 | - |
|
| 2440 | - // set orderby |
|
| 2441 | - $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
|
| 2442 | - |
|
| 2443 | - switch ($this->_req_data['orderby']) { |
|
| 2444 | - case 'TXN_ID': |
|
| 2445 | - $orderby = 'TXN_ID'; |
|
| 2446 | - break; |
|
| 2447 | - case 'ATT_fname': |
|
| 2448 | - $orderby = 'Registration.Attendee.ATT_fname'; |
|
| 2449 | - break; |
|
| 2450 | - case 'event_name': |
|
| 2451 | - $orderby = 'Registration.Event.EVT_name'; |
|
| 2452 | - break; |
|
| 2453 | - default: // 'TXN_timestamp' |
|
| 2454 | - $orderby = 'TXN_timestamp'; |
|
| 2455 | - } |
|
| 2456 | - |
|
| 2457 | - $sort = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
| 2458 | - $current_page = ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
| 2459 | - $per_page = ! empty($perpage) ? $perpage : 10; |
|
| 2460 | - $per_page = ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page; |
|
| 2461 | - |
|
| 2462 | - $offset = ($current_page - 1) * $per_page; |
|
| 2463 | - $limit = array($offset, $per_page); |
|
| 2464 | - |
|
| 2465 | - $_where = array( |
|
| 2466 | - 'TXN_timestamp' => array('BETWEEN', array($start_date, $end_date)), |
|
| 2467 | - 'Registration.REG_count' => 1, |
|
| 2468 | - ); |
|
| 2469 | - |
|
| 2470 | - if (isset($this->_req_data['EVT_ID'])) { |
|
| 2471 | - $_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID']; |
|
| 2472 | - } |
|
| 2473 | - |
|
| 2474 | - if (isset($this->_req_data['s'])) { |
|
| 2475 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 2476 | - $_where['OR'] = array( |
|
| 2477 | - 'Registration.Event.EVT_name' => array('LIKE', $search_string), |
|
| 2478 | - 'Registration.Event.EVT_desc' => array('LIKE', $search_string), |
|
| 2479 | - 'Registration.Event.EVT_short_desc' => array('LIKE', $search_string), |
|
| 2480 | - 'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string), |
|
| 2481 | - 'Registration.Attendee.ATT_fname' => array('LIKE', $search_string), |
|
| 2482 | - 'Registration.Attendee.ATT_lname' => array('LIKE', $search_string), |
|
| 2483 | - 'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string), |
|
| 2484 | - 'Registration.Attendee.ATT_email' => array('LIKE', $search_string), |
|
| 2485 | - 'Registration.Attendee.ATT_address' => array('LIKE', $search_string), |
|
| 2486 | - 'Registration.Attendee.ATT_address2' => array('LIKE', $search_string), |
|
| 2487 | - 'Registration.Attendee.ATT_city' => array('LIKE', $search_string), |
|
| 2488 | - 'Registration.REG_final_price' => array('LIKE', $search_string), |
|
| 2489 | - 'Registration.REG_code' => array('LIKE', $search_string), |
|
| 2490 | - 'Registration.REG_count' => array('LIKE', $search_string), |
|
| 2491 | - 'Registration.REG_group_size' => array('LIKE', $search_string), |
|
| 2492 | - 'Registration.Ticket.TKT_name' => array('LIKE', $search_string), |
|
| 2493 | - 'Registration.Ticket.TKT_description' => array('LIKE', $search_string), |
|
| 2494 | - 'Payment.PAY_source' => array('LIKE', $search_string), |
|
| 2495 | - 'Payment.Payment_Method.PMD_name' => array('LIKE', $search_string), |
|
| 2496 | - 'TXN_session_data' => array('LIKE', $search_string), |
|
| 2497 | - 'Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string), |
|
| 2498 | - ); |
|
| 2499 | - } |
|
| 2500 | - |
|
| 2501 | - // failed transactions |
|
| 2502 | - $failed = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count) |
|
| 2503 | - || ($count && $view === 'failed'); |
|
| 2504 | - $abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count) |
|
| 2505 | - || ($count && $view === 'abandoned'); |
|
| 2506 | - $incomplete = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'incomplete' && ! $count) |
|
| 2507 | - || ($count && $view === 'incomplete'); |
|
| 2508 | - |
|
| 2509 | - if ($failed) { |
|
| 2510 | - $_where['STS_ID'] = EEM_Transaction::failed_status_code; |
|
| 2511 | - } elseif ($abandoned) { |
|
| 2512 | - $_where['STS_ID'] = EEM_Transaction::abandoned_status_code; |
|
| 2513 | - } elseif ($incomplete) { |
|
| 2514 | - $_where['STS_ID'] = EEM_Transaction::incomplete_status_code; |
|
| 2515 | - } else { |
|
| 2516 | - $_where['STS_ID'] = array('!=', EEM_Transaction::failed_status_code); |
|
| 2517 | - $_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code); |
|
| 2518 | - } |
|
| 2519 | - |
|
| 2520 | - $query_params = apply_filters( |
|
| 2521 | - 'FHEE__Transactions_Admin_Page___get_transactions_query_params', |
|
| 2522 | - array( |
|
| 2523 | - $_where, |
|
| 2524 | - 'order_by' => array($orderby => $sort), |
|
| 2525 | - 'limit' => $limit, |
|
| 2526 | - 'default_where_conditions' => EEM_Base::default_where_conditions_this_only, |
|
| 2527 | - ), |
|
| 2528 | - $this->_req_data, |
|
| 2529 | - $view, |
|
| 2530 | - $count |
|
| 2531 | - ); |
|
| 2532 | - |
|
| 2533 | - $transactions = $count |
|
| 2534 | - ? $TXN->count(array($query_params[0]), 'TXN_ID', true) |
|
| 2535 | - : $TXN->get_all($query_params); |
|
| 2536 | - |
|
| 2537 | - return $transactions; |
|
| 2538 | - } |
|
| 2539 | - |
|
| 2540 | - |
|
| 2541 | - /** |
|
| 2542 | - * @since 4.9.79.p |
|
| 2543 | - * @throws EE_Error |
|
| 2544 | - * @throws InvalidArgumentException |
|
| 2545 | - * @throws InvalidDataTypeException |
|
| 2546 | - * @throws InvalidInterfaceException |
|
| 2547 | - * @throws ReflectionException |
|
| 2548 | - * @throws RuntimeException |
|
| 2549 | - */ |
|
| 2550 | - public function recalculateLineItems() |
|
| 2551 | - { |
|
| 2552 | - $TXN_ID = ! empty($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : false; |
|
| 2553 | - /** @var EE_Transaction $transaction */ |
|
| 2554 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 2555 | - $total_line_item = $transaction->total_line_item(false); |
|
| 2556 | - $success = $transaction->recalculateLineItems(); |
|
| 2557 | - $this->_redirect_after_action( |
|
| 2558 | - (bool) $success, |
|
| 2559 | - esc_html__('Transaction taxes and totals', 'event_espresso'), |
|
| 2560 | - esc_html__('recalculated', 'event_espresso'), |
|
| 2561 | - isset($this->_req_data['redirect_to']) |
|
| 2562 | - ? array( |
|
| 2563 | - 'action' => $this->_req_data['redirect_to'], |
|
| 2564 | - 'TXN_ID' => $this->_req_data['TXN_ID'], |
|
| 2565 | - ) |
|
| 2566 | - : array(), |
|
| 2567 | - true |
|
| 2568 | - ); |
|
| 2569 | - } |
|
| 16 | + /** |
|
| 17 | + * @var EE_Transaction |
|
| 18 | + */ |
|
| 19 | + private $_transaction; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @var EE_Session |
|
| 23 | + */ |
|
| 24 | + private $_session; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @var array $_txn_status |
|
| 28 | + */ |
|
| 29 | + private static $_txn_status; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var array $_pay_status |
|
| 33 | + */ |
|
| 34 | + private static $_pay_status; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var array $_existing_reg_payment_REG_IDs |
|
| 38 | + */ |
|
| 39 | + protected $_existing_reg_payment_REG_IDs; |
|
| 40 | + |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * _init_page_props |
|
| 44 | + * |
|
| 45 | + * @return void |
|
| 46 | + */ |
|
| 47 | + protected function _init_page_props() |
|
| 48 | + { |
|
| 49 | + $this->page_slug = TXN_PG_SLUG; |
|
| 50 | + $this->page_label = esc_html__('Transactions', 'event_espresso'); |
|
| 51 | + $this->_admin_base_url = TXN_ADMIN_URL; |
|
| 52 | + $this->_admin_base_path = TXN_ADMIN; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * _ajax_hooks |
|
| 58 | + * |
|
| 59 | + * @return void |
|
| 60 | + */ |
|
| 61 | + protected function _ajax_hooks() |
|
| 62 | + { |
|
| 63 | + add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds')); |
|
| 64 | + add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds')); |
|
| 65 | + add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment')); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * _define_page_props |
|
| 71 | + * |
|
| 72 | + * @return void |
|
| 73 | + */ |
|
| 74 | + protected function _define_page_props() |
|
| 75 | + { |
|
| 76 | + $this->_admin_page_title = $this->page_label; |
|
| 77 | + $this->_labels = array( |
|
| 78 | + 'buttons' => array( |
|
| 79 | + 'add' => esc_html__('Add New Transaction', 'event_espresso'), |
|
| 80 | + 'edit' => esc_html__('Edit Transaction', 'event_espresso'), |
|
| 81 | + 'delete' => esc_html__('Delete Transaction', 'event_espresso'), |
|
| 82 | + ), |
|
| 83 | + ); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * grab url requests and route them |
|
| 89 | + * |
|
| 90 | + * @access private |
|
| 91 | + * @return void |
|
| 92 | + * @throws EE_Error |
|
| 93 | + * @throws InvalidArgumentException |
|
| 94 | + * @throws InvalidDataTypeException |
|
| 95 | + * @throws InvalidInterfaceException |
|
| 96 | + */ |
|
| 97 | + public function _set_page_routes() |
|
| 98 | + { |
|
| 99 | + |
|
| 100 | + $this->_set_transaction_status_array(); |
|
| 101 | + |
|
| 102 | + $txn_id = ! empty($this->_req_data['TXN_ID']) |
|
| 103 | + && ! is_array($this->_req_data['TXN_ID']) |
|
| 104 | + ? $this->_req_data['TXN_ID'] |
|
| 105 | + : 0; |
|
| 106 | + |
|
| 107 | + $this->_page_routes = array( |
|
| 108 | + |
|
| 109 | + 'default' => array( |
|
| 110 | + 'func' => '_transactions_overview_list_table', |
|
| 111 | + 'capability' => 'ee_read_transactions', |
|
| 112 | + ), |
|
| 113 | + |
|
| 114 | + 'view_transaction' => array( |
|
| 115 | + 'func' => '_transaction_details', |
|
| 116 | + 'capability' => 'ee_read_transaction', |
|
| 117 | + 'obj_id' => $txn_id, |
|
| 118 | + ), |
|
| 119 | + |
|
| 120 | + 'send_payment_reminder' => array( |
|
| 121 | + 'func' => '_send_payment_reminder', |
|
| 122 | + 'noheader' => true, |
|
| 123 | + 'capability' => 'ee_send_message', |
|
| 124 | + ), |
|
| 125 | + |
|
| 126 | + 'espresso_apply_payment' => array( |
|
| 127 | + 'func' => 'apply_payments_or_refunds', |
|
| 128 | + 'noheader' => true, |
|
| 129 | + 'capability' => 'ee_edit_payments', |
|
| 130 | + ), |
|
| 131 | + |
|
| 132 | + 'espresso_apply_refund' => array( |
|
| 133 | + 'func' => 'apply_payments_or_refunds', |
|
| 134 | + 'noheader' => true, |
|
| 135 | + 'capability' => 'ee_edit_payments', |
|
| 136 | + ), |
|
| 137 | + |
|
| 138 | + 'espresso_delete_payment' => array( |
|
| 139 | + 'func' => 'delete_payment', |
|
| 140 | + 'noheader' => true, |
|
| 141 | + 'capability' => 'ee_delete_payments', |
|
| 142 | + ), |
|
| 143 | + |
|
| 144 | + 'espresso_recalculate_line_items' => array( |
|
| 145 | + 'func' => 'recalculateLineItems', |
|
| 146 | + 'noheader' => true, |
|
| 147 | + 'capability' => 'ee_edit_payments', |
|
| 148 | + ), |
|
| 149 | + |
|
| 150 | + ); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + |
|
| 154 | + protected function _set_page_config() |
|
| 155 | + { |
|
| 156 | + $this->_page_config = array( |
|
| 157 | + 'default' => array( |
|
| 158 | + 'nav' => array( |
|
| 159 | + 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 160 | + 'order' => 10, |
|
| 161 | + ), |
|
| 162 | + 'list_table' => 'EE_Admin_Transactions_List_Table', |
|
| 163 | + 'help_tabs' => array( |
|
| 164 | + 'transactions_overview_help_tab' => array( |
|
| 165 | + 'title' => esc_html__('Transactions Overview', 'event_espresso'), |
|
| 166 | + 'filename' => 'transactions_overview', |
|
| 167 | + ), |
|
| 168 | + 'transactions_overview_table_column_headings_help_tab' => array( |
|
| 169 | + 'title' => esc_html__('Transactions Table Column Headings', 'event_espresso'), |
|
| 170 | + 'filename' => 'transactions_overview_table_column_headings', |
|
| 171 | + ), |
|
| 172 | + 'transactions_overview_views_filters_help_tab' => array( |
|
| 173 | + 'title' => esc_html__('Transaction Views & Filters & Search', 'event_espresso'), |
|
| 174 | + 'filename' => 'transactions_overview_views_filters_search', |
|
| 175 | + ), |
|
| 176 | + ), |
|
| 177 | + 'help_tour' => array('Transactions_Overview_Help_Tour'), |
|
| 178 | + /** |
|
| 179 | + * commented out because currently we are not displaying tips for transaction list table status but this |
|
| 180 | + * may change in a later iteration so want to keep the code for then. |
|
| 181 | + */ |
|
| 182 | + // 'qtips' => array( 'Transactions_List_Table_Tips' ), |
|
| 183 | + 'require_nonce' => false, |
|
| 184 | + ), |
|
| 185 | + 'view_transaction' => array( |
|
| 186 | + 'nav' => array( |
|
| 187 | + 'label' => esc_html__('View Transaction', 'event_espresso'), |
|
| 188 | + 'order' => 5, |
|
| 189 | + 'url' => isset($this->_req_data['TXN_ID']) |
|
| 190 | + ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']), $this->_current_page_view_url) |
|
| 191 | + : $this->_admin_base_url, |
|
| 192 | + 'persistent' => false, |
|
| 193 | + ), |
|
| 194 | + 'help_tabs' => array( |
|
| 195 | + 'transactions_view_transaction_help_tab' => array( |
|
| 196 | + 'title' => esc_html__('View Transaction', 'event_espresso'), |
|
| 197 | + 'filename' => 'transactions_view_transaction', |
|
| 198 | + ), |
|
| 199 | + 'transactions_view_transaction_transaction_details_table_help_tab' => array( |
|
| 200 | + 'title' => esc_html__('Transaction Details Table', 'event_espresso'), |
|
| 201 | + 'filename' => 'transactions_view_transaction_transaction_details_table', |
|
| 202 | + ), |
|
| 203 | + 'transactions_view_transaction_attendees_registered_help_tab' => array( |
|
| 204 | + 'title' => esc_html__('Attendees Registered', 'event_espresso'), |
|
| 205 | + 'filename' => 'transactions_view_transaction_attendees_registered', |
|
| 206 | + ), |
|
| 207 | + 'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array( |
|
| 208 | + 'title' => esc_html__('Primary Registrant & Billing Information', 'event_espresso'), |
|
| 209 | + 'filename' => 'transactions_view_transaction_primary_registrant_billing_information', |
|
| 210 | + ), |
|
| 211 | + ), |
|
| 212 | + 'qtips' => array('Transaction_Details_Tips'), |
|
| 213 | + 'help_tour' => array('Transaction_Details_Help_Tour'), |
|
| 214 | + 'metaboxes' => array('_transaction_details_metaboxes'), |
|
| 215 | + |
|
| 216 | + 'require_nonce' => false, |
|
| 217 | + ), |
|
| 218 | + ); |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * The below methods aren't used by this class currently |
|
| 224 | + */ |
|
| 225 | + protected function _add_screen_options() |
|
| 226 | + { |
|
| 227 | + // noop |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + protected function _add_feature_pointers() |
|
| 232 | + { |
|
| 233 | + // noop |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + |
|
| 237 | + public function admin_init() |
|
| 238 | + { |
|
| 239 | + // IF a registration was JUST added via the admin... |
|
| 240 | + if (isset( |
|
| 241 | + $this->_req_data['redirect_from'], |
|
| 242 | + $this->_req_data['EVT_ID'], |
|
| 243 | + $this->_req_data['event_name'] |
|
| 244 | + )) { |
|
| 245 | + // then set a cookie so that we can block any attempts to use |
|
| 246 | + // the back button as a way to enter another registration. |
|
| 247 | + setcookie( |
|
| 248 | + 'ee_registration_added', |
|
| 249 | + $this->_req_data['EVT_ID'], |
|
| 250 | + time() + WEEK_IN_SECONDS, |
|
| 251 | + '/' |
|
| 252 | + ); |
|
| 253 | + // and update the global |
|
| 254 | + $_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID']; |
|
| 255 | + } |
|
| 256 | + EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__( |
|
| 257 | + 'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.', |
|
| 258 | + 'event_espresso' |
|
| 259 | + ); |
|
| 260 | + EE_Registry::$i18n_js_strings['error_occurred'] = esc_html__( |
|
| 261 | + 'An error occurred! Please refresh the page and try again.', |
|
| 262 | + 'event_espresso' |
|
| 263 | + ); |
|
| 264 | + EE_Registry::$i18n_js_strings['txn_status_array'] = self::$_txn_status; |
|
| 265 | + EE_Registry::$i18n_js_strings['pay_status_array'] = self::$_pay_status; |
|
| 266 | + EE_Registry::$i18n_js_strings['payments_total'] = esc_html__('Payments Total', 'event_espresso'); |
|
| 267 | + EE_Registry::$i18n_js_strings['transaction_overpaid'] = esc_html__( |
|
| 268 | + 'This transaction has been overpaid ! Payments Total', |
|
| 269 | + 'event_espresso' |
|
| 270 | + ); |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + |
|
| 274 | + public function admin_notices() |
|
| 275 | + { |
|
| 276 | + // noop |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + |
|
| 280 | + public function admin_footer_scripts() |
|
| 281 | + { |
|
| 282 | + // noop |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * _set_transaction_status_array |
|
| 288 | + * sets list of transaction statuses |
|
| 289 | + * |
|
| 290 | + * @access private |
|
| 291 | + * @return void |
|
| 292 | + * @throws EE_Error |
|
| 293 | + * @throws InvalidArgumentException |
|
| 294 | + * @throws InvalidDataTypeException |
|
| 295 | + * @throws InvalidInterfaceException |
|
| 296 | + */ |
|
| 297 | + private function _set_transaction_status_array() |
|
| 298 | + { |
|
| 299 | + self::$_txn_status = EEM_Transaction::instance()->status_array(true); |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + |
|
| 303 | + /** |
|
| 304 | + * get_transaction_status_array |
|
| 305 | + * return the transaction status array for wp_list_table |
|
| 306 | + * |
|
| 307 | + * @access public |
|
| 308 | + * @return array |
|
| 309 | + */ |
|
| 310 | + public function get_transaction_status_array() |
|
| 311 | + { |
|
| 312 | + return self::$_txn_status; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * get list of payment statuses |
|
| 318 | + * |
|
| 319 | + * @access private |
|
| 320 | + * @return void |
|
| 321 | + * @throws EE_Error |
|
| 322 | + * @throws InvalidArgumentException |
|
| 323 | + * @throws InvalidDataTypeException |
|
| 324 | + * @throws InvalidInterfaceException |
|
| 325 | + */ |
|
| 326 | + private function _get_payment_status_array() |
|
| 327 | + { |
|
| 328 | + self::$_pay_status = EEM_Payment::instance()->status_array(true); |
|
| 329 | + $this->_template_args['payment_status'] = self::$_pay_status; |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + |
|
| 333 | + /** |
|
| 334 | + * _add_screen_options_default |
|
| 335 | + * |
|
| 336 | + * @access protected |
|
| 337 | + * @return void |
|
| 338 | + * @throws InvalidArgumentException |
|
| 339 | + * @throws InvalidDataTypeException |
|
| 340 | + * @throws InvalidInterfaceException |
|
| 341 | + */ |
|
| 342 | + protected function _add_screen_options_default() |
|
| 343 | + { |
|
| 344 | + $this->_per_page_screen_option(); |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + |
|
| 348 | + /** |
|
| 349 | + * load_scripts_styles |
|
| 350 | + * |
|
| 351 | + * @access public |
|
| 352 | + * @return void |
|
| 353 | + */ |
|
| 354 | + public function load_scripts_styles() |
|
| 355 | + { |
|
| 356 | + // enqueue style |
|
| 357 | + wp_register_style( |
|
| 358 | + 'espresso_txn', |
|
| 359 | + TXN_ASSETS_URL . 'espresso_transactions_admin.css', |
|
| 360 | + array(), |
|
| 361 | + EVENT_ESPRESSO_VERSION |
|
| 362 | + ); |
|
| 363 | + wp_enqueue_style('espresso_txn'); |
|
| 364 | + // scripts |
|
| 365 | + wp_register_script( |
|
| 366 | + 'espresso_txn', |
|
| 367 | + TXN_ASSETS_URL . 'espresso_transactions_admin.js', |
|
| 368 | + array( |
|
| 369 | + 'ee_admin_js', |
|
| 370 | + 'ee-datepicker', |
|
| 371 | + 'jquery-ui-datepicker', |
|
| 372 | + 'jquery-ui-draggable', |
|
| 373 | + 'ee-dialog', |
|
| 374 | + 'ee-accounting', |
|
| 375 | + 'ee-serialize-full-array', |
|
| 376 | + ), |
|
| 377 | + EVENT_ESPRESSO_VERSION, |
|
| 378 | + true |
|
| 379 | + ); |
|
| 380 | + wp_enqueue_script('espresso_txn'); |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * load_scripts_styles_view_transaction |
|
| 386 | + * |
|
| 387 | + * @access public |
|
| 388 | + * @return void |
|
| 389 | + */ |
|
| 390 | + public function load_scripts_styles_view_transaction() |
|
| 391 | + { |
|
| 392 | + // styles |
|
| 393 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * load_scripts_styles_default |
|
| 399 | + * |
|
| 400 | + * @access public |
|
| 401 | + * @return void |
|
| 402 | + */ |
|
| 403 | + public function load_scripts_styles_default() |
|
| 404 | + { |
|
| 405 | + // styles |
|
| 406 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * _set_list_table_views_default |
|
| 412 | + * |
|
| 413 | + * @access protected |
|
| 414 | + * @return void |
|
| 415 | + */ |
|
| 416 | + protected function _set_list_table_views_default() |
|
| 417 | + { |
|
| 418 | + $this->_views = array( |
|
| 419 | + 'all' => array( |
|
| 420 | + 'slug' => 'all', |
|
| 421 | + 'label' => esc_html__('View All Transactions', 'event_espresso'), |
|
| 422 | + 'count' => 0, |
|
| 423 | + ), |
|
| 424 | + 'abandoned' => array( |
|
| 425 | + 'slug' => 'abandoned', |
|
| 426 | + 'label' => esc_html__('Abandoned Transactions', 'event_espresso'), |
|
| 427 | + 'count' => 0, |
|
| 428 | + ), |
|
| 429 | + 'incomplete' => array( |
|
| 430 | + 'slug' => 'incomplete', |
|
| 431 | + 'label' => esc_html__('Incomplete Transactions', 'event_espresso'), |
|
| 432 | + 'count' => 0, |
|
| 433 | + ), |
|
| 434 | + ); |
|
| 435 | + if (/** |
|
| 436 | + * Filters whether a link to the "Failed Transactions" list table |
|
| 437 | + * appears on the Transactions Admin Page list table. |
|
| 438 | + * List display can be turned back on via the following: |
|
| 439 | + * add_filter( |
|
| 440 | + * 'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list', |
|
| 441 | + * '__return_true' |
|
| 442 | + * ); |
|
| 443 | + * |
|
| 444 | + * @since 4.9.70.p |
|
| 445 | + * @param boolean $display_failed_txns_list |
|
| 446 | + * @param Transactions_Admin_Page $this |
|
| 447 | + */ |
|
| 448 | + apply_filters( |
|
| 449 | + 'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list', |
|
| 450 | + false, |
|
| 451 | + $this |
|
| 452 | + ) |
|
| 453 | + ) { |
|
| 454 | + $this->_views['failed'] = array( |
|
| 455 | + 'slug' => 'failed', |
|
| 456 | + 'label' => esc_html__('Failed Transactions', 'event_espresso'), |
|
| 457 | + 'count' => 0, |
|
| 458 | + ); |
|
| 459 | + } |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * _set_transaction_object |
|
| 465 | + * This sets the _transaction property for the transaction details screen |
|
| 466 | + * |
|
| 467 | + * @access private |
|
| 468 | + * @return void |
|
| 469 | + * @throws EE_Error |
|
| 470 | + * @throws InvalidArgumentException |
|
| 471 | + * @throws RuntimeException |
|
| 472 | + * @throws InvalidDataTypeException |
|
| 473 | + * @throws InvalidInterfaceException |
|
| 474 | + * @throws ReflectionException |
|
| 475 | + */ |
|
| 476 | + private function _set_transaction_object() |
|
| 477 | + { |
|
| 478 | + if ($this->_transaction instanceof EE_Transaction) { |
|
| 479 | + return; |
|
| 480 | + } //get out we've already set the object |
|
| 481 | + |
|
| 482 | + $TXN_ID = ! empty($this->_req_data['TXN_ID']) |
|
| 483 | + ? absint($this->_req_data['TXN_ID']) |
|
| 484 | + : false; |
|
| 485 | + |
|
| 486 | + // get transaction object |
|
| 487 | + $this->_transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 488 | + $this->_session = $this->_transaction instanceof EE_Transaction |
|
| 489 | + ? $this->_transaction->session_data() |
|
| 490 | + : null; |
|
| 491 | + if ($this->_transaction instanceof EE_Transaction) { |
|
| 492 | + $this->_transaction->verify_abandoned_transaction_status(); |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + if (! $this->_transaction instanceof EE_Transaction) { |
|
| 496 | + $error_msg = sprintf( |
|
| 497 | + esc_html__( |
|
| 498 | + 'An error occurred and the details for the transaction with the ID # %d could not be retrieved.', |
|
| 499 | + 'event_espresso' |
|
| 500 | + ), |
|
| 501 | + $TXN_ID |
|
| 502 | + ); |
|
| 503 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 504 | + } |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + |
|
| 508 | + /** |
|
| 509 | + * _transaction_legend_items |
|
| 510 | + * |
|
| 511 | + * @access protected |
|
| 512 | + * @return array |
|
| 513 | + * @throws EE_Error |
|
| 514 | + * @throws InvalidArgumentException |
|
| 515 | + * @throws ReflectionException |
|
| 516 | + * @throws InvalidDataTypeException |
|
| 517 | + * @throws InvalidInterfaceException |
|
| 518 | + */ |
|
| 519 | + protected function _transaction_legend_items() |
|
| 520 | + { |
|
| 521 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 522 | + $items = array(); |
|
| 523 | + |
|
| 524 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 525 | + 'ee_read_global_messages', |
|
| 526 | + 'view_filtered_messages' |
|
| 527 | + )) { |
|
| 528 | + $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 529 | + if (is_array($related_for_icon) |
|
| 530 | + && isset($related_for_icon['css_class'], $related_for_icon['label']) |
|
| 531 | + ) { |
|
| 532 | + $items['view_related_messages'] = array( |
|
| 533 | + 'class' => $related_for_icon['css_class'], |
|
| 534 | + 'desc' => $related_for_icon['label'], |
|
| 535 | + ); |
|
| 536 | + } |
|
| 537 | + } |
|
| 538 | + |
|
| 539 | + $items = apply_filters( |
|
| 540 | + 'FHEE__Transactions_Admin_Page___transaction_legend_items__items', |
|
| 541 | + array_merge( |
|
| 542 | + $items, |
|
| 543 | + array( |
|
| 544 | + 'view_details' => array( |
|
| 545 | + 'class' => 'dashicons dashicons-cart', |
|
| 546 | + 'desc' => esc_html__('View Transaction Details', 'event_espresso'), |
|
| 547 | + ), |
|
| 548 | + 'view_invoice' => array( |
|
| 549 | + 'class' => 'dashicons dashicons-media-spreadsheet', |
|
| 550 | + 'desc' => esc_html__('View Transaction Invoice', 'event_espresso'), |
|
| 551 | + ), |
|
| 552 | + 'view_receipt' => array( |
|
| 553 | + 'class' => 'dashicons dashicons-media-default', |
|
| 554 | + 'desc' => esc_html__('View Transaction Receipt', 'event_espresso'), |
|
| 555 | + ), |
|
| 556 | + 'view_registration' => array( |
|
| 557 | + 'class' => 'dashicons dashicons-clipboard', |
|
| 558 | + 'desc' => esc_html__('View Registration Details', 'event_espresso'), |
|
| 559 | + ), |
|
| 560 | + 'payment_overview_link' => array( |
|
| 561 | + 'class' => 'dashicons dashicons-money', |
|
| 562 | + 'desc' => esc_html__('Make Payment on Frontend', 'event_espresso'), |
|
| 563 | + ), |
|
| 564 | + ) |
|
| 565 | + ) |
|
| 566 | + ); |
|
| 567 | + |
|
| 568 | + if (EEH_MSG_Template::is_mt_active('payment_reminder') |
|
| 569 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 570 | + 'ee_send_message', |
|
| 571 | + 'espresso_transactions_send_payment_reminder' |
|
| 572 | + ) |
|
| 573 | + ) { |
|
| 574 | + $items['send_payment_reminder'] = array( |
|
| 575 | + 'class' => 'dashicons dashicons-email-alt', |
|
| 576 | + 'desc' => esc_html__('Send Payment Reminder', 'event_espresso'), |
|
| 577 | + ); |
|
| 578 | + } else { |
|
| 579 | + $items['blank*'] = array( |
|
| 580 | + 'class' => '', |
|
| 581 | + 'desc' => '', |
|
| 582 | + ); |
|
| 583 | + } |
|
| 584 | + $more_items = apply_filters( |
|
| 585 | + 'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items', |
|
| 586 | + array( |
|
| 587 | + 'overpaid' => array( |
|
| 588 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code, |
|
| 589 | + 'desc' => EEH_Template::pretty_status( |
|
| 590 | + EEM_Transaction::overpaid_status_code, |
|
| 591 | + false, |
|
| 592 | + 'sentence' |
|
| 593 | + ), |
|
| 594 | + ), |
|
| 595 | + 'complete' => array( |
|
| 596 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code, |
|
| 597 | + 'desc' => EEH_Template::pretty_status( |
|
| 598 | + EEM_Transaction::complete_status_code, |
|
| 599 | + false, |
|
| 600 | + 'sentence' |
|
| 601 | + ), |
|
| 602 | + ), |
|
| 603 | + 'incomplete' => array( |
|
| 604 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code, |
|
| 605 | + 'desc' => EEH_Template::pretty_status( |
|
| 606 | + EEM_Transaction::incomplete_status_code, |
|
| 607 | + false, |
|
| 608 | + 'sentence' |
|
| 609 | + ), |
|
| 610 | + ), |
|
| 611 | + 'abandoned' => array( |
|
| 612 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code, |
|
| 613 | + 'desc' => EEH_Template::pretty_status( |
|
| 614 | + EEM_Transaction::abandoned_status_code, |
|
| 615 | + false, |
|
| 616 | + 'sentence' |
|
| 617 | + ), |
|
| 618 | + ), |
|
| 619 | + 'failed' => array( |
|
| 620 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code, |
|
| 621 | + 'desc' => EEH_Template::pretty_status( |
|
| 622 | + EEM_Transaction::failed_status_code, |
|
| 623 | + false, |
|
| 624 | + 'sentence' |
|
| 625 | + ), |
|
| 626 | + ), |
|
| 627 | + ) |
|
| 628 | + ); |
|
| 629 | + |
|
| 630 | + return array_merge($items, $more_items); |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + |
|
| 634 | + /** |
|
| 635 | + * _transactions_overview_list_table |
|
| 636 | + * |
|
| 637 | + * @access protected |
|
| 638 | + * @return void |
|
| 639 | + * @throws DomainException |
|
| 640 | + * @throws EE_Error |
|
| 641 | + * @throws InvalidArgumentException |
|
| 642 | + * @throws InvalidDataTypeException |
|
| 643 | + * @throws InvalidInterfaceException |
|
| 644 | + * @throws ReflectionException |
|
| 645 | + */ |
|
| 646 | + protected function _transactions_overview_list_table() |
|
| 647 | + { |
|
| 648 | + $this->_admin_page_title = esc_html__('Transactions', 'event_espresso'); |
|
| 649 | + $event = isset($this->_req_data['EVT_ID']) |
|
| 650 | + ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']) |
|
| 651 | + : null; |
|
| 652 | + $this->_template_args['admin_page_header'] = $event instanceof EE_Event |
|
| 653 | + ? sprintf( |
|
| 654 | + esc_html__( |
|
| 655 | + '%sViewing Transactions for the Event: %s%s', |
|
| 656 | + 'event_espresso' |
|
| 657 | + ), |
|
| 658 | + '<h3>', |
|
| 659 | + '<a href="' |
|
| 660 | + . EE_Admin_Page::add_query_args_and_nonce( |
|
| 661 | + array('action' => 'edit', 'post' => $event->ID()), |
|
| 662 | + EVENTS_ADMIN_URL |
|
| 663 | + ) |
|
| 664 | + . '" title="' |
|
| 665 | + . esc_attr__( |
|
| 666 | + 'Click to Edit event', |
|
| 667 | + 'event_espresso' |
|
| 668 | + ) |
|
| 669 | + . '">' . $event->name() . '</a>', |
|
| 670 | + '</h3>' |
|
| 671 | + ) |
|
| 672 | + : ''; |
|
| 673 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items()); |
|
| 674 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 675 | + } |
|
| 676 | + |
|
| 677 | + |
|
| 678 | + /** |
|
| 679 | + * _transaction_details |
|
| 680 | + * generates HTML for the View Transaction Details Admin page |
|
| 681 | + * |
|
| 682 | + * @access protected |
|
| 683 | + * @return void |
|
| 684 | + * @throws DomainException |
|
| 685 | + * @throws EE_Error |
|
| 686 | + * @throws InvalidArgumentException |
|
| 687 | + * @throws InvalidDataTypeException |
|
| 688 | + * @throws InvalidInterfaceException |
|
| 689 | + * @throws RuntimeException |
|
| 690 | + * @throws ReflectionException |
|
| 691 | + */ |
|
| 692 | + protected function _transaction_details() |
|
| 693 | + { |
|
| 694 | + do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction); |
|
| 695 | + |
|
| 696 | + $this->_set_transaction_status_array(); |
|
| 697 | + |
|
| 698 | + $this->_template_args = array(); |
|
| 699 | + $this->_template_args['transactions_page'] = $this->_wp_page_slug; |
|
| 700 | + |
|
| 701 | + $this->_set_transaction_object(); |
|
| 702 | + |
|
| 703 | + if (! $this->_transaction instanceof EE_Transaction) { |
|
| 704 | + return; |
|
| 705 | + } |
|
| 706 | + $primary_registration = $this->_transaction->primary_registration(); |
|
| 707 | + $attendee = $primary_registration instanceof EE_Registration |
|
| 708 | + ? $primary_registration->attendee() |
|
| 709 | + : null; |
|
| 710 | + |
|
| 711 | + $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID(); |
|
| 712 | + $this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso'); |
|
| 713 | + |
|
| 714 | + $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp'); |
|
| 715 | + $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso'); |
|
| 716 | + |
|
| 717 | + $this->_template_args['txn_status']['value'] = self::$_txn_status[ $this->_transaction->status_ID() ]; |
|
| 718 | + $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso'); |
|
| 719 | + $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->status_ID(); |
|
| 720 | + |
|
| 721 | + $this->_template_args['grand_total'] = $this->_transaction->total(); |
|
| 722 | + $this->_template_args['total_paid'] = $this->_transaction->paid(); |
|
| 723 | + |
|
| 724 | + $amount_due = $this->_transaction->total() - $this->_transaction->paid(); |
|
| 725 | + $this->_template_args['amount_due'] = EEH_Template::format_currency( |
|
| 726 | + $amount_due, |
|
| 727 | + true |
|
| 728 | + ); |
|
| 729 | + if (EE_Registry::instance()->CFG->currency->sign_b4) { |
|
| 730 | + $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign |
|
| 731 | + . $this->_template_args['amount_due']; |
|
| 732 | + } else { |
|
| 733 | + $this->_template_args['amount_due'] .= EE_Registry::instance()->CFG->currency->sign; |
|
| 734 | + } |
|
| 735 | + $this->_template_args['amount_due_class'] = ''; |
|
| 736 | + |
|
| 737 | + if ($this->_transaction->paid() === $this->_transaction->total()) { |
|
| 738 | + // paid in full |
|
| 739 | + $this->_template_args['amount_due'] = false; |
|
| 740 | + } elseif ($this->_transaction->paid() > $this->_transaction->total()) { |
|
| 741 | + // overpaid |
|
| 742 | + $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 743 | + } elseif ($this->_transaction->total() > (float) 0) { |
|
| 744 | + if ($this->_transaction->paid() > (float) 0) { |
|
| 745 | + // monies owing |
|
| 746 | + $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn'; |
|
| 747 | + } elseif ($this->_transaction->paid() === (float) 0) { |
|
| 748 | + // no payments made yet |
|
| 749 | + $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 750 | + } |
|
| 751 | + } elseif ($this->_transaction->total() === (float) 0) { |
|
| 752 | + // free event |
|
| 753 | + $this->_template_args['amount_due'] = false; |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + $payment_method = $this->_transaction->payment_method(); |
|
| 757 | + |
|
| 758 | + $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method |
|
| 759 | + ? $payment_method->admin_name() |
|
| 760 | + : esc_html__('Unknown', 'event_espresso'); |
|
| 761 | + |
|
| 762 | + $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 763 | + // link back to overview |
|
| 764 | + $this->_template_args['txn_overview_url'] = ! empty($_SERVER['HTTP_REFERER']) |
|
| 765 | + ? $_SERVER['HTTP_REFERER'] |
|
| 766 | + : TXN_ADMIN_URL; |
|
| 767 | + |
|
| 768 | + |
|
| 769 | + // next link |
|
| 770 | + $next_txn = $this->_transaction->next( |
|
| 771 | + null, |
|
| 772 | + array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
| 773 | + 'TXN_ID' |
|
| 774 | + ); |
|
| 775 | + $this->_template_args['next_transaction'] = $next_txn |
|
| 776 | + ? $this->_next_link( |
|
| 777 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 778 | + array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']), |
|
| 779 | + TXN_ADMIN_URL |
|
| 780 | + ), |
|
| 781 | + 'dashicons dashicons-arrow-right ee-icon-size-22' |
|
| 782 | + ) |
|
| 783 | + : ''; |
|
| 784 | + // previous link |
|
| 785 | + $previous_txn = $this->_transaction->previous( |
|
| 786 | + null, |
|
| 787 | + array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
| 788 | + 'TXN_ID' |
|
| 789 | + ); |
|
| 790 | + $this->_template_args['previous_transaction'] = $previous_txn |
|
| 791 | + ? $this->_previous_link( |
|
| 792 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 793 | + array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']), |
|
| 794 | + TXN_ADMIN_URL |
|
| 795 | + ), |
|
| 796 | + 'dashicons dashicons-arrow-left ee-icon-size-22' |
|
| 797 | + ) |
|
| 798 | + : ''; |
|
| 799 | + |
|
| 800 | + // were we just redirected here after adding a new registration ??? |
|
| 801 | + if (isset( |
|
| 802 | + $this->_req_data['redirect_from'], |
|
| 803 | + $this->_req_data['EVT_ID'], |
|
| 804 | + $this->_req_data['event_name'] |
|
| 805 | + )) { |
|
| 806 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 807 | + 'ee_edit_registrations', |
|
| 808 | + 'espresso_registrations_new_registration', |
|
| 809 | + $this->_req_data['EVT_ID'] |
|
| 810 | + )) { |
|
| 811 | + $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="'; |
|
| 812 | + $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce( |
|
| 813 | + array( |
|
| 814 | + 'page' => 'espresso_registrations', |
|
| 815 | + 'action' => 'new_registration', |
|
| 816 | + 'return' => 'default', |
|
| 817 | + 'TXN_ID' => $this->_transaction->ID(), |
|
| 818 | + 'event_id' => $this->_req_data['EVT_ID'], |
|
| 819 | + ), |
|
| 820 | + REG_ADMIN_URL |
|
| 821 | + ); |
|
| 822 | + $this->_admin_page_title .= '">'; |
|
| 823 | + |
|
| 824 | + $this->_admin_page_title .= sprintf( |
|
| 825 | + esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'), |
|
| 826 | + htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8') |
|
| 827 | + ); |
|
| 828 | + $this->_admin_page_title .= '</a>'; |
|
| 829 | + } |
|
| 830 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 831 | + } |
|
| 832 | + // grab messages at the last second |
|
| 833 | + $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 834 | + // path to template |
|
| 835 | + $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php'; |
|
| 836 | + $this->_template_args['admin_page_header'] = EEH_Template::display_template( |
|
| 837 | + $template_path, |
|
| 838 | + $this->_template_args, |
|
| 839 | + true |
|
| 840 | + ); |
|
| 841 | + |
|
| 842 | + // the details template wrapper |
|
| 843 | + $this->display_admin_page_with_sidebar(); |
|
| 844 | + } |
|
| 845 | + |
|
| 846 | + |
|
| 847 | + /** |
|
| 848 | + * _transaction_details_metaboxes |
|
| 849 | + * |
|
| 850 | + * @access protected |
|
| 851 | + * @return void |
|
| 852 | + * @throws EE_Error |
|
| 853 | + * @throws InvalidArgumentException |
|
| 854 | + * @throws InvalidDataTypeException |
|
| 855 | + * @throws InvalidInterfaceException |
|
| 856 | + * @throws RuntimeException |
|
| 857 | + * @throws ReflectionException |
|
| 858 | + */ |
|
| 859 | + protected function _transaction_details_metaboxes() |
|
| 860 | + { |
|
| 861 | + |
|
| 862 | + $this->_set_transaction_object(); |
|
| 863 | + |
|
| 864 | + if (! $this->_transaction instanceof EE_Transaction) { |
|
| 865 | + return; |
|
| 866 | + } |
|
| 867 | + add_meta_box( |
|
| 868 | + 'edit-txn-details-mbox', |
|
| 869 | + esc_html__('Transaction Details', 'event_espresso'), |
|
| 870 | + array($this, 'txn_details_meta_box'), |
|
| 871 | + $this->_wp_page_slug, |
|
| 872 | + 'normal', |
|
| 873 | + 'high' |
|
| 874 | + ); |
|
| 875 | + add_meta_box( |
|
| 876 | + 'edit-txn-attendees-mbox', |
|
| 877 | + esc_html__('Attendees Registered in this Transaction', 'event_espresso'), |
|
| 878 | + array($this, 'txn_attendees_meta_box'), |
|
| 879 | + $this->_wp_page_slug, |
|
| 880 | + 'normal', |
|
| 881 | + 'high', |
|
| 882 | + array('TXN_ID' => $this->_transaction->ID()) |
|
| 883 | + ); |
|
| 884 | + add_meta_box( |
|
| 885 | + 'edit-txn-registrant-mbox', |
|
| 886 | + esc_html__('Primary Contact', 'event_espresso'), |
|
| 887 | + array($this, 'txn_registrant_side_meta_box'), |
|
| 888 | + $this->_wp_page_slug, |
|
| 889 | + 'side', |
|
| 890 | + 'high' |
|
| 891 | + ); |
|
| 892 | + add_meta_box( |
|
| 893 | + 'edit-txn-billing-info-mbox', |
|
| 894 | + esc_html__('Billing Information', 'event_espresso'), |
|
| 895 | + array($this, 'txn_billing_info_side_meta_box'), |
|
| 896 | + $this->_wp_page_slug, |
|
| 897 | + 'side', |
|
| 898 | + 'high' |
|
| 899 | + ); |
|
| 900 | + } |
|
| 901 | + |
|
| 902 | + |
|
| 903 | + /** |
|
| 904 | + * Callback for transaction actions metabox. |
|
| 905 | + * |
|
| 906 | + * @param EE_Transaction|null $transaction |
|
| 907 | + * @return string |
|
| 908 | + * @throws DomainException |
|
| 909 | + * @throws EE_Error |
|
| 910 | + * @throws InvalidArgumentException |
|
| 911 | + * @throws InvalidDataTypeException |
|
| 912 | + * @throws InvalidInterfaceException |
|
| 913 | + * @throws ReflectionException |
|
| 914 | + * @throws RuntimeException |
|
| 915 | + */ |
|
| 916 | + public function getActionButtons(EE_Transaction $transaction = null) |
|
| 917 | + { |
|
| 918 | + $content = ''; |
|
| 919 | + $actions = array(); |
|
| 920 | + if (! $transaction instanceof EE_Transaction) { |
|
| 921 | + return $content; |
|
| 922 | + } |
|
| 923 | + /** @var EE_Registration $primary_registration */ |
|
| 924 | + $primary_registration = $transaction->primary_registration(); |
|
| 925 | + $attendee = $primary_registration instanceof EE_Registration |
|
| 926 | + ? $primary_registration->attendee() |
|
| 927 | + : null; |
|
| 928 | + |
|
| 929 | + if ($attendee instanceof EE_Attendee |
|
| 930 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 931 | + 'ee_send_message', |
|
| 932 | + 'espresso_transactions_send_payment_reminder' |
|
| 933 | + ) |
|
| 934 | + ) { |
|
| 935 | + $actions['payment_reminder'] = |
|
| 936 | + EEH_MSG_Template::is_mt_active('payment_reminder') |
|
| 937 | + && $this->_transaction->status_ID() !== EEM_Transaction::complete_status_code |
|
| 938 | + && $this->_transaction->status_ID() !== EEM_Transaction::overpaid_status_code |
|
| 939 | + ? EEH_Template::get_button_or_link( |
|
| 940 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 941 | + array( |
|
| 942 | + 'action' => 'send_payment_reminder', |
|
| 943 | + 'TXN_ID' => $this->_transaction->ID(), |
|
| 944 | + 'redirect_to' => 'view_transaction', |
|
| 945 | + ), |
|
| 946 | + TXN_ADMIN_URL |
|
| 947 | + ), |
|
| 948 | + esc_html__(' Send Payment Reminder', 'event_espresso'), |
|
| 949 | + 'button secondary-button', |
|
| 950 | + 'dashicons dashicons-email-alt' |
|
| 951 | + ) |
|
| 952 | + : ''; |
|
| 953 | + } |
|
| 954 | + |
|
| 955 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 956 | + 'ee_edit_payments', |
|
| 957 | + 'espresso_transactions_recalculate_line_items' |
|
| 958 | + ) |
|
| 959 | + ) { |
|
| 960 | + $actions['recalculate_line_items'] = EEH_Template::get_button_or_link( |
|
| 961 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 962 | + array( |
|
| 963 | + 'action' => 'espresso_recalculate_line_items', |
|
| 964 | + 'TXN_ID' => $this->_transaction->ID(), |
|
| 965 | + 'redirect_to' => 'view_transaction', |
|
| 966 | + ), |
|
| 967 | + TXN_ADMIN_URL |
|
| 968 | + ), |
|
| 969 | + esc_html__(' Recalculate Taxes and Total', 'event_espresso'), |
|
| 970 | + 'button secondary-button', |
|
| 971 | + 'dashicons dashicons-update' |
|
| 972 | + ); |
|
| 973 | + } |
|
| 974 | + |
|
| 975 | + if ($primary_registration instanceof EE_Registration |
|
| 976 | + && EEH_MSG_Template::is_mt_active('receipt') |
|
| 977 | + ) { |
|
| 978 | + $actions['receipt'] = EEH_Template::get_button_or_link( |
|
| 979 | + $primary_registration->receipt_url(), |
|
| 980 | + esc_html__('View Receipt', 'event_espresso'), |
|
| 981 | + 'button secondary-button', |
|
| 982 | + 'dashicons dashicons-media-default' |
|
| 983 | + ); |
|
| 984 | + } |
|
| 985 | + |
|
| 986 | + if ($primary_registration instanceof EE_Registration |
|
| 987 | + && EEH_MSG_Template::is_mt_active('invoice') |
|
| 988 | + ) { |
|
| 989 | + $actions['invoice'] = EEH_Template::get_button_or_link( |
|
| 990 | + $primary_registration->invoice_url(), |
|
| 991 | + esc_html__('View Invoice', 'event_espresso'), |
|
| 992 | + 'button secondary-button', |
|
| 993 | + 'dashicons dashicons-media-spreadsheet' |
|
| 994 | + ); |
|
| 995 | + } |
|
| 996 | + $actions = array_filter( |
|
| 997 | + apply_filters('FHEE__Transactions_Admin_Page__getActionButtons__actions', $actions, $transaction) |
|
| 998 | + ); |
|
| 999 | + if ($actions) { |
|
| 1000 | + $content = '<ul>'; |
|
| 1001 | + $content .= '<li>' . implode('</li><li>', $actions) . '</li>'; |
|
| 1002 | + $content .= '</uL>'; |
|
| 1003 | + } |
|
| 1004 | + return $content; |
|
| 1005 | + } |
|
| 1006 | + |
|
| 1007 | + |
|
| 1008 | + /** |
|
| 1009 | + * txn_details_meta_box |
|
| 1010 | + * generates HTML for the Transaction main meta box |
|
| 1011 | + * |
|
| 1012 | + * @return void |
|
| 1013 | + * @throws DomainException |
|
| 1014 | + * @throws EE_Error |
|
| 1015 | + * @throws InvalidArgumentException |
|
| 1016 | + * @throws InvalidDataTypeException |
|
| 1017 | + * @throws InvalidInterfaceException |
|
| 1018 | + * @throws RuntimeException |
|
| 1019 | + * @throws ReflectionException |
|
| 1020 | + */ |
|
| 1021 | + public function txn_details_meta_box() |
|
| 1022 | + { |
|
| 1023 | + $this->_set_transaction_object(); |
|
| 1024 | + $this->_template_args['TXN_ID'] = $this->_transaction->ID(); |
|
| 1025 | + $this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration |
|
| 1026 | + ? $this->_transaction->primary_registration()->attendee() |
|
| 1027 | + : null; |
|
| 1028 | + $this->_template_args['can_edit_payments'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 1029 | + 'ee_edit_payments', |
|
| 1030 | + 'apply_payment_or_refund_from_registration_details' |
|
| 1031 | + ); |
|
| 1032 | + $this->_template_args['can_delete_payments'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 1033 | + 'ee_delete_payments', |
|
| 1034 | + 'delete_payment_from_registration_details' |
|
| 1035 | + ); |
|
| 1036 | + |
|
| 1037 | + // get line table |
|
| 1038 | + EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 1039 | + $Line_Item_Display = new EE_Line_Item_Display( |
|
| 1040 | + 'admin_table', |
|
| 1041 | + 'EE_Admin_Table_Line_Item_Display_Strategy' |
|
| 1042 | + ); |
|
| 1043 | + $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item( |
|
| 1044 | + $this->_transaction->total_line_item() |
|
| 1045 | + ); |
|
| 1046 | + $this->_template_args['REG_code'] = $this->_transaction->primary_registration()->reg_code(); |
|
| 1047 | + |
|
| 1048 | + // process taxes |
|
| 1049 | + $taxes = $this->_transaction->line_items(array(array('LIN_type' => EEM_Line_Item::type_tax))); |
|
| 1050 | + $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false; |
|
| 1051 | + |
|
| 1052 | + $this->_template_args['grand_total'] = EEH_Template::format_currency( |
|
| 1053 | + $this->_transaction->total(), |
|
| 1054 | + false, |
|
| 1055 | + false |
|
| 1056 | + ); |
|
| 1057 | + $this->_template_args['grand_raw_total'] = $this->_transaction->total(); |
|
| 1058 | + $this->_template_args['TXN_status'] = $this->_transaction->status_ID(); |
|
| 1059 | + |
|
| 1060 | + // process payment details |
|
| 1061 | + $payments = $this->_transaction->payments(); |
|
| 1062 | + if (! empty($payments)) { |
|
| 1063 | + $this->_template_args['payments'] = $payments; |
|
| 1064 | + $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments); |
|
| 1065 | + } else { |
|
| 1066 | + $this->_template_args['payments'] = false; |
|
| 1067 | + $this->_template_args['existing_reg_payments'] = array(); |
|
| 1068 | + } |
|
| 1069 | + |
|
| 1070 | + $this->_template_args['edit_payment_url'] = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL); |
|
| 1071 | + $this->_template_args['delete_payment_url'] = add_query_arg( |
|
| 1072 | + array('action' => 'espresso_delete_payment'), |
|
| 1073 | + TXN_ADMIN_URL |
|
| 1074 | + ); |
|
| 1075 | + |
|
| 1076 | + if (isset($txn_details['invoice_number'])) { |
|
| 1077 | + $this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code']; |
|
| 1078 | + $this->_template_args['txn_details']['invoice_number']['label'] = esc_html__( |
|
| 1079 | + 'Invoice Number', |
|
| 1080 | + 'event_espresso' |
|
| 1081 | + ); |
|
| 1082 | + } |
|
| 1083 | + |
|
| 1084 | + $this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction |
|
| 1085 | + ->primary_registration() |
|
| 1086 | + ->session_ID(); |
|
| 1087 | + $this->_template_args['txn_details']['registration_session']['label'] = esc_html__( |
|
| 1088 | + 'Registration Session', |
|
| 1089 | + 'event_espresso' |
|
| 1090 | + ); |
|
| 1091 | + |
|
| 1092 | + $this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address']) |
|
| 1093 | + ? $this->_session['ip_address'] |
|
| 1094 | + : ''; |
|
| 1095 | + $this->_template_args['txn_details']['ip_address']['label'] = esc_html__( |
|
| 1096 | + 'Transaction placed from IP', |
|
| 1097 | + 'event_espresso' |
|
| 1098 | + ); |
|
| 1099 | + |
|
| 1100 | + $this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent']) |
|
| 1101 | + ? $this->_session['user_agent'] |
|
| 1102 | + : ''; |
|
| 1103 | + $this->_template_args['txn_details']['user_agent']['label'] = esc_html__( |
|
| 1104 | + 'Registrant User Agent', |
|
| 1105 | + 'event_espresso' |
|
| 1106 | + ); |
|
| 1107 | + |
|
| 1108 | + $reg_steps = '<ul>'; |
|
| 1109 | + foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) { |
|
| 1110 | + if ($reg_step_status === true) { |
|
| 1111 | + $reg_steps .= '<li style="color:#70cc50">' |
|
| 1112 | + . sprintf( |
|
| 1113 | + esc_html__('%1$s : Completed', 'event_espresso'), |
|
| 1114 | + ucwords(str_replace('_', ' ', $reg_step)) |
|
| 1115 | + ) |
|
| 1116 | + . '</li>'; |
|
| 1117 | + } elseif (is_numeric($reg_step_status) && $reg_step_status !== false) { |
|
| 1118 | + $reg_steps .= '<li style="color:#2EA2CC">' |
|
| 1119 | + . sprintf( |
|
| 1120 | + esc_html__('%1$s : Initiated %2$s', 'event_espresso'), |
|
| 1121 | + ucwords(str_replace('_', ' ', $reg_step)), |
|
| 1122 | + date( |
|
| 1123 | + get_option('date_format') . ' ' . get_option('time_format'), |
|
| 1124 | + $reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
| 1125 | + ) |
|
| 1126 | + ) |
|
| 1127 | + . '</li>'; |
|
| 1128 | + } else { |
|
| 1129 | + $reg_steps .= '<li style="color:#E76700">' |
|
| 1130 | + . sprintf( |
|
| 1131 | + esc_html__('%1$s : Never Initiated', 'event_espresso'), |
|
| 1132 | + ucwords(str_replace('_', ' ', $reg_step)) |
|
| 1133 | + ) |
|
| 1134 | + . '</li>'; |
|
| 1135 | + } |
|
| 1136 | + } |
|
| 1137 | + $reg_steps .= '</ul>'; |
|
| 1138 | + $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps; |
|
| 1139 | + $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__( |
|
| 1140 | + 'Registration Step Progress', |
|
| 1141 | + 'event_espresso' |
|
| 1142 | + ); |
|
| 1143 | + |
|
| 1144 | + |
|
| 1145 | + $this->_get_registrations_to_apply_payment_to(); |
|
| 1146 | + $this->_get_payment_methods($payments); |
|
| 1147 | + $this->_get_payment_status_array(); |
|
| 1148 | + $this->_get_reg_status_selection(); // sets up the template args for the reg status array for the transaction. |
|
| 1149 | + |
|
| 1150 | + $this->_template_args['transaction_form_url'] = add_query_arg( |
|
| 1151 | + array( |
|
| 1152 | + 'action' => 'edit_transaction', |
|
| 1153 | + 'process' => 'transaction', |
|
| 1154 | + ), |
|
| 1155 | + TXN_ADMIN_URL |
|
| 1156 | + ); |
|
| 1157 | + $this->_template_args['apply_payment_form_url'] = add_query_arg( |
|
| 1158 | + array( |
|
| 1159 | + 'page' => 'espresso_transactions', |
|
| 1160 | + 'action' => 'espresso_apply_payment', |
|
| 1161 | + ), |
|
| 1162 | + WP_AJAX_URL |
|
| 1163 | + ); |
|
| 1164 | + $this->_template_args['delete_payment_form_url'] = add_query_arg( |
|
| 1165 | + array( |
|
| 1166 | + 'page' => 'espresso_transactions', |
|
| 1167 | + 'action' => 'espresso_delete_payment', |
|
| 1168 | + ), |
|
| 1169 | + WP_AJAX_URL |
|
| 1170 | + ); |
|
| 1171 | + |
|
| 1172 | + $this->_template_args['action_buttons'] = $this->getActionButtons($this->_transaction); |
|
| 1173 | + |
|
| 1174 | + // 'espresso_delete_payment_nonce' |
|
| 1175 | + |
|
| 1176 | + $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
| 1177 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 1178 | + } |
|
| 1179 | + |
|
| 1180 | + |
|
| 1181 | + /** |
|
| 1182 | + * _get_registration_payment_IDs |
|
| 1183 | + * generates an array of Payment IDs and their corresponding Registration IDs |
|
| 1184 | + * |
|
| 1185 | + * @access protected |
|
| 1186 | + * @param EE_Payment[] $payments |
|
| 1187 | + * @return array |
|
| 1188 | + * @throws EE_Error |
|
| 1189 | + * @throws InvalidArgumentException |
|
| 1190 | + * @throws InvalidDataTypeException |
|
| 1191 | + * @throws InvalidInterfaceException |
|
| 1192 | + * @throws ReflectionException |
|
| 1193 | + */ |
|
| 1194 | + protected function _get_registration_payment_IDs($payments = array()) |
|
| 1195 | + { |
|
| 1196 | + $existing_reg_payments = array(); |
|
| 1197 | + // get all reg payments for these payments |
|
| 1198 | + $reg_payments = EEM_Registration_Payment::instance()->get_all( |
|
| 1199 | + array( |
|
| 1200 | + array( |
|
| 1201 | + 'PAY_ID' => array( |
|
| 1202 | + 'IN', |
|
| 1203 | + array_keys($payments), |
|
| 1204 | + ), |
|
| 1205 | + ), |
|
| 1206 | + ) |
|
| 1207 | + ); |
|
| 1208 | + if (! empty($reg_payments)) { |
|
| 1209 | + foreach ($payments as $payment) { |
|
| 1210 | + if (! $payment instanceof EE_Payment) { |
|
| 1211 | + continue; |
|
| 1212 | + } elseif (! isset($existing_reg_payments[ $payment->ID() ])) { |
|
| 1213 | + $existing_reg_payments[ $payment->ID() ] = array(); |
|
| 1214 | + } |
|
| 1215 | + foreach ($reg_payments as $reg_payment) { |
|
| 1216 | + if ($reg_payment instanceof EE_Registration_Payment |
|
| 1217 | + && $reg_payment->payment_ID() === $payment->ID() |
|
| 1218 | + ) { |
|
| 1219 | + $existing_reg_payments[ $payment->ID() ][] = $reg_payment->registration_ID(); |
|
| 1220 | + } |
|
| 1221 | + } |
|
| 1222 | + } |
|
| 1223 | + } |
|
| 1224 | + |
|
| 1225 | + return $existing_reg_payments; |
|
| 1226 | + } |
|
| 1227 | + |
|
| 1228 | + |
|
| 1229 | + /** |
|
| 1230 | + * _get_registrations_to_apply_payment_to |
|
| 1231 | + * generates HTML for displaying a series of checkboxes in the admin payment modal window |
|
| 1232 | + * which allows the admin to only apply the payment to the specific registrations |
|
| 1233 | + * |
|
| 1234 | + * @access protected |
|
| 1235 | + * @return void |
|
| 1236 | + * @throws EE_Error |
|
| 1237 | + * @throws InvalidArgumentException |
|
| 1238 | + * @throws InvalidDataTypeException |
|
| 1239 | + * @throws InvalidInterfaceException |
|
| 1240 | + * @throws ReflectionException |
|
| 1241 | + */ |
|
| 1242 | + protected function _get_registrations_to_apply_payment_to() |
|
| 1243 | + { |
|
| 1244 | + // we want any registration with an active status (ie: not deleted or cancelled) |
|
| 1245 | + $query_params = array( |
|
| 1246 | + array( |
|
| 1247 | + 'STS_ID' => array( |
|
| 1248 | + 'IN', |
|
| 1249 | + array( |
|
| 1250 | + EEM_Registration::status_id_approved, |
|
| 1251 | + EEM_Registration::status_id_pending_payment, |
|
| 1252 | + EEM_Registration::status_id_not_approved, |
|
| 1253 | + ), |
|
| 1254 | + ), |
|
| 1255 | + ), |
|
| 1256 | + ); |
|
| 1257 | + $registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div( |
|
| 1258 | + '', |
|
| 1259 | + 'txn-admin-apply-payment-to-registrations-dv', |
|
| 1260 | + '', |
|
| 1261 | + 'clear: both; margin: 1.5em 0 0; display: none;' |
|
| 1262 | + ); |
|
| 1263 | + $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
| 1264 | + $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl'); |
|
| 1265 | + $registrations_to_apply_payment_to .= EEH_HTML::thead( |
|
| 1266 | + EEH_HTML::tr( |
|
| 1267 | + EEH_HTML::th(esc_html__('ID', 'event_espresso')) . |
|
| 1268 | + EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) . |
|
| 1269 | + EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) . |
|
| 1270 | + EEH_HTML::th(esc_html__('Event', 'event_espresso')) . |
|
| 1271 | + EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 1272 | + EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
| 1273 | + EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr') |
|
| 1274 | + ) |
|
| 1275 | + ); |
|
| 1276 | + $registrations_to_apply_payment_to .= EEH_HTML::tbody(); |
|
| 1277 | + // get registrations for TXN |
|
| 1278 | + $registrations = $this->_transaction->registrations($query_params); |
|
| 1279 | + $existing_reg_payments = $this->_template_args['existing_reg_payments']; |
|
| 1280 | + foreach ($registrations as $registration) { |
|
| 1281 | + if ($registration instanceof EE_Registration) { |
|
| 1282 | + $attendee_name = $registration->attendee() instanceof EE_Attendee |
|
| 1283 | + ? $registration->attendee()->full_name() |
|
| 1284 | + : esc_html__('Unknown Attendee', 'event_espresso'); |
|
| 1285 | + $owing = $registration->final_price() - $registration->paid(); |
|
| 1286 | + $taxable = $registration->ticket()->taxable() |
|
| 1287 | + ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>' |
|
| 1288 | + : ''; |
|
| 1289 | + $checked = empty($existing_reg_payments) |
|
| 1290 | + || in_array($registration->ID(), $existing_reg_payments, true) |
|
| 1291 | + ? ' checked="checked"' |
|
| 1292 | + : ''; |
|
| 1293 | + $disabled = $registration->final_price() > 0 ? '' : ' disabled'; |
|
| 1294 | + $registrations_to_apply_payment_to .= EEH_HTML::tr( |
|
| 1295 | + EEH_HTML::td($registration->ID()) . |
|
| 1296 | + EEH_HTML::td($attendee_name) . |
|
| 1297 | + EEH_HTML::td( |
|
| 1298 | + $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable |
|
| 1299 | + ) . |
|
| 1300 | + EEH_HTML::td($registration->event_name()) . |
|
| 1301 | + EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 1302 | + EEH_HTML::td( |
|
| 1303 | + EEH_Template::format_currency($owing), |
|
| 1304 | + '', |
|
| 1305 | + 'txn-admin-payment-owing-td jst-cntr' |
|
| 1306 | + ) . |
|
| 1307 | + EEH_HTML::td( |
|
| 1308 | + '<input type="checkbox" value="' . $registration->ID() |
|
| 1309 | + . '" name="txn_admin_payment[registrations]"' |
|
| 1310 | + . $checked . $disabled . '>', |
|
| 1311 | + '', |
|
| 1312 | + 'jst-cntr' |
|
| 1313 | + ), |
|
| 1314 | + 'apply-payment-registration-row-' . $registration->ID() |
|
| 1315 | + ); |
|
| 1316 | + } |
|
| 1317 | + } |
|
| 1318 | + $registrations_to_apply_payment_to .= EEH_HTML::tbodyx(); |
|
| 1319 | + $registrations_to_apply_payment_to .= EEH_HTML::tablex(); |
|
| 1320 | + $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1321 | + $registrations_to_apply_payment_to .= EEH_HTML::p( |
|
| 1322 | + esc_html__( |
|
| 1323 | + 'The payment will only be applied to the registrations that have a check mark in their corresponding check box. Checkboxes for free registrations have been disabled.', |
|
| 1324 | + 'event_espresso' |
|
| 1325 | + ), |
|
| 1326 | + '', |
|
| 1327 | + 'clear description' |
|
| 1328 | + ); |
|
| 1329 | + $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1330 | + $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to; |
|
| 1331 | + } |
|
| 1332 | + |
|
| 1333 | + |
|
| 1334 | + /** |
|
| 1335 | + * _get_reg_status_selection |
|
| 1336 | + * |
|
| 1337 | + * @todo this will need to be adjusted either once MER comes along OR we move default reg status to tickets |
|
| 1338 | + * instead of events. |
|
| 1339 | + * @access protected |
|
| 1340 | + * @return void |
|
| 1341 | + * @throws EE_Error |
|
| 1342 | + */ |
|
| 1343 | + protected function _get_reg_status_selection() |
|
| 1344 | + { |
|
| 1345 | + // first get all possible statuses |
|
| 1346 | + $statuses = EEM_Registration::reg_status_array(array(), true); |
|
| 1347 | + // let's add a "don't change" option. |
|
| 1348 | + $status_array['NAN'] = esc_html__('Leave the Same', 'event_espresso'); |
|
| 1349 | + $status_array = array_merge($status_array, $statuses); |
|
| 1350 | + $this->_template_args['status_change_select'] = EEH_Form_Fields::select_input( |
|
| 1351 | + 'txn_reg_status_change[reg_status]', |
|
| 1352 | + $status_array, |
|
| 1353 | + 'NAN', |
|
| 1354 | + 'id="txn-admin-payment-reg-status-inp"', |
|
| 1355 | + 'txn-reg-status-change-reg-status' |
|
| 1356 | + ); |
|
| 1357 | + $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input( |
|
| 1358 | + 'delete_txn_reg_status_change[reg_status]', |
|
| 1359 | + $status_array, |
|
| 1360 | + 'NAN', |
|
| 1361 | + 'delete-txn-admin-payment-reg-status-inp', |
|
| 1362 | + 'delete-txn-reg-status-change-reg-status' |
|
| 1363 | + ); |
|
| 1364 | + } |
|
| 1365 | + |
|
| 1366 | + |
|
| 1367 | + /** |
|
| 1368 | + * _get_payment_methods |
|
| 1369 | + * Gets all the payment methods available generally, or the ones that are already |
|
| 1370 | + * selected on these payments (in case their payment methods are no longer active). |
|
| 1371 | + * Has the side-effect of updating the template args' payment_methods item |
|
| 1372 | + * |
|
| 1373 | + * @access private |
|
| 1374 | + * @param EE_Payment[] to show on this page |
|
| 1375 | + * @return void |
|
| 1376 | + * @throws EE_Error |
|
| 1377 | + * @throws InvalidArgumentException |
|
| 1378 | + * @throws InvalidDataTypeException |
|
| 1379 | + * @throws InvalidInterfaceException |
|
| 1380 | + * @throws ReflectionException |
|
| 1381 | + */ |
|
| 1382 | + private function _get_payment_methods($payments = array()) |
|
| 1383 | + { |
|
| 1384 | + $payment_methods_of_payments = array(); |
|
| 1385 | + foreach ($payments as $payment) { |
|
| 1386 | + if ($payment instanceof EE_Payment) { |
|
| 1387 | + $payment_methods_of_payments[] = $payment->ID(); |
|
| 1388 | + } |
|
| 1389 | + } |
|
| 1390 | + if ($payment_methods_of_payments) { |
|
| 1391 | + $query_args = array( |
|
| 1392 | + array( |
|
| 1393 | + 'OR*payment_method_for_payment' => array( |
|
| 1394 | + 'PMD_ID' => array('IN', $payment_methods_of_payments), |
|
| 1395 | + 'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'), |
|
| 1396 | + ), |
|
| 1397 | + ), |
|
| 1398 | + ); |
|
| 1399 | + } else { |
|
| 1400 | + $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'))); |
|
| 1401 | + } |
|
| 1402 | + $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args); |
|
| 1403 | + } |
|
| 1404 | + |
|
| 1405 | + |
|
| 1406 | + /** |
|
| 1407 | + * txn_attendees_meta_box |
|
| 1408 | + * generates HTML for the Attendees Transaction main meta box |
|
| 1409 | + * |
|
| 1410 | + * @access public |
|
| 1411 | + * @param WP_Post $post |
|
| 1412 | + * @param array $metabox |
|
| 1413 | + * @return void |
|
| 1414 | + * @throws DomainException |
|
| 1415 | + * @throws EE_Error |
|
| 1416 | + * @throws InvalidArgumentException |
|
| 1417 | + * @throws InvalidDataTypeException |
|
| 1418 | + * @throws InvalidInterfaceException |
|
| 1419 | + * @throws ReflectionException |
|
| 1420 | + */ |
|
| 1421 | + public function txn_attendees_meta_box($post, $metabox = array('args' => array())) |
|
| 1422 | + { |
|
| 1423 | + |
|
| 1424 | + /** @noinspection NonSecureExtractUsageInspection */ |
|
| 1425 | + extract($metabox['args']); |
|
| 1426 | + $this->_template_args['post'] = $post; |
|
| 1427 | + $this->_template_args['event_attendees'] = array(); |
|
| 1428 | + // process items in cart |
|
| 1429 | + $line_items = $this->_transaction->get_many_related( |
|
| 1430 | + 'Line_Item', |
|
| 1431 | + array(array('LIN_type' => 'line-item')) |
|
| 1432 | + ); |
|
| 1433 | + if (! empty($line_items)) { |
|
| 1434 | + foreach ($line_items as $item) { |
|
| 1435 | + if ($item instanceof EE_Line_Item) { |
|
| 1436 | + switch ($item->OBJ_type()) { |
|
| 1437 | + case 'Event': |
|
| 1438 | + break; |
|
| 1439 | + case 'Ticket': |
|
| 1440 | + $ticket = $item->ticket(); |
|
| 1441 | + // right now we're only handling tickets here. |
|
| 1442 | + // Cause its expected that only tickets will have attendees right? |
|
| 1443 | + if (! $ticket instanceof EE_Ticket) { |
|
| 1444 | + break; |
|
| 1445 | + } |
|
| 1446 | + try { |
|
| 1447 | + $event_name = $ticket->get_event_name(); |
|
| 1448 | + } catch (Exception $e) { |
|
| 1449 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1450 | + $event_name = esc_html__('Unknown Event', 'event_espresso'); |
|
| 1451 | + } |
|
| 1452 | + $event_name .= ' - ' . $item->name(); |
|
| 1453 | + $ticket_price = EEH_Template::format_currency($item->unit_price()); |
|
| 1454 | + // now get all of the registrations for this transaction that use this ticket |
|
| 1455 | + $registrations = $ticket->registrations( |
|
| 1456 | + array(array('TXN_ID' => $this->_transaction->ID())) |
|
| 1457 | + ); |
|
| 1458 | + foreach ($registrations as $registration) { |
|
| 1459 | + if (! $registration instanceof EE_Registration) { |
|
| 1460 | + break; |
|
| 1461 | + } |
|
| 1462 | + $this->_template_args['event_attendees'][ $registration->ID() ]['STS_ID'] |
|
| 1463 | + = $registration->status_ID(); |
|
| 1464 | + $this->_template_args['event_attendees'][ $registration->ID() ]['att_num'] |
|
| 1465 | + = $registration->count(); |
|
| 1466 | + $this->_template_args['event_attendees'][ $registration->ID() ]['event_ticket_name'] |
|
| 1467 | + = $event_name; |
|
| 1468 | + $this->_template_args['event_attendees'][ $registration->ID() ]['ticket_price'] |
|
| 1469 | + = $ticket_price; |
|
| 1470 | + // attendee info |
|
| 1471 | + $attendee = $registration->get_first_related('Attendee'); |
|
| 1472 | + if ($attendee instanceof EE_Attendee) { |
|
| 1473 | + $this->_template_args['event_attendees'][ $registration->ID() ]['att_id'] |
|
| 1474 | + = $attendee->ID(); |
|
| 1475 | + $this->_template_args['event_attendees'][ $registration->ID() ]['attendee'] |
|
| 1476 | + = $attendee->full_name(); |
|
| 1477 | + $this->_template_args['event_attendees'][ $registration->ID() ]['email'] |
|
| 1478 | + = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name |
|
| 1479 | + . esc_html__( |
|
| 1480 | + ' Event', |
|
| 1481 | + 'event_espresso' |
|
| 1482 | + ) |
|
| 1483 | + . '">' . $attendee->email() . '</a>'; |
|
| 1484 | + $this->_template_args['event_attendees'][ $registration->ID() ]['address'] |
|
| 1485 | + = EEH_Address::format($attendee, 'inline', false, false); |
|
| 1486 | + } else { |
|
| 1487 | + $this->_template_args['event_attendees'][ $registration->ID() ]['att_id'] = ''; |
|
| 1488 | + $this->_template_args['event_attendees'][ $registration->ID() ]['attendee'] = ''; |
|
| 1489 | + $this->_template_args['event_attendees'][ $registration->ID() ]['email'] = ''; |
|
| 1490 | + $this->_template_args['event_attendees'][ $registration->ID() ]['address'] = ''; |
|
| 1491 | + } |
|
| 1492 | + } |
|
| 1493 | + break; |
|
| 1494 | + } |
|
| 1495 | + } |
|
| 1496 | + } |
|
| 1497 | + |
|
| 1498 | + $this->_template_args['transaction_form_url'] = add_query_arg( |
|
| 1499 | + array( |
|
| 1500 | + 'action' => 'edit_transaction', |
|
| 1501 | + 'process' => 'attendees', |
|
| 1502 | + ), |
|
| 1503 | + TXN_ADMIN_URL |
|
| 1504 | + ); |
|
| 1505 | + echo EEH_Template::display_template( |
|
| 1506 | + TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php', |
|
| 1507 | + $this->_template_args, |
|
| 1508 | + true |
|
| 1509 | + ); |
|
| 1510 | + } else { |
|
| 1511 | + echo sprintf( |
|
| 1512 | + esc_html__( |
|
| 1513 | + '%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s', |
|
| 1514 | + 'event_espresso' |
|
| 1515 | + ), |
|
| 1516 | + '<p class="important-notice">', |
|
| 1517 | + '</p>' |
|
| 1518 | + ); |
|
| 1519 | + } |
|
| 1520 | + } |
|
| 1521 | + |
|
| 1522 | + |
|
| 1523 | + /** |
|
| 1524 | + * txn_registrant_side_meta_box |
|
| 1525 | + * generates HTML for the Edit Transaction side meta box |
|
| 1526 | + * |
|
| 1527 | + * @access public |
|
| 1528 | + * @return void |
|
| 1529 | + * @throws DomainException |
|
| 1530 | + * @throws EE_Error |
|
| 1531 | + * @throws InvalidArgumentException |
|
| 1532 | + * @throws InvalidDataTypeException |
|
| 1533 | + * @throws InvalidInterfaceException |
|
| 1534 | + * @throws ReflectionException |
|
| 1535 | + */ |
|
| 1536 | + public function txn_registrant_side_meta_box() |
|
| 1537 | + { |
|
| 1538 | + $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration |
|
| 1539 | + ? $this->_transaction->primary_registration()->get_first_related('Attendee') |
|
| 1540 | + : null; |
|
| 1541 | + if (! $primary_att instanceof EE_Attendee) { |
|
| 1542 | + $this->_template_args['no_attendee_message'] = esc_html__( |
|
| 1543 | + 'There is no attached contact for this transaction. The transaction either failed due to an error or was abandoned.', |
|
| 1544 | + 'event_espresso' |
|
| 1545 | + ); |
|
| 1546 | + $primary_att = EEM_Attendee::instance()->create_default_object(); |
|
| 1547 | + } |
|
| 1548 | + $this->_template_args['ATT_ID'] = $primary_att->ID(); |
|
| 1549 | + $this->_template_args['prime_reg_fname'] = $primary_att->fname(); |
|
| 1550 | + $this->_template_args['prime_reg_lname'] = $primary_att->lname(); |
|
| 1551 | + $this->_template_args['prime_reg_email'] = $primary_att->email(); |
|
| 1552 | + $this->_template_args['prime_reg_phone'] = $primary_att->phone(); |
|
| 1553 | + $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1554 | + array( |
|
| 1555 | + 'action' => 'edit_attendee', |
|
| 1556 | + 'post' => $primary_att->ID(), |
|
| 1557 | + ), |
|
| 1558 | + REG_ADMIN_URL |
|
| 1559 | + ); |
|
| 1560 | + // get formatted address for registrant |
|
| 1561 | + $this->_template_args['formatted_address'] = EEH_Address::format($primary_att); |
|
| 1562 | + echo EEH_Template::display_template( |
|
| 1563 | + TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php', |
|
| 1564 | + $this->_template_args, |
|
| 1565 | + true |
|
| 1566 | + ); |
|
| 1567 | + } |
|
| 1568 | + |
|
| 1569 | + |
|
| 1570 | + /** |
|
| 1571 | + * txn_billing_info_side_meta_box |
|
| 1572 | + * generates HTML for the Edit Transaction side meta box |
|
| 1573 | + * |
|
| 1574 | + * @access public |
|
| 1575 | + * @return void |
|
| 1576 | + * @throws DomainException |
|
| 1577 | + * @throws EE_Error |
|
| 1578 | + */ |
|
| 1579 | + public function txn_billing_info_side_meta_box() |
|
| 1580 | + { |
|
| 1581 | + |
|
| 1582 | + $this->_template_args['billing_form'] = $this->_transaction->billing_info(); |
|
| 1583 | + $this->_template_args['billing_form_url'] = add_query_arg( |
|
| 1584 | + array('action' => 'edit_transaction', 'process' => 'billing'), |
|
| 1585 | + TXN_ADMIN_URL |
|
| 1586 | + ); |
|
| 1587 | + |
|
| 1588 | + $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
| 1589 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 1590 | + } |
|
| 1591 | + |
|
| 1592 | + |
|
| 1593 | + /** |
|
| 1594 | + * apply_payments_or_refunds |
|
| 1595 | + * registers a payment or refund made towards a transaction |
|
| 1596 | + * |
|
| 1597 | + * @access public |
|
| 1598 | + * @return void |
|
| 1599 | + * @throws EE_Error |
|
| 1600 | + * @throws InvalidArgumentException |
|
| 1601 | + * @throws ReflectionException |
|
| 1602 | + * @throws RuntimeException |
|
| 1603 | + * @throws InvalidDataTypeException |
|
| 1604 | + * @throws InvalidInterfaceException |
|
| 1605 | + */ |
|
| 1606 | + public function apply_payments_or_refunds() |
|
| 1607 | + { |
|
| 1608 | + $json_response_data = array('return_data' => false); |
|
| 1609 | + $valid_data = $this->_validate_payment_request_data(); |
|
| 1610 | + $has_access = EE_Registry::instance()->CAP->current_user_can( |
|
| 1611 | + 'ee_edit_payments', |
|
| 1612 | + 'apply_payment_or_refund_from_registration_details' |
|
| 1613 | + ); |
|
| 1614 | + if (! empty($valid_data) && $has_access) { |
|
| 1615 | + $PAY_ID = $valid_data['PAY_ID']; |
|
| 1616 | + // save the new payment |
|
| 1617 | + $payment = $this->_create_payment_from_request_data($valid_data); |
|
| 1618 | + // get the TXN for this payment |
|
| 1619 | + $transaction = $payment->transaction(); |
|
| 1620 | + // verify transaction |
|
| 1621 | + if ($transaction instanceof EE_Transaction) { |
|
| 1622 | + // calculate_total_payments_and_update_status |
|
| 1623 | + $this->_process_transaction_payments($transaction); |
|
| 1624 | + $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment); |
|
| 1625 | + $this->_remove_existing_registration_payments($payment, $PAY_ID); |
|
| 1626 | + // apply payment to registrations (if applicable) |
|
| 1627 | + if (! empty($REG_IDs)) { |
|
| 1628 | + $this->_update_registration_payments($transaction, $payment, $REG_IDs); |
|
| 1629 | + $this->_maybe_send_notifications(); |
|
| 1630 | + // now process status changes for the same registrations |
|
| 1631 | + $this->_process_registration_status_change($transaction, $REG_IDs); |
|
| 1632 | + } |
|
| 1633 | + $this->_maybe_send_notifications($payment); |
|
| 1634 | + // prepare to render page |
|
| 1635 | + $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs); |
|
| 1636 | + do_action( |
|
| 1637 | + 'AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording', |
|
| 1638 | + $transaction, |
|
| 1639 | + $payment |
|
| 1640 | + ); |
|
| 1641 | + } else { |
|
| 1642 | + EE_Error::add_error( |
|
| 1643 | + esc_html__( |
|
| 1644 | + 'A valid Transaction for this payment could not be retrieved.', |
|
| 1645 | + 'event_espresso' |
|
| 1646 | + ), |
|
| 1647 | + __FILE__, |
|
| 1648 | + __FUNCTION__, |
|
| 1649 | + __LINE__ |
|
| 1650 | + ); |
|
| 1651 | + } |
|
| 1652 | + } elseif ($has_access) { |
|
| 1653 | + EE_Error::add_error( |
|
| 1654 | + esc_html__( |
|
| 1655 | + 'The payment form data could not be processed. Please try again.', |
|
| 1656 | + 'event_espresso' |
|
| 1657 | + ), |
|
| 1658 | + __FILE__, |
|
| 1659 | + __FUNCTION__, |
|
| 1660 | + __LINE__ |
|
| 1661 | + ); |
|
| 1662 | + } else { |
|
| 1663 | + EE_Error::add_error( |
|
| 1664 | + esc_html__( |
|
| 1665 | + 'You do not have access to apply payments or refunds to a registration.', |
|
| 1666 | + 'event_espresso' |
|
| 1667 | + ), |
|
| 1668 | + __FILE__, |
|
| 1669 | + __FUNCTION__, |
|
| 1670 | + __LINE__ |
|
| 1671 | + ); |
|
| 1672 | + } |
|
| 1673 | + $notices = EE_Error::get_notices( |
|
| 1674 | + false, |
|
| 1675 | + false, |
|
| 1676 | + false |
|
| 1677 | + ); |
|
| 1678 | + $this->_template_args = array( |
|
| 1679 | + 'data' => $json_response_data, |
|
| 1680 | + 'error' => $notices['errors'], |
|
| 1681 | + 'success' => $notices['success'], |
|
| 1682 | + ); |
|
| 1683 | + $this->_return_json(); |
|
| 1684 | + } |
|
| 1685 | + |
|
| 1686 | + |
|
| 1687 | + /** |
|
| 1688 | + * _validate_payment_request_data |
|
| 1689 | + * |
|
| 1690 | + * @return array |
|
| 1691 | + * @throws EE_Error |
|
| 1692 | + * @throws InvalidArgumentException |
|
| 1693 | + * @throws InvalidDataTypeException |
|
| 1694 | + * @throws InvalidInterfaceException |
|
| 1695 | + */ |
|
| 1696 | + protected function _validate_payment_request_data() |
|
| 1697 | + { |
|
| 1698 | + if (! isset($this->_req_data['txn_admin_payment'])) { |
|
| 1699 | + return array(); |
|
| 1700 | + } |
|
| 1701 | + $payment_form = $this->_generate_payment_form_section(); |
|
| 1702 | + try { |
|
| 1703 | + if ($payment_form->was_submitted()) { |
|
| 1704 | + $payment_form->receive_form_submission(); |
|
| 1705 | + if (! $payment_form->is_valid()) { |
|
| 1706 | + $submission_error_messages = array(); |
|
| 1707 | + foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) { |
|
| 1708 | + if ($validation_error instanceof EE_Validation_Error) { |
|
| 1709 | + $submission_error_messages[] = sprintf( |
|
| 1710 | + _x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'), |
|
| 1711 | + $validation_error->get_form_section()->html_label_text(), |
|
| 1712 | + $validation_error->getMessage() |
|
| 1713 | + ); |
|
| 1714 | + } |
|
| 1715 | + } |
|
| 1716 | + EE_Error::add_error( |
|
| 1717 | + implode('<br />', $submission_error_messages), |
|
| 1718 | + __FILE__, |
|
| 1719 | + __FUNCTION__, |
|
| 1720 | + __LINE__ |
|
| 1721 | + ); |
|
| 1722 | + return array(); |
|
| 1723 | + } |
|
| 1724 | + } |
|
| 1725 | + } catch (EE_Error $e) { |
|
| 1726 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1727 | + return array(); |
|
| 1728 | + } |
|
| 1729 | + |
|
| 1730 | + return $payment_form->valid_data(); |
|
| 1731 | + } |
|
| 1732 | + |
|
| 1733 | + |
|
| 1734 | + /** |
|
| 1735 | + * _generate_payment_form_section |
|
| 1736 | + * |
|
| 1737 | + * @return EE_Form_Section_Proper |
|
| 1738 | + * @throws EE_Error |
|
| 1739 | + */ |
|
| 1740 | + protected function _generate_payment_form_section() |
|
| 1741 | + { |
|
| 1742 | + return new EE_Form_Section_Proper( |
|
| 1743 | + array( |
|
| 1744 | + 'name' => 'txn_admin_payment', |
|
| 1745 | + 'subsections' => array( |
|
| 1746 | + 'PAY_ID' => new EE_Text_Input( |
|
| 1747 | + array( |
|
| 1748 | + 'default' => 0, |
|
| 1749 | + 'required' => false, |
|
| 1750 | + 'html_label_text' => esc_html__('Payment ID', 'event_espresso'), |
|
| 1751 | + 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1752 | + ) |
|
| 1753 | + ), |
|
| 1754 | + 'TXN_ID' => new EE_Text_Input( |
|
| 1755 | + array( |
|
| 1756 | + 'default' => 0, |
|
| 1757 | + 'required' => true, |
|
| 1758 | + 'html_label_text' => esc_html__('Transaction ID', 'event_espresso'), |
|
| 1759 | + 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1760 | + ) |
|
| 1761 | + ), |
|
| 1762 | + 'type' => new EE_Text_Input( |
|
| 1763 | + array( |
|
| 1764 | + 'default' => 1, |
|
| 1765 | + 'required' => true, |
|
| 1766 | + 'html_label_text' => esc_html__('Payment or Refund', 'event_espresso'), |
|
| 1767 | + 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1768 | + ) |
|
| 1769 | + ), |
|
| 1770 | + 'amount' => new EE_Text_Input( |
|
| 1771 | + array( |
|
| 1772 | + 'default' => 0, |
|
| 1773 | + 'required' => true, |
|
| 1774 | + 'html_label_text' => esc_html__('Payment amount', 'event_espresso'), |
|
| 1775 | + 'validation_strategies' => array(new EE_Float_Normalization()), |
|
| 1776 | + ) |
|
| 1777 | + ), |
|
| 1778 | + 'status' => new EE_Text_Input( |
|
| 1779 | + array( |
|
| 1780 | + 'default' => EEM_Payment::status_id_approved, |
|
| 1781 | + 'required' => true, |
|
| 1782 | + 'html_label_text' => esc_html__('Payment status', 'event_espresso'), |
|
| 1783 | + ) |
|
| 1784 | + ), |
|
| 1785 | + 'PMD_ID' => new EE_Text_Input( |
|
| 1786 | + array( |
|
| 1787 | + 'default' => 2, |
|
| 1788 | + 'required' => true, |
|
| 1789 | + 'html_label_text' => esc_html__('Payment Method', 'event_espresso'), |
|
| 1790 | + 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1791 | + ) |
|
| 1792 | + ), |
|
| 1793 | + 'date' => new EE_Text_Input( |
|
| 1794 | + array( |
|
| 1795 | + 'default' => time(), |
|
| 1796 | + 'required' => true, |
|
| 1797 | + 'html_label_text' => esc_html__('Payment date', 'event_espresso'), |
|
| 1798 | + ) |
|
| 1799 | + ), |
|
| 1800 | + 'txn_id_chq_nmbr' => new EE_Text_Input( |
|
| 1801 | + array( |
|
| 1802 | + 'default' => '', |
|
| 1803 | + 'required' => false, |
|
| 1804 | + 'html_label_text' => esc_html__('Transaction or Cheque Number', 'event_espresso'), |
|
| 1805 | + 'validation_strategies' => array( |
|
| 1806 | + new EE_Max_Length_Validation_Strategy( |
|
| 1807 | + esc_html__('Input too long', 'event_espresso'), |
|
| 1808 | + 100 |
|
| 1809 | + ), |
|
| 1810 | + ), |
|
| 1811 | + ) |
|
| 1812 | + ), |
|
| 1813 | + 'po_number' => new EE_Text_Input( |
|
| 1814 | + array( |
|
| 1815 | + 'default' => '', |
|
| 1816 | + 'required' => false, |
|
| 1817 | + 'html_label_text' => esc_html__('Purchase Order Number', 'event_espresso'), |
|
| 1818 | + 'validation_strategies' => array( |
|
| 1819 | + new EE_Max_Length_Validation_Strategy( |
|
| 1820 | + esc_html__('Input too long', 'event_espresso'), |
|
| 1821 | + 100 |
|
| 1822 | + ), |
|
| 1823 | + ), |
|
| 1824 | + ) |
|
| 1825 | + ), |
|
| 1826 | + 'accounting' => new EE_Text_Input( |
|
| 1827 | + array( |
|
| 1828 | + 'default' => '', |
|
| 1829 | + 'required' => false, |
|
| 1830 | + 'html_label_text' => esc_html__('Extra Field for Accounting', 'event_espresso'), |
|
| 1831 | + 'validation_strategies' => array( |
|
| 1832 | + new EE_Max_Length_Validation_Strategy( |
|
| 1833 | + esc_html__('Input too long', 'event_espresso'), |
|
| 1834 | + 100 |
|
| 1835 | + ), |
|
| 1836 | + ), |
|
| 1837 | + ) |
|
| 1838 | + ), |
|
| 1839 | + ), |
|
| 1840 | + ) |
|
| 1841 | + ); |
|
| 1842 | + } |
|
| 1843 | + |
|
| 1844 | + |
|
| 1845 | + /** |
|
| 1846 | + * _create_payment_from_request_data |
|
| 1847 | + * |
|
| 1848 | + * @param array $valid_data |
|
| 1849 | + * @return EE_Payment |
|
| 1850 | + * @throws EE_Error |
|
| 1851 | + * @throws InvalidArgumentException |
|
| 1852 | + * @throws InvalidDataTypeException |
|
| 1853 | + * @throws InvalidInterfaceException |
|
| 1854 | + * @throws ReflectionException |
|
| 1855 | + */ |
|
| 1856 | + protected function _create_payment_from_request_data($valid_data) |
|
| 1857 | + { |
|
| 1858 | + $PAY_ID = $valid_data['PAY_ID']; |
|
| 1859 | + // get payment amount |
|
| 1860 | + $amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0; |
|
| 1861 | + // payments have a type value of 1 and refunds have a type value of -1 |
|
| 1862 | + // so multiplying amount by type will give a positive value for payments, and negative values for refunds |
|
| 1863 | + $amount = $valid_data['type'] < 0 ? $amount * -1 : $amount; |
|
| 1864 | + // for some reason the date string coming in has extra spaces between the date and time. This fixes that. |
|
| 1865 | + $date = $valid_data['date'] |
|
| 1866 | + ? preg_replace('/\s+/', ' ', $valid_data['date']) |
|
| 1867 | + : date('Y-m-d g:i a', current_time('timestamp')); |
|
| 1868 | + $payment = EE_Payment::new_instance( |
|
| 1869 | + array( |
|
| 1870 | + 'TXN_ID' => $valid_data['TXN_ID'], |
|
| 1871 | + 'STS_ID' => $valid_data['status'], |
|
| 1872 | + 'PAY_timestamp' => $date, |
|
| 1873 | + 'PAY_source' => EEM_Payment_Method::scope_admin, |
|
| 1874 | + 'PMD_ID' => $valid_data['PMD_ID'], |
|
| 1875 | + 'PAY_amount' => $amount, |
|
| 1876 | + 'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'], |
|
| 1877 | + 'PAY_po_number' => $valid_data['po_number'], |
|
| 1878 | + 'PAY_extra_accntng' => $valid_data['accounting'], |
|
| 1879 | + 'PAY_details' => $valid_data, |
|
| 1880 | + 'PAY_ID' => $PAY_ID, |
|
| 1881 | + ), |
|
| 1882 | + '', |
|
| 1883 | + array('Y-m-d', 'g:i a') |
|
| 1884 | + ); |
|
| 1885 | + |
|
| 1886 | + if (! $payment->save()) { |
|
| 1887 | + EE_Error::add_error( |
|
| 1888 | + sprintf( |
|
| 1889 | + esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'), |
|
| 1890 | + $payment->ID() |
|
| 1891 | + ), |
|
| 1892 | + __FILE__, |
|
| 1893 | + __FUNCTION__, |
|
| 1894 | + __LINE__ |
|
| 1895 | + ); |
|
| 1896 | + } |
|
| 1897 | + |
|
| 1898 | + return $payment; |
|
| 1899 | + } |
|
| 1900 | + |
|
| 1901 | + |
|
| 1902 | + /** |
|
| 1903 | + * _process_transaction_payments |
|
| 1904 | + * |
|
| 1905 | + * @param \EE_Transaction $transaction |
|
| 1906 | + * @return void |
|
| 1907 | + * @throws EE_Error |
|
| 1908 | + * @throws InvalidArgumentException |
|
| 1909 | + * @throws ReflectionException |
|
| 1910 | + * @throws InvalidDataTypeException |
|
| 1911 | + * @throws InvalidInterfaceException |
|
| 1912 | + */ |
|
| 1913 | + protected function _process_transaction_payments(EE_Transaction $transaction) |
|
| 1914 | + { |
|
| 1915 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 1916 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 1917 | + // update the transaction with this payment |
|
| 1918 | + if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) { |
|
| 1919 | + EE_Error::add_success( |
|
| 1920 | + esc_html__( |
|
| 1921 | + 'The payment has been processed successfully.', |
|
| 1922 | + 'event_espresso' |
|
| 1923 | + ), |
|
| 1924 | + __FILE__, |
|
| 1925 | + __FUNCTION__, |
|
| 1926 | + __LINE__ |
|
| 1927 | + ); |
|
| 1928 | + } else { |
|
| 1929 | + EE_Error::add_error( |
|
| 1930 | + esc_html__( |
|
| 1931 | + 'The payment was processed successfully but the amount paid for the transaction was not updated.', |
|
| 1932 | + 'event_espresso' |
|
| 1933 | + ), |
|
| 1934 | + __FILE__, |
|
| 1935 | + __FUNCTION__, |
|
| 1936 | + __LINE__ |
|
| 1937 | + ); |
|
| 1938 | + } |
|
| 1939 | + } |
|
| 1940 | + |
|
| 1941 | + |
|
| 1942 | + /** |
|
| 1943 | + * _get_REG_IDs_to_apply_payment_to |
|
| 1944 | + * returns a list of registration IDs that the payment will apply to |
|
| 1945 | + * |
|
| 1946 | + * @param \EE_Payment $payment |
|
| 1947 | + * @return array |
|
| 1948 | + * @throws EE_Error |
|
| 1949 | + * @throws InvalidArgumentException |
|
| 1950 | + * @throws InvalidDataTypeException |
|
| 1951 | + * @throws InvalidInterfaceException |
|
| 1952 | + * @throws ReflectionException |
|
| 1953 | + */ |
|
| 1954 | + protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment) |
|
| 1955 | + { |
|
| 1956 | + $REG_IDs = array(); |
|
| 1957 | + // grab array of IDs for specific registrations to apply changes to |
|
| 1958 | + if (isset($this->_req_data['txn_admin_payment']['registrations'])) { |
|
| 1959 | + $REG_IDs = (array) $this->_req_data['txn_admin_payment']['registrations']; |
|
| 1960 | + } |
|
| 1961 | + // nothing specified ? then get all reg IDs |
|
| 1962 | + if (empty($REG_IDs)) { |
|
| 1963 | + $registrations = $payment->transaction()->registrations(); |
|
| 1964 | + $REG_IDs = ! empty($registrations) |
|
| 1965 | + ? array_keys($registrations) |
|
| 1966 | + : $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 1967 | + } |
|
| 1968 | + |
|
| 1969 | + // ensure that REG_IDs are integers and NOT strings |
|
| 1970 | + return array_map('intval', $REG_IDs); |
|
| 1971 | + } |
|
| 1972 | + |
|
| 1973 | + |
|
| 1974 | + /** |
|
| 1975 | + * @return array |
|
| 1976 | + */ |
|
| 1977 | + public function existing_reg_payment_REG_IDs() |
|
| 1978 | + { |
|
| 1979 | + return $this->_existing_reg_payment_REG_IDs; |
|
| 1980 | + } |
|
| 1981 | + |
|
| 1982 | + |
|
| 1983 | + /** |
|
| 1984 | + * @param array $existing_reg_payment_REG_IDs |
|
| 1985 | + */ |
|
| 1986 | + public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null) |
|
| 1987 | + { |
|
| 1988 | + $this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs; |
|
| 1989 | + } |
|
| 1990 | + |
|
| 1991 | + |
|
| 1992 | + /** |
|
| 1993 | + * _get_existing_reg_payment_REG_IDs |
|
| 1994 | + * returns a list of registration IDs that the payment is currently related to |
|
| 1995 | + * as recorded in the database |
|
| 1996 | + * |
|
| 1997 | + * @param \EE_Payment $payment |
|
| 1998 | + * @return array |
|
| 1999 | + * @throws EE_Error |
|
| 2000 | + * @throws InvalidArgumentException |
|
| 2001 | + * @throws InvalidDataTypeException |
|
| 2002 | + * @throws InvalidInterfaceException |
|
| 2003 | + * @throws ReflectionException |
|
| 2004 | + */ |
|
| 2005 | + protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment) |
|
| 2006 | + { |
|
| 2007 | + if ($this->existing_reg_payment_REG_IDs() === null) { |
|
| 2008 | + // let's get any existing reg payment records for this payment |
|
| 2009 | + $existing_reg_payment_REG_IDs = $payment->get_many_related('Registration'); |
|
| 2010 | + // but we only want the REG IDs, so grab the array keys |
|
| 2011 | + $existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs) |
|
| 2012 | + ? array_keys($existing_reg_payment_REG_IDs) |
|
| 2013 | + : array(); |
|
| 2014 | + $this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs); |
|
| 2015 | + } |
|
| 2016 | + |
|
| 2017 | + return $this->existing_reg_payment_REG_IDs(); |
|
| 2018 | + } |
|
| 2019 | + |
|
| 2020 | + |
|
| 2021 | + /** |
|
| 2022 | + * _remove_existing_registration_payments |
|
| 2023 | + * this calculates the difference between existing relations |
|
| 2024 | + * to the supplied payment and the new list registration IDs, |
|
| 2025 | + * removes any related registrations that no longer apply, |
|
| 2026 | + * and then updates the registration paid fields |
|
| 2027 | + * |
|
| 2028 | + * @param \EE_Payment $payment |
|
| 2029 | + * @param int $PAY_ID |
|
| 2030 | + * @return bool; |
|
| 2031 | + * @throws EE_Error |
|
| 2032 | + * @throws InvalidArgumentException |
|
| 2033 | + * @throws ReflectionException |
|
| 2034 | + * @throws InvalidDataTypeException |
|
| 2035 | + * @throws InvalidInterfaceException |
|
| 2036 | + */ |
|
| 2037 | + protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0) |
|
| 2038 | + { |
|
| 2039 | + // newly created payments will have nothing recorded for $PAY_ID |
|
| 2040 | + if (absint($PAY_ID) === 0) { |
|
| 2041 | + return false; |
|
| 2042 | + } |
|
| 2043 | + $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 2044 | + if (empty($existing_reg_payment_REG_IDs)) { |
|
| 2045 | + return false; |
|
| 2046 | + } |
|
| 2047 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 2048 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 2049 | + |
|
| 2050 | + return $transaction_payments->delete_registration_payments_and_update_registrations( |
|
| 2051 | + $payment, |
|
| 2052 | + array( |
|
| 2053 | + array( |
|
| 2054 | + 'PAY_ID' => $payment->ID(), |
|
| 2055 | + 'REG_ID' => array('IN', $existing_reg_payment_REG_IDs), |
|
| 2056 | + ), |
|
| 2057 | + ) |
|
| 2058 | + ); |
|
| 2059 | + } |
|
| 2060 | + |
|
| 2061 | + |
|
| 2062 | + /** |
|
| 2063 | + * _update_registration_payments |
|
| 2064 | + * this applies the payments to the selected registrations |
|
| 2065 | + * but only if they have not already been paid for |
|
| 2066 | + * |
|
| 2067 | + * @param EE_Transaction $transaction |
|
| 2068 | + * @param \EE_Payment $payment |
|
| 2069 | + * @param array $REG_IDs |
|
| 2070 | + * @return void |
|
| 2071 | + * @throws EE_Error |
|
| 2072 | + * @throws InvalidArgumentException |
|
| 2073 | + * @throws ReflectionException |
|
| 2074 | + * @throws RuntimeException |
|
| 2075 | + * @throws InvalidDataTypeException |
|
| 2076 | + * @throws InvalidInterfaceException |
|
| 2077 | + */ |
|
| 2078 | + protected function _update_registration_payments( |
|
| 2079 | + EE_Transaction $transaction, |
|
| 2080 | + EE_Payment $payment, |
|
| 2081 | + $REG_IDs = array() |
|
| 2082 | + ) { |
|
| 2083 | + // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments() |
|
| 2084 | + // so let's do that using our set of REG_IDs from the form |
|
| 2085 | + $registration_query_where_params = array( |
|
| 2086 | + 'REG_ID' => array('IN', $REG_IDs), |
|
| 2087 | + ); |
|
| 2088 | + // but add in some conditions regarding payment, |
|
| 2089 | + // so that we don't apply payments to registrations that are free or have already been paid for |
|
| 2090 | + // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative ) |
|
| 2091 | + if (! $payment->is_a_refund()) { |
|
| 2092 | + $registration_query_where_params['REG_final_price'] = array('!=', 0); |
|
| 2093 | + $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true); |
|
| 2094 | + } |
|
| 2095 | + $registrations = $transaction->registrations(array($registration_query_where_params)); |
|
| 2096 | + if (! empty($registrations)) { |
|
| 2097 | + /** @type EE_Payment_Processor $payment_processor */ |
|
| 2098 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 2099 | + $payment_processor->process_registration_payments($transaction, $payment, $registrations); |
|
| 2100 | + } |
|
| 2101 | + } |
|
| 2102 | + |
|
| 2103 | + |
|
| 2104 | + /** |
|
| 2105 | + * _process_registration_status_change |
|
| 2106 | + * This processes requested registration status changes for all the registrations |
|
| 2107 | + * on a given transaction and (optionally) sends out notifications for the changes. |
|
| 2108 | + * |
|
| 2109 | + * @param EE_Transaction $transaction |
|
| 2110 | + * @param array $REG_IDs |
|
| 2111 | + * @return bool |
|
| 2112 | + * @throws EE_Error |
|
| 2113 | + * @throws InvalidArgumentException |
|
| 2114 | + * @throws ReflectionException |
|
| 2115 | + * @throws InvalidDataTypeException |
|
| 2116 | + * @throws InvalidInterfaceException |
|
| 2117 | + */ |
|
| 2118 | + protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array()) |
|
| 2119 | + { |
|
| 2120 | + // first if there is no change in status then we get out. |
|
| 2121 | + if (! isset($this->_req_data['txn_reg_status_change']['reg_status']) |
|
| 2122 | + || $this->_req_data['txn_reg_status_change']['reg_status'] === 'NAN' |
|
| 2123 | + ) { |
|
| 2124 | + // no error message, no change requested, just nothing to do man. |
|
| 2125 | + return false; |
|
| 2126 | + } |
|
| 2127 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 2128 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 2129 | + |
|
| 2130 | + // made it here dude? Oh WOW. K, let's take care of changing the statuses |
|
| 2131 | + return $transaction_processor->manually_update_registration_statuses( |
|
| 2132 | + $transaction, |
|
| 2133 | + sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']), |
|
| 2134 | + array(array('REG_ID' => array('IN', $REG_IDs))) |
|
| 2135 | + ); |
|
| 2136 | + } |
|
| 2137 | + |
|
| 2138 | + |
|
| 2139 | + /** |
|
| 2140 | + * _build_payment_json_response |
|
| 2141 | + * |
|
| 2142 | + * @access public |
|
| 2143 | + * @param \EE_Payment $payment |
|
| 2144 | + * @param array $REG_IDs |
|
| 2145 | + * @param bool | null $delete_txn_reg_status_change |
|
| 2146 | + * @return array |
|
| 2147 | + * @throws EE_Error |
|
| 2148 | + * @throws InvalidArgumentException |
|
| 2149 | + * @throws InvalidDataTypeException |
|
| 2150 | + * @throws InvalidInterfaceException |
|
| 2151 | + * @throws ReflectionException |
|
| 2152 | + */ |
|
| 2153 | + protected function _build_payment_json_response( |
|
| 2154 | + EE_Payment $payment, |
|
| 2155 | + $REG_IDs = array(), |
|
| 2156 | + $delete_txn_reg_status_change = null |
|
| 2157 | + ) { |
|
| 2158 | + // was the payment deleted ? |
|
| 2159 | + if (is_bool($delete_txn_reg_status_change)) { |
|
| 2160 | + return array( |
|
| 2161 | + 'PAY_ID' => $payment->ID(), |
|
| 2162 | + 'amount' => $payment->amount(), |
|
| 2163 | + 'total_paid' => $payment->transaction()->paid(), |
|
| 2164 | + 'txn_status' => $payment->transaction()->status_ID(), |
|
| 2165 | + 'pay_status' => $payment->STS_ID(), |
|
| 2166 | + 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
| 2167 | + 'delete_txn_reg_status_change' => $delete_txn_reg_status_change, |
|
| 2168 | + ); |
|
| 2169 | + } else { |
|
| 2170 | + $this->_get_payment_status_array(); |
|
| 2171 | + |
|
| 2172 | + return array( |
|
| 2173 | + 'amount' => $payment->amount(), |
|
| 2174 | + 'total_paid' => $payment->transaction()->paid(), |
|
| 2175 | + 'txn_status' => $payment->transaction()->status_ID(), |
|
| 2176 | + 'pay_status' => $payment->STS_ID(), |
|
| 2177 | + 'PAY_ID' => $payment->ID(), |
|
| 2178 | + 'STS_ID' => $payment->STS_ID(), |
|
| 2179 | + 'status' => self::$_pay_status[ $payment->STS_ID() ], |
|
| 2180 | + 'date' => $payment->timestamp('Y-m-d', 'h:i a'), |
|
| 2181 | + 'method' => strtoupper($payment->source()), |
|
| 2182 | + 'PM_ID' => $payment->payment_method() ? $payment->payment_method()->ID() : 1, |
|
| 2183 | + 'gateway' => $payment->payment_method() |
|
| 2184 | + ? $payment->payment_method()->admin_name() |
|
| 2185 | + : esc_html__('Unknown', 'event_espresso'), |
|
| 2186 | + 'gateway_response' => $payment->gateway_response(), |
|
| 2187 | + 'txn_id_chq_nmbr' => $payment->txn_id_chq_nmbr(), |
|
| 2188 | + 'po_number' => $payment->po_number(), |
|
| 2189 | + 'extra_accntng' => $payment->extra_accntng(), |
|
| 2190 | + 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
| 2191 | + ); |
|
| 2192 | + } |
|
| 2193 | + } |
|
| 2194 | + |
|
| 2195 | + |
|
| 2196 | + /** |
|
| 2197 | + * delete_payment |
|
| 2198 | + * delete a payment or refund made towards a transaction |
|
| 2199 | + * |
|
| 2200 | + * @access public |
|
| 2201 | + * @return void |
|
| 2202 | + * @throws EE_Error |
|
| 2203 | + * @throws InvalidArgumentException |
|
| 2204 | + * @throws ReflectionException |
|
| 2205 | + * @throws InvalidDataTypeException |
|
| 2206 | + * @throws InvalidInterfaceException |
|
| 2207 | + */ |
|
| 2208 | + public function delete_payment() |
|
| 2209 | + { |
|
| 2210 | + $json_response_data = array('return_data' => false); |
|
| 2211 | + $PAY_ID = isset($this->_req_data['delete_txn_admin_payment']['PAY_ID']) |
|
| 2212 | + ? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID']) |
|
| 2213 | + : 0; |
|
| 2214 | + $can_delete = EE_Registry::instance()->CAP->current_user_can( |
|
| 2215 | + 'ee_delete_payments', |
|
| 2216 | + 'delete_payment_from_registration_details' |
|
| 2217 | + ); |
|
| 2218 | + if ($PAY_ID && $can_delete) { |
|
| 2219 | + $delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change']) |
|
| 2220 | + ? $this->_req_data['delete_txn_reg_status_change'] |
|
| 2221 | + : false; |
|
| 2222 | + $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
| 2223 | + if ($payment instanceof EE_Payment) { |
|
| 2224 | + $REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 2225 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 2226 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 2227 | + if ($transaction_payments->delete_payment_and_update_transaction($payment)) { |
|
| 2228 | + $json_response_data['return_data'] = $this->_build_payment_json_response( |
|
| 2229 | + $payment, |
|
| 2230 | + $REG_IDs, |
|
| 2231 | + $delete_txn_reg_status_change |
|
| 2232 | + ); |
|
| 2233 | + if ($delete_txn_reg_status_change) { |
|
| 2234 | + $this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
| 2235 | + // MAKE sure we also add the delete_txn_req_status_change to the |
|
| 2236 | + // $_REQUEST global because that's how messages will be looking for it. |
|
| 2237 | + $_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
| 2238 | + $this->_maybe_send_notifications(); |
|
| 2239 | + $this->_process_registration_status_change($payment->transaction(), $REG_IDs); |
|
| 2240 | + } |
|
| 2241 | + } |
|
| 2242 | + } else { |
|
| 2243 | + EE_Error::add_error( |
|
| 2244 | + esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'), |
|
| 2245 | + __FILE__, |
|
| 2246 | + __FUNCTION__, |
|
| 2247 | + __LINE__ |
|
| 2248 | + ); |
|
| 2249 | + } |
|
| 2250 | + } elseif ($can_delete) { |
|
| 2251 | + EE_Error::add_error( |
|
| 2252 | + esc_html__( |
|
| 2253 | + 'A valid Payment ID was not received, therefore payment form data could not be loaded.', |
|
| 2254 | + 'event_espresso' |
|
| 2255 | + ), |
|
| 2256 | + __FILE__, |
|
| 2257 | + __FUNCTION__, |
|
| 2258 | + __LINE__ |
|
| 2259 | + ); |
|
| 2260 | + } else { |
|
| 2261 | + EE_Error::add_error( |
|
| 2262 | + esc_html__( |
|
| 2263 | + 'You do not have access to delete a payment.', |
|
| 2264 | + 'event_espresso' |
|
| 2265 | + ), |
|
| 2266 | + __FILE__, |
|
| 2267 | + __FUNCTION__, |
|
| 2268 | + __LINE__ |
|
| 2269 | + ); |
|
| 2270 | + } |
|
| 2271 | + $notices = EE_Error::get_notices(false, false, false); |
|
| 2272 | + $this->_template_args = array( |
|
| 2273 | + 'data' => $json_response_data, |
|
| 2274 | + 'success' => $notices['success'], |
|
| 2275 | + 'error' => $notices['errors'], |
|
| 2276 | + 'attention' => $notices['attention'], |
|
| 2277 | + ); |
|
| 2278 | + $this->_return_json(); |
|
| 2279 | + } |
|
| 2280 | + |
|
| 2281 | + |
|
| 2282 | + /** |
|
| 2283 | + * _registration_payment_data_array |
|
| 2284 | + * adds info for 'owing' and 'paid' for each registration to the json response |
|
| 2285 | + * |
|
| 2286 | + * @access protected |
|
| 2287 | + * @param array $REG_IDs |
|
| 2288 | + * @return array |
|
| 2289 | + * @throws EE_Error |
|
| 2290 | + * @throws InvalidArgumentException |
|
| 2291 | + * @throws InvalidDataTypeException |
|
| 2292 | + * @throws InvalidInterfaceException |
|
| 2293 | + * @throws ReflectionException |
|
| 2294 | + */ |
|
| 2295 | + protected function _registration_payment_data_array($REG_IDs) |
|
| 2296 | + { |
|
| 2297 | + $registration_payment_data = array(); |
|
| 2298 | + // if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows. |
|
| 2299 | + if (! empty($REG_IDs)) { |
|
| 2300 | + $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs)))); |
|
| 2301 | + foreach ($registrations as $registration) { |
|
| 2302 | + if ($registration instanceof EE_Registration) { |
|
| 2303 | + $registration_payment_data[ $registration->ID() ] = array( |
|
| 2304 | + 'paid' => $registration->pretty_paid(), |
|
| 2305 | + 'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()), |
|
| 2306 | + ); |
|
| 2307 | + } |
|
| 2308 | + } |
|
| 2309 | + } |
|
| 2310 | + |
|
| 2311 | + return $registration_payment_data; |
|
| 2312 | + } |
|
| 2313 | + |
|
| 2314 | + |
|
| 2315 | + /** |
|
| 2316 | + * _maybe_send_notifications |
|
| 2317 | + * determines whether or not the admin has indicated that notifications should be sent. |
|
| 2318 | + * If so, will toggle a filter switch for delivering registration notices. |
|
| 2319 | + * If passed an EE_Payment object, then it will trigger payment notifications instead. |
|
| 2320 | + * |
|
| 2321 | + * @access protected |
|
| 2322 | + * @param \EE_Payment | null $payment |
|
| 2323 | + */ |
|
| 2324 | + protected function _maybe_send_notifications($payment = null) |
|
| 2325 | + { |
|
| 2326 | + switch ($payment instanceof EE_Payment) { |
|
| 2327 | + // payment notifications |
|
| 2328 | + case true: |
|
| 2329 | + if (isset($this->_req_data['txn_payments']['send_notifications']) |
|
| 2330 | + && filter_var( |
|
| 2331 | + $this->_req_data['txn_payments']['send_notifications'], |
|
| 2332 | + FILTER_VALIDATE_BOOLEAN |
|
| 2333 | + ) |
|
| 2334 | + ) { |
|
| 2335 | + $this->_process_payment_notification($payment); |
|
| 2336 | + } |
|
| 2337 | + break; |
|
| 2338 | + // registration notifications |
|
| 2339 | + case false: |
|
| 2340 | + if (isset($this->_req_data['txn_reg_status_change']['send_notifications']) |
|
| 2341 | + && filter_var( |
|
| 2342 | + $this->_req_data['txn_reg_status_change']['send_notifications'], |
|
| 2343 | + FILTER_VALIDATE_BOOLEAN |
|
| 2344 | + ) |
|
| 2345 | + ) { |
|
| 2346 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
| 2347 | + } |
|
| 2348 | + break; |
|
| 2349 | + } |
|
| 2350 | + } |
|
| 2351 | + |
|
| 2352 | + |
|
| 2353 | + /** |
|
| 2354 | + * _send_payment_reminder |
|
| 2355 | + * generates HTML for the View Transaction Details Admin page |
|
| 2356 | + * |
|
| 2357 | + * @access protected |
|
| 2358 | + * @return void |
|
| 2359 | + * @throws EE_Error |
|
| 2360 | + * @throws InvalidArgumentException |
|
| 2361 | + * @throws InvalidDataTypeException |
|
| 2362 | + * @throws InvalidInterfaceException |
|
| 2363 | + */ |
|
| 2364 | + protected function _send_payment_reminder() |
|
| 2365 | + { |
|
| 2366 | + $TXN_ID = ! empty($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : false; |
|
| 2367 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 2368 | + $query_args = isset($this->_req_data['redirect_to']) ? array( |
|
| 2369 | + 'action' => $this->_req_data['redirect_to'], |
|
| 2370 | + 'TXN_ID' => $this->_req_data['TXN_ID'], |
|
| 2371 | + ) : array(); |
|
| 2372 | + do_action( |
|
| 2373 | + 'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
| 2374 | + $transaction |
|
| 2375 | + ); |
|
| 2376 | + $this->_redirect_after_action( |
|
| 2377 | + false, |
|
| 2378 | + esc_html__('payment reminder', 'event_espresso'), |
|
| 2379 | + esc_html__('sent', 'event_espresso'), |
|
| 2380 | + $query_args, |
|
| 2381 | + true |
|
| 2382 | + ); |
|
| 2383 | + } |
|
| 2384 | + |
|
| 2385 | + |
|
| 2386 | + /** |
|
| 2387 | + * get_transactions |
|
| 2388 | + * get transactions for given parameters (used by list table) |
|
| 2389 | + * |
|
| 2390 | + * @param int $perpage how many transactions displayed per page |
|
| 2391 | + * @param boolean $count return the count or objects |
|
| 2392 | + * @param string $view |
|
| 2393 | + * @return mixed int = count || array of transaction objects |
|
| 2394 | + * @throws EE_Error |
|
| 2395 | + * @throws InvalidArgumentException |
|
| 2396 | + * @throws InvalidDataTypeException |
|
| 2397 | + * @throws InvalidInterfaceException |
|
| 2398 | + */ |
|
| 2399 | + public function get_transactions($perpage, $count = false, $view = '') |
|
| 2400 | + { |
|
| 2401 | + |
|
| 2402 | + $TXN = EEM_Transaction::instance(); |
|
| 2403 | + |
|
| 2404 | + $start_date = isset($this->_req_data['txn-filter-start-date']) |
|
| 2405 | + ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) |
|
| 2406 | + : date( |
|
| 2407 | + 'm/d/Y', |
|
| 2408 | + strtotime('-10 year') |
|
| 2409 | + ); |
|
| 2410 | + $end_date = isset($this->_req_data['txn-filter-end-date']) |
|
| 2411 | + ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) |
|
| 2412 | + : date('m/d/Y'); |
|
| 2413 | + |
|
| 2414 | + // make sure our timestamps start and end right at the boundaries for each day |
|
| 2415 | + $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
| 2416 | + $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
| 2417 | + |
|
| 2418 | + |
|
| 2419 | + // convert to timestamps |
|
| 2420 | + $start_date = strtotime($start_date); |
|
| 2421 | + $end_date = strtotime($end_date); |
|
| 2422 | + |
|
| 2423 | + // makes sure start date is the lowest value and vice versa |
|
| 2424 | + $start_date = min($start_date, $end_date); |
|
| 2425 | + $end_date = max($start_date, $end_date); |
|
| 2426 | + |
|
| 2427 | + // convert to correct format for query |
|
| 2428 | + $start_date = EEM_Transaction::instance()->convert_datetime_for_query( |
|
| 2429 | + 'TXN_timestamp', |
|
| 2430 | + date('Y-m-d H:i:s', $start_date), |
|
| 2431 | + 'Y-m-d H:i:s' |
|
| 2432 | + ); |
|
| 2433 | + $end_date = EEM_Transaction::instance()->convert_datetime_for_query( |
|
| 2434 | + 'TXN_timestamp', |
|
| 2435 | + date('Y-m-d H:i:s', $end_date), |
|
| 2436 | + 'Y-m-d H:i:s' |
|
| 2437 | + ); |
|
| 2438 | + |
|
| 2439 | + |
|
| 2440 | + // set orderby |
|
| 2441 | + $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
|
| 2442 | + |
|
| 2443 | + switch ($this->_req_data['orderby']) { |
|
| 2444 | + case 'TXN_ID': |
|
| 2445 | + $orderby = 'TXN_ID'; |
|
| 2446 | + break; |
|
| 2447 | + case 'ATT_fname': |
|
| 2448 | + $orderby = 'Registration.Attendee.ATT_fname'; |
|
| 2449 | + break; |
|
| 2450 | + case 'event_name': |
|
| 2451 | + $orderby = 'Registration.Event.EVT_name'; |
|
| 2452 | + break; |
|
| 2453 | + default: // 'TXN_timestamp' |
|
| 2454 | + $orderby = 'TXN_timestamp'; |
|
| 2455 | + } |
|
| 2456 | + |
|
| 2457 | + $sort = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
| 2458 | + $current_page = ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
| 2459 | + $per_page = ! empty($perpage) ? $perpage : 10; |
|
| 2460 | + $per_page = ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page; |
|
| 2461 | + |
|
| 2462 | + $offset = ($current_page - 1) * $per_page; |
|
| 2463 | + $limit = array($offset, $per_page); |
|
| 2464 | + |
|
| 2465 | + $_where = array( |
|
| 2466 | + 'TXN_timestamp' => array('BETWEEN', array($start_date, $end_date)), |
|
| 2467 | + 'Registration.REG_count' => 1, |
|
| 2468 | + ); |
|
| 2469 | + |
|
| 2470 | + if (isset($this->_req_data['EVT_ID'])) { |
|
| 2471 | + $_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID']; |
|
| 2472 | + } |
|
| 2473 | + |
|
| 2474 | + if (isset($this->_req_data['s'])) { |
|
| 2475 | + $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 2476 | + $_where['OR'] = array( |
|
| 2477 | + 'Registration.Event.EVT_name' => array('LIKE', $search_string), |
|
| 2478 | + 'Registration.Event.EVT_desc' => array('LIKE', $search_string), |
|
| 2479 | + 'Registration.Event.EVT_short_desc' => array('LIKE', $search_string), |
|
| 2480 | + 'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string), |
|
| 2481 | + 'Registration.Attendee.ATT_fname' => array('LIKE', $search_string), |
|
| 2482 | + 'Registration.Attendee.ATT_lname' => array('LIKE', $search_string), |
|
| 2483 | + 'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string), |
|
| 2484 | + 'Registration.Attendee.ATT_email' => array('LIKE', $search_string), |
|
| 2485 | + 'Registration.Attendee.ATT_address' => array('LIKE', $search_string), |
|
| 2486 | + 'Registration.Attendee.ATT_address2' => array('LIKE', $search_string), |
|
| 2487 | + 'Registration.Attendee.ATT_city' => array('LIKE', $search_string), |
|
| 2488 | + 'Registration.REG_final_price' => array('LIKE', $search_string), |
|
| 2489 | + 'Registration.REG_code' => array('LIKE', $search_string), |
|
| 2490 | + 'Registration.REG_count' => array('LIKE', $search_string), |
|
| 2491 | + 'Registration.REG_group_size' => array('LIKE', $search_string), |
|
| 2492 | + 'Registration.Ticket.TKT_name' => array('LIKE', $search_string), |
|
| 2493 | + 'Registration.Ticket.TKT_description' => array('LIKE', $search_string), |
|
| 2494 | + 'Payment.PAY_source' => array('LIKE', $search_string), |
|
| 2495 | + 'Payment.Payment_Method.PMD_name' => array('LIKE', $search_string), |
|
| 2496 | + 'TXN_session_data' => array('LIKE', $search_string), |
|
| 2497 | + 'Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string), |
|
| 2498 | + ); |
|
| 2499 | + } |
|
| 2500 | + |
|
| 2501 | + // failed transactions |
|
| 2502 | + $failed = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count) |
|
| 2503 | + || ($count && $view === 'failed'); |
|
| 2504 | + $abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count) |
|
| 2505 | + || ($count && $view === 'abandoned'); |
|
| 2506 | + $incomplete = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'incomplete' && ! $count) |
|
| 2507 | + || ($count && $view === 'incomplete'); |
|
| 2508 | + |
|
| 2509 | + if ($failed) { |
|
| 2510 | + $_where['STS_ID'] = EEM_Transaction::failed_status_code; |
|
| 2511 | + } elseif ($abandoned) { |
|
| 2512 | + $_where['STS_ID'] = EEM_Transaction::abandoned_status_code; |
|
| 2513 | + } elseif ($incomplete) { |
|
| 2514 | + $_where['STS_ID'] = EEM_Transaction::incomplete_status_code; |
|
| 2515 | + } else { |
|
| 2516 | + $_where['STS_ID'] = array('!=', EEM_Transaction::failed_status_code); |
|
| 2517 | + $_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code); |
|
| 2518 | + } |
|
| 2519 | + |
|
| 2520 | + $query_params = apply_filters( |
|
| 2521 | + 'FHEE__Transactions_Admin_Page___get_transactions_query_params', |
|
| 2522 | + array( |
|
| 2523 | + $_where, |
|
| 2524 | + 'order_by' => array($orderby => $sort), |
|
| 2525 | + 'limit' => $limit, |
|
| 2526 | + 'default_where_conditions' => EEM_Base::default_where_conditions_this_only, |
|
| 2527 | + ), |
|
| 2528 | + $this->_req_data, |
|
| 2529 | + $view, |
|
| 2530 | + $count |
|
| 2531 | + ); |
|
| 2532 | + |
|
| 2533 | + $transactions = $count |
|
| 2534 | + ? $TXN->count(array($query_params[0]), 'TXN_ID', true) |
|
| 2535 | + : $TXN->get_all($query_params); |
|
| 2536 | + |
|
| 2537 | + return $transactions; |
|
| 2538 | + } |
|
| 2539 | + |
|
| 2540 | + |
|
| 2541 | + /** |
|
| 2542 | + * @since 4.9.79.p |
|
| 2543 | + * @throws EE_Error |
|
| 2544 | + * @throws InvalidArgumentException |
|
| 2545 | + * @throws InvalidDataTypeException |
|
| 2546 | + * @throws InvalidInterfaceException |
|
| 2547 | + * @throws ReflectionException |
|
| 2548 | + * @throws RuntimeException |
|
| 2549 | + */ |
|
| 2550 | + public function recalculateLineItems() |
|
| 2551 | + { |
|
| 2552 | + $TXN_ID = ! empty($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : false; |
|
| 2553 | + /** @var EE_Transaction $transaction */ |
|
| 2554 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 2555 | + $total_line_item = $transaction->total_line_item(false); |
|
| 2556 | + $success = $transaction->recalculateLineItems(); |
|
| 2557 | + $this->_redirect_after_action( |
|
| 2558 | + (bool) $success, |
|
| 2559 | + esc_html__('Transaction taxes and totals', 'event_espresso'), |
|
| 2560 | + esc_html__('recalculated', 'event_espresso'), |
|
| 2561 | + isset($this->_req_data['redirect_to']) |
|
| 2562 | + ? array( |
|
| 2563 | + 'action' => $this->_req_data['redirect_to'], |
|
| 2564 | + 'TXN_ID' => $this->_req_data['TXN_ID'], |
|
| 2565 | + ) |
|
| 2566 | + : array(), |
|
| 2567 | + true |
|
| 2568 | + ); |
|
| 2569 | + } |
|
| 2570 | 2570 | } |
@@ -135,11 +135,11 @@ discard block |
||
| 135 | 135 | } |
| 136 | 136 | } else { |
| 137 | 137 | $user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso'); |
| 138 | - $dev_msg = $user_msg . __( |
|
| 138 | + $dev_msg = $user_msg.__( |
|
| 139 | 139 | 'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.', |
| 140 | 140 | 'event_espresso' |
| 141 | 141 | ); |
| 142 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 142 | + EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 143 | 143 | return false; |
| 144 | 144 | } |
| 145 | 145 | return true; |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | // reset filter for displaying submit button |
| 201 | 201 | remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
| 202 | 202 | // poke and prod incoming event till it tells us what it is |
| 203 | - if (! $this->setEvent($event)) { |
|
| 203 | + if ( ! $this->setEvent($event)) { |
|
| 204 | 204 | return false; |
| 205 | 205 | } |
| 206 | 206 | // begin gathering template arguments by getting event status |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | : $this->loadTicketSelector($tickets, $template_args); |
| 239 | 239 | // now set up the form (but not for the admin) |
| 240 | 240 | $ticket_selector = $this->display_full_ui() |
| 241 | - ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector |
|
| 241 | + ? $this->formOpen($this->event->ID(), $external_url).$ticket_selector |
|
| 242 | 242 | : $ticket_selector; |
| 243 | 243 | // submit button and form close tag |
| 244 | 244 | $ticket_selector .= $this->display_full_ui() ? $this->displaySubmitButton($external_url) : ''; |
@@ -286,10 +286,10 @@ discard block |
||
| 286 | 286 | */ |
| 287 | 287 | protected function expiredEventMessage() |
| 288 | 288 | { |
| 289 | - return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__( |
|
| 289 | + return '<div class="ee-event-expired-notice"><span class="important-notice">'.esc_html__( |
|
| 290 | 290 | 'We\'re sorry, but all tickets sales have ended because the event is expired.', |
| 291 | 291 | 'event_espresso' |
| 292 | - ) . '</span></div><!-- .ee-event-expired-notice -->'; |
|
| 292 | + ).'</span></div><!-- .ee-event-expired-notice -->'; |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | } |
| 320 | 320 | return ' |
| 321 | 321 | <div class="ee-event-expired-notice"> |
| 322 | - <span class="important-notice">' . $no_ticket_available_msg . '</span> |
|
| 322 | + <span class="important-notice">' . $no_ticket_available_msg.'</span> |
|
| 323 | 323 | </div><!-- .ee-event-expired-notice -->'; |
| 324 | 324 | } |
| 325 | 325 | |
@@ -351,7 +351,7 @@ discard block |
||
| 351 | 351 | '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->' |
| 352 | 352 | ); |
| 353 | 353 | } |
| 354 | - return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>'; |
|
| 354 | + return '<p><span class="important-notice">'.$sales_closed_msg.'</span></p>'; |
|
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | |
@@ -381,7 +381,7 @@ discard block |
||
| 381 | 381 | 'Datetime.DTT_EVT_start' => 'DESC', |
| 382 | 382 | ), |
| 383 | 383 | ); |
| 384 | - if (! $show_expired_tickets) { |
|
| 384 | + if ( ! $show_expired_tickets) { |
|
| 385 | 385 | // use the correct applicable time query depending on what version of core is being run. |
| 386 | 386 | $current_time = method_exists('EEM_Datetime', 'current_time_for_query') |
| 387 | 387 | ? time() |
@@ -419,7 +419,7 @@ discard block |
||
| 419 | 419 | */ |
| 420 | 420 | $template_args['anchor_id'] = apply_filters( |
| 421 | 421 | 'FHEE__EE_Ticket_Selector__redirect_anchor_id', |
| 422 | - '#tkt-slctr-tbl-' . $this->event->ID(), |
|
| 422 | + '#tkt-slctr-tbl-'.$this->event->ID(), |
|
| 423 | 423 | $this->event->ID() |
| 424 | 424 | ); |
| 425 | 425 | $template_args['tickets'] = $tickets; |
@@ -505,8 +505,8 @@ discard block |
||
| 505 | 505 | // if redirecting, we don't need any anything else |
| 506 | 506 | if ($external_url) { |
| 507 | 507 | $html = '<form method="GET" '; |
| 508 | - $html .= 'action="' . EEH_URL::refactor_url($external_url) . '" '; |
|
| 509 | - $html .= 'name="ticket-selector-form-' . $ID . '"'; |
|
| 508 | + $html .= 'action="'.EEH_URL::refactor_url($external_url).'" '; |
|
| 509 | + $html .= 'name="ticket-selector-form-'.$ID.'"'; |
|
| 510 | 510 | // open link in new window ? |
| 511 | 511 | $html .= apply_filters( |
| 512 | 512 | 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank', |
@@ -518,17 +518,17 @@ discard block |
||
| 518 | 518 | $html .= '>'; |
| 519 | 519 | $query_args = EEH_URL::get_query_string($external_url); |
| 520 | 520 | foreach ((array) $query_args as $query_arg => $value) { |
| 521 | - $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">'; |
|
| 521 | + $html .= '<input type="hidden" name="'.$query_arg.'" value="'.$value.'">'; |
|
| 522 | 522 | } |
| 523 | 523 | return $html; |
| 524 | 524 | } |
| 525 | 525 | // if there is no submit button, then don't start building a form |
| 526 | 526 | // because the "View Details" button will build its own form |
| 527 | - if (! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
| 527 | + if ( ! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
| 528 | 528 | return ''; |
| 529 | 529 | } |
| 530 | 530 | $checkout_url = EEH_Event_View::event_link_url($ID); |
| 531 | - if (! $checkout_url) { |
|
| 531 | + if ( ! $checkout_url) { |
|
| 532 | 532 | EE_Error::add_error( |
| 533 | 533 | esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'), |
| 534 | 534 | __FILE__, |
@@ -539,8 +539,8 @@ discard block |
||
| 539 | 539 | // set no cache headers and constants |
| 540 | 540 | EE_System::do_not_cache(); |
| 541 | 541 | $html = '<form method="POST" '; |
| 542 | - $html .= 'action="' . $checkout_url . '" '; |
|
| 543 | - $html .= 'name="ticket-selector-form-' . $ID . '"'; |
|
| 542 | + $html .= 'action="'.$checkout_url.'" '; |
|
| 543 | + $html .= 'name="ticket-selector-form-'.$ID.'"'; |
|
| 544 | 544 | $html .= $this->iframe ? ' target="_blank"' : ''; |
| 545 | 545 | $html .= '>'; |
| 546 | 546 | $html .= '<input type="hidden" name="ee" value="process_ticket_selections">'; |
@@ -566,7 +566,7 @@ discard block |
||
| 566 | 566 | $html .= empty($external_url) |
| 567 | 567 | ? $this->ticketSelectorEndDiv() |
| 568 | 568 | : $this->clearTicketSelector(); |
| 569 | - $html .= '<br/>' . $this->formClose(); |
|
| 569 | + $html .= '<br/>'.$this->formClose(); |
|
| 570 | 570 | } elseif ($this->getMaxAttendees() === 1) { |
| 571 | 571 | // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1) |
| 572 | 572 | if ($this->event->is_sold_out()) { |
@@ -619,7 +619,7 @@ discard block |
||
| 619 | 619 | // no submit or view details button, and no additional content |
| 620 | 620 | $html .= $this->ticketSelectorEndDiv(); |
| 621 | 621 | } |
| 622 | - if (! $this->iframe && ! is_archive()) { |
|
| 622 | + if ( ! $this->iframe && ! is_archive()) { |
|
| 623 | 623 | $html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector')); |
| 624 | 624 | } |
| 625 | 625 | } |
@@ -649,14 +649,14 @@ discard block |
||
| 649 | 649 | : ''; |
| 650 | 650 | $html = EEH_HTML::div( |
| 651 | 651 | '', |
| 652 | - 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', |
|
| 652 | + 'ticket-selector-submit-'.$this->event->ID().'-btn-wrap', |
|
| 653 | 653 | 'ticket-selector-submit-btn-wrap' |
| 654 | 654 | ); |
| 655 | - $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"'; |
|
| 655 | + $html .= '<input id="ticket-selector-submit-'.$this->event->ID().'-btn"'; |
|
| 656 | 656 | $html .= ' class="ticket-selector-submit-btn '; |
| 657 | 657 | $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"'; |
| 658 | - $html .= ' type="submit" value="' . $btn_text . '" data-ee-disable-after-recaptcha="true" />'; |
|
| 659 | - $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->'; |
|
| 658 | + $html .= ' type="submit" value="'.$btn_text.'" data-ee-disable-after-recaptcha="true" />'; |
|
| 659 | + $html .= EEH_HTML::divx().'<!-- .ticket-selector-submit-btn-wrap -->'; |
|
| 660 | 660 | $html .= apply_filters( |
| 661 | 661 | 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
| 662 | 662 | '', |
@@ -679,7 +679,7 @@ discard block |
||
| 679 | 679 | */ |
| 680 | 680 | public function displayViewDetailsButton($DWMTS = false) |
| 681 | 681 | { |
| 682 | - if (! $this->event->get_permalink()) { |
|
| 682 | + if ( ! $this->event->get_permalink()) { |
|
| 683 | 683 | EE_Error::add_error( |
| 684 | 684 | esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'), |
| 685 | 685 | __FILE__, |
@@ -732,7 +732,7 @@ discard block |
||
| 732 | 732 | */ |
| 733 | 733 | public function ticketSelectorEndDiv() |
| 734 | 734 | { |
| 735 | - return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->'; |
|
| 735 | + return $this->clearTicketSelector().'</div><!-- ticketSelectorEndDiv -->'; |
|
| 736 | 736 | } |
| 737 | 737 | |
| 738 | 738 | |
@@ -33,725 +33,725 @@ |
||
| 33 | 33 | class DisplayTicketSelector |
| 34 | 34 | { |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * event that ticket selector is being generated for |
|
| 38 | - * |
|
| 39 | - * @access protected |
|
| 40 | - * @var EE_Event $event |
|
| 41 | - */ |
|
| 42 | - protected $event; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Used to flag when the ticket selector is being called from an external iframe. |
|
| 46 | - * |
|
| 47 | - * @var bool $iframe |
|
| 48 | - */ |
|
| 49 | - protected $iframe = false; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * max attendees that can register for event at one time |
|
| 53 | - * |
|
| 54 | - * @var int $max_attendees |
|
| 55 | - */ |
|
| 56 | - private $max_attendees = EE_INF; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @var string $date_format |
|
| 60 | - */ |
|
| 61 | - private $date_format; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @var string $time_format |
|
| 65 | - */ |
|
| 66 | - private $time_format; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @var boolean $display_full_ui |
|
| 70 | - */ |
|
| 71 | - private $display_full_ui; |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * DisplayTicketSelector constructor. |
|
| 76 | - * |
|
| 77 | - * @param bool $iframe |
|
| 78 | - */ |
|
| 79 | - public function __construct($iframe = false) |
|
| 80 | - { |
|
| 81 | - $this->iframe = $iframe; |
|
| 82 | - $this->date_format = apply_filters( |
|
| 83 | - 'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format', |
|
| 84 | - get_option('date_format') |
|
| 85 | - ); |
|
| 86 | - $this->time_format = apply_filters( |
|
| 87 | - 'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format', |
|
| 88 | - get_option('time_format') |
|
| 89 | - ); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * @return bool |
|
| 95 | - */ |
|
| 96 | - public function isIframe() |
|
| 97 | - { |
|
| 98 | - return $this->iframe; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @param boolean $iframe |
|
| 104 | - */ |
|
| 105 | - public function setIframe($iframe = true) |
|
| 106 | - { |
|
| 107 | - $this->iframe = filter_var($iframe, FILTER_VALIDATE_BOOLEAN); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * finds and sets the \EE_Event object for use throughout class |
|
| 113 | - * |
|
| 114 | - * @param mixed $event |
|
| 115 | - * @return bool |
|
| 116 | - * @throws EE_Error |
|
| 117 | - * @throws InvalidDataTypeException |
|
| 118 | - * @throws InvalidInterfaceException |
|
| 119 | - * @throws InvalidArgumentException |
|
| 120 | - */ |
|
| 121 | - protected function setEvent($event = null) |
|
| 122 | - { |
|
| 123 | - if ($event === null) { |
|
| 124 | - global $post; |
|
| 125 | - $event = $post; |
|
| 126 | - } |
|
| 127 | - if ($event instanceof EE_Event) { |
|
| 128 | - $this->event = $event; |
|
| 129 | - } elseif ($event instanceof WP_Post) { |
|
| 130 | - if (isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) { |
|
| 131 | - $this->event = $event->EE_Event; |
|
| 132 | - } elseif ($event->post_type === 'espresso_events') { |
|
| 133 | - $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object($event); |
|
| 134 | - $this->event = $event->EE_Event; |
|
| 135 | - } |
|
| 136 | - } else { |
|
| 137 | - $user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso'); |
|
| 138 | - $dev_msg = $user_msg . __( |
|
| 139 | - 'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.', |
|
| 140 | - 'event_espresso' |
|
| 141 | - ); |
|
| 142 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 143 | - return false; |
|
| 144 | - } |
|
| 145 | - return true; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * @return int |
|
| 151 | - */ |
|
| 152 | - public function getMaxAttendees() |
|
| 153 | - { |
|
| 154 | - return $this->max_attendees; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * @param int $max_attendees |
|
| 160 | - */ |
|
| 161 | - public function setMaxAttendees($max_attendees) |
|
| 162 | - { |
|
| 163 | - $this->max_attendees = absint( |
|
| 164 | - apply_filters( |
|
| 165 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets', |
|
| 166 | - $max_attendees |
|
| 167 | - ) |
|
| 168 | - ); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * Returns whether or not the full ticket selector should be shown or not. |
|
| 174 | - * Currently, it displays on the frontend (including ajax requests) but not the backend |
|
| 175 | - * |
|
| 176 | - * @return bool |
|
| 177 | - */ |
|
| 178 | - private function display_full_ui() |
|
| 179 | - { |
|
| 180 | - if ($this->display_full_ui === null) { |
|
| 181 | - $this->display_full_ui = ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX); |
|
| 182 | - } |
|
| 183 | - return $this->display_full_ui; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * creates buttons for selecting number of attendees for an event |
|
| 189 | - * |
|
| 190 | - * @param WP_Post|int $event |
|
| 191 | - * @param bool $view_details |
|
| 192 | - * @return string |
|
| 193 | - * @throws EE_Error |
|
| 194 | - * @throws InvalidArgumentException |
|
| 195 | - * @throws InvalidDataTypeException |
|
| 196 | - * @throws InvalidInterfaceException |
|
| 197 | - */ |
|
| 198 | - public function display($event = null, $view_details = false) |
|
| 199 | - { |
|
| 200 | - // reset filter for displaying submit button |
|
| 201 | - remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
| 202 | - // poke and prod incoming event till it tells us what it is |
|
| 203 | - if (! $this->setEvent($event)) { |
|
| 204 | - return false; |
|
| 205 | - } |
|
| 206 | - // begin gathering template arguments by getting event status |
|
| 207 | - $template_args = array('event_status' => $this->event->get_active_status()); |
|
| 208 | - if ($this->activeEventAndShowTicketSelector( |
|
| 209 | - $event, |
|
| 210 | - $template_args['event_status'], |
|
| 211 | - $view_details |
|
| 212 | - )) { |
|
| 213 | - return ! is_single() ? $this->displayViewDetailsButton() : ''; |
|
| 214 | - } |
|
| 215 | - // filter the maximum qty that can appear in the Ticket Selector qty dropdowns |
|
| 216 | - $this->setMaxAttendees($this->event->additional_limit()); |
|
| 217 | - if ($this->getMaxAttendees() < 1) { |
|
| 218 | - return $this->ticketSalesClosedMessage(); |
|
| 219 | - } |
|
| 220 | - // is the event expired ? |
|
| 221 | - $template_args['event_is_expired'] = ! is_admin() ? $this->event->is_expired() : false; |
|
| 222 | - if ($template_args['event_is_expired']) { |
|
| 223 | - return $this->expiredEventMessage(); |
|
| 224 | - } |
|
| 225 | - // get all tickets for this event ordered by the datetime |
|
| 226 | - $tickets = $this->getTickets(); |
|
| 227 | - if (count($tickets) < 1) { |
|
| 228 | - return $this->noTicketAvailableMessage(); |
|
| 229 | - } |
|
| 230 | - // redirecting to another site for registration ?? |
|
| 231 | - $external_url = (string) $this->event->external_url() |
|
| 232 | - && $this->event->external_url() !== get_the_permalink() |
|
| 233 | - ? $this->event->external_url() |
|
| 234 | - : ''; |
|
| 235 | - // if redirecting to another site for registration, then we don't load the TS |
|
| 236 | - $ticket_selector = $external_url |
|
| 237 | - ? $this->externalEventRegistration() |
|
| 238 | - : $this->loadTicketSelector($tickets, $template_args); |
|
| 239 | - // now set up the form (but not for the admin) |
|
| 240 | - $ticket_selector = $this->display_full_ui() |
|
| 241 | - ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector |
|
| 242 | - : $ticket_selector; |
|
| 243 | - // submit button and form close tag |
|
| 244 | - $ticket_selector .= $this->display_full_ui() ? $this->displaySubmitButton($external_url) : ''; |
|
| 245 | - return $ticket_selector; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * displayTicketSelector |
|
| 251 | - * examines the event properties and determines whether a Ticket Selector should be displayed |
|
| 252 | - * |
|
| 253 | - * @param WP_Post|int $event |
|
| 254 | - * @param string $_event_active_status |
|
| 255 | - * @param bool $view_details |
|
| 256 | - * @return bool |
|
| 257 | - * @throws EE_Error |
|
| 258 | - */ |
|
| 259 | - protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details) |
|
| 260 | - { |
|
| 261 | - $event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event; |
|
| 262 | - return $this->display_full_ui() |
|
| 263 | - && ( |
|
| 264 | - ! $this->event->display_ticket_selector() |
|
| 265 | - || $view_details |
|
| 266 | - || post_password_required($event_post) |
|
| 267 | - || ( |
|
| 268 | - $_event_active_status !== EE_Datetime::active |
|
| 269 | - && $_event_active_status !== EE_Datetime::upcoming |
|
| 270 | - && $_event_active_status !== EE_Datetime::sold_out |
|
| 271 | - && ! ( |
|
| 272 | - $_event_active_status === EE_Datetime::inactive |
|
| 273 | - && is_user_logged_in() |
|
| 274 | - ) |
|
| 275 | - ) |
|
| 276 | - ); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * noTicketAvailableMessage |
|
| 282 | - * notice displayed if event is expired |
|
| 283 | - * |
|
| 284 | - * @return string |
|
| 285 | - * @throws EE_Error |
|
| 286 | - */ |
|
| 287 | - protected function expiredEventMessage() |
|
| 288 | - { |
|
| 289 | - return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__( |
|
| 290 | - 'We\'re sorry, but all tickets sales have ended because the event is expired.', |
|
| 291 | - 'event_espresso' |
|
| 292 | - ) . '</span></div><!-- .ee-event-expired-notice -->'; |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * noTicketAvailableMessage |
|
| 298 | - * notice displayed if event has no more tickets available |
|
| 299 | - * |
|
| 300 | - * @return string |
|
| 301 | - * @throws EE_Error |
|
| 302 | - */ |
|
| 303 | - protected function noTicketAvailableMessage() |
|
| 304 | - { |
|
| 305 | - $no_ticket_available_msg = esc_html__('We\'re sorry, but all ticket sales have ended.', 'event_espresso'); |
|
| 306 | - if (current_user_can('edit_post', $this->event->ID())) { |
|
| 307 | - $no_ticket_available_msg .= sprintf( |
|
| 308 | - esc_html__( |
|
| 309 | - '%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s', |
|
| 310 | - 'event_espresso' |
|
| 311 | - ), |
|
| 312 | - '<div class="ee-attention" style="text-align: left;"><b>', |
|
| 313 | - '</b><br />', |
|
| 314 | - '<span class="edit-link"><a class="post-edit-link" href="' |
|
| 315 | - . get_edit_post_link($this->event->ID()) |
|
| 316 | - . '">', |
|
| 317 | - '</a></span></div><!-- .ee-attention noTicketAvailableMessage -->' |
|
| 318 | - ); |
|
| 319 | - } |
|
| 320 | - return ' |
|
| 36 | + /** |
|
| 37 | + * event that ticket selector is being generated for |
|
| 38 | + * |
|
| 39 | + * @access protected |
|
| 40 | + * @var EE_Event $event |
|
| 41 | + */ |
|
| 42 | + protected $event; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Used to flag when the ticket selector is being called from an external iframe. |
|
| 46 | + * |
|
| 47 | + * @var bool $iframe |
|
| 48 | + */ |
|
| 49 | + protected $iframe = false; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * max attendees that can register for event at one time |
|
| 53 | + * |
|
| 54 | + * @var int $max_attendees |
|
| 55 | + */ |
|
| 56 | + private $max_attendees = EE_INF; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @var string $date_format |
|
| 60 | + */ |
|
| 61 | + private $date_format; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @var string $time_format |
|
| 65 | + */ |
|
| 66 | + private $time_format; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @var boolean $display_full_ui |
|
| 70 | + */ |
|
| 71 | + private $display_full_ui; |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * DisplayTicketSelector constructor. |
|
| 76 | + * |
|
| 77 | + * @param bool $iframe |
|
| 78 | + */ |
|
| 79 | + public function __construct($iframe = false) |
|
| 80 | + { |
|
| 81 | + $this->iframe = $iframe; |
|
| 82 | + $this->date_format = apply_filters( |
|
| 83 | + 'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format', |
|
| 84 | + get_option('date_format') |
|
| 85 | + ); |
|
| 86 | + $this->time_format = apply_filters( |
|
| 87 | + 'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format', |
|
| 88 | + get_option('time_format') |
|
| 89 | + ); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * @return bool |
|
| 95 | + */ |
|
| 96 | + public function isIframe() |
|
| 97 | + { |
|
| 98 | + return $this->iframe; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @param boolean $iframe |
|
| 104 | + */ |
|
| 105 | + public function setIframe($iframe = true) |
|
| 106 | + { |
|
| 107 | + $this->iframe = filter_var($iframe, FILTER_VALIDATE_BOOLEAN); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * finds and sets the \EE_Event object for use throughout class |
|
| 113 | + * |
|
| 114 | + * @param mixed $event |
|
| 115 | + * @return bool |
|
| 116 | + * @throws EE_Error |
|
| 117 | + * @throws InvalidDataTypeException |
|
| 118 | + * @throws InvalidInterfaceException |
|
| 119 | + * @throws InvalidArgumentException |
|
| 120 | + */ |
|
| 121 | + protected function setEvent($event = null) |
|
| 122 | + { |
|
| 123 | + if ($event === null) { |
|
| 124 | + global $post; |
|
| 125 | + $event = $post; |
|
| 126 | + } |
|
| 127 | + if ($event instanceof EE_Event) { |
|
| 128 | + $this->event = $event; |
|
| 129 | + } elseif ($event instanceof WP_Post) { |
|
| 130 | + if (isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) { |
|
| 131 | + $this->event = $event->EE_Event; |
|
| 132 | + } elseif ($event->post_type === 'espresso_events') { |
|
| 133 | + $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object($event); |
|
| 134 | + $this->event = $event->EE_Event; |
|
| 135 | + } |
|
| 136 | + } else { |
|
| 137 | + $user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso'); |
|
| 138 | + $dev_msg = $user_msg . __( |
|
| 139 | + 'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.', |
|
| 140 | + 'event_espresso' |
|
| 141 | + ); |
|
| 142 | + EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 143 | + return false; |
|
| 144 | + } |
|
| 145 | + return true; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * @return int |
|
| 151 | + */ |
|
| 152 | + public function getMaxAttendees() |
|
| 153 | + { |
|
| 154 | + return $this->max_attendees; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * @param int $max_attendees |
|
| 160 | + */ |
|
| 161 | + public function setMaxAttendees($max_attendees) |
|
| 162 | + { |
|
| 163 | + $this->max_attendees = absint( |
|
| 164 | + apply_filters( |
|
| 165 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets', |
|
| 166 | + $max_attendees |
|
| 167 | + ) |
|
| 168 | + ); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * Returns whether or not the full ticket selector should be shown or not. |
|
| 174 | + * Currently, it displays on the frontend (including ajax requests) but not the backend |
|
| 175 | + * |
|
| 176 | + * @return bool |
|
| 177 | + */ |
|
| 178 | + private function display_full_ui() |
|
| 179 | + { |
|
| 180 | + if ($this->display_full_ui === null) { |
|
| 181 | + $this->display_full_ui = ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX); |
|
| 182 | + } |
|
| 183 | + return $this->display_full_ui; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * creates buttons for selecting number of attendees for an event |
|
| 189 | + * |
|
| 190 | + * @param WP_Post|int $event |
|
| 191 | + * @param bool $view_details |
|
| 192 | + * @return string |
|
| 193 | + * @throws EE_Error |
|
| 194 | + * @throws InvalidArgumentException |
|
| 195 | + * @throws InvalidDataTypeException |
|
| 196 | + * @throws InvalidInterfaceException |
|
| 197 | + */ |
|
| 198 | + public function display($event = null, $view_details = false) |
|
| 199 | + { |
|
| 200 | + // reset filter for displaying submit button |
|
| 201 | + remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
| 202 | + // poke and prod incoming event till it tells us what it is |
|
| 203 | + if (! $this->setEvent($event)) { |
|
| 204 | + return false; |
|
| 205 | + } |
|
| 206 | + // begin gathering template arguments by getting event status |
|
| 207 | + $template_args = array('event_status' => $this->event->get_active_status()); |
|
| 208 | + if ($this->activeEventAndShowTicketSelector( |
|
| 209 | + $event, |
|
| 210 | + $template_args['event_status'], |
|
| 211 | + $view_details |
|
| 212 | + )) { |
|
| 213 | + return ! is_single() ? $this->displayViewDetailsButton() : ''; |
|
| 214 | + } |
|
| 215 | + // filter the maximum qty that can appear in the Ticket Selector qty dropdowns |
|
| 216 | + $this->setMaxAttendees($this->event->additional_limit()); |
|
| 217 | + if ($this->getMaxAttendees() < 1) { |
|
| 218 | + return $this->ticketSalesClosedMessage(); |
|
| 219 | + } |
|
| 220 | + // is the event expired ? |
|
| 221 | + $template_args['event_is_expired'] = ! is_admin() ? $this->event->is_expired() : false; |
|
| 222 | + if ($template_args['event_is_expired']) { |
|
| 223 | + return $this->expiredEventMessage(); |
|
| 224 | + } |
|
| 225 | + // get all tickets for this event ordered by the datetime |
|
| 226 | + $tickets = $this->getTickets(); |
|
| 227 | + if (count($tickets) < 1) { |
|
| 228 | + return $this->noTicketAvailableMessage(); |
|
| 229 | + } |
|
| 230 | + // redirecting to another site for registration ?? |
|
| 231 | + $external_url = (string) $this->event->external_url() |
|
| 232 | + && $this->event->external_url() !== get_the_permalink() |
|
| 233 | + ? $this->event->external_url() |
|
| 234 | + : ''; |
|
| 235 | + // if redirecting to another site for registration, then we don't load the TS |
|
| 236 | + $ticket_selector = $external_url |
|
| 237 | + ? $this->externalEventRegistration() |
|
| 238 | + : $this->loadTicketSelector($tickets, $template_args); |
|
| 239 | + // now set up the form (but not for the admin) |
|
| 240 | + $ticket_selector = $this->display_full_ui() |
|
| 241 | + ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector |
|
| 242 | + : $ticket_selector; |
|
| 243 | + // submit button and form close tag |
|
| 244 | + $ticket_selector .= $this->display_full_ui() ? $this->displaySubmitButton($external_url) : ''; |
|
| 245 | + return $ticket_selector; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * displayTicketSelector |
|
| 251 | + * examines the event properties and determines whether a Ticket Selector should be displayed |
|
| 252 | + * |
|
| 253 | + * @param WP_Post|int $event |
|
| 254 | + * @param string $_event_active_status |
|
| 255 | + * @param bool $view_details |
|
| 256 | + * @return bool |
|
| 257 | + * @throws EE_Error |
|
| 258 | + */ |
|
| 259 | + protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details) |
|
| 260 | + { |
|
| 261 | + $event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event; |
|
| 262 | + return $this->display_full_ui() |
|
| 263 | + && ( |
|
| 264 | + ! $this->event->display_ticket_selector() |
|
| 265 | + || $view_details |
|
| 266 | + || post_password_required($event_post) |
|
| 267 | + || ( |
|
| 268 | + $_event_active_status !== EE_Datetime::active |
|
| 269 | + && $_event_active_status !== EE_Datetime::upcoming |
|
| 270 | + && $_event_active_status !== EE_Datetime::sold_out |
|
| 271 | + && ! ( |
|
| 272 | + $_event_active_status === EE_Datetime::inactive |
|
| 273 | + && is_user_logged_in() |
|
| 274 | + ) |
|
| 275 | + ) |
|
| 276 | + ); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * noTicketAvailableMessage |
|
| 282 | + * notice displayed if event is expired |
|
| 283 | + * |
|
| 284 | + * @return string |
|
| 285 | + * @throws EE_Error |
|
| 286 | + */ |
|
| 287 | + protected function expiredEventMessage() |
|
| 288 | + { |
|
| 289 | + return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__( |
|
| 290 | + 'We\'re sorry, but all tickets sales have ended because the event is expired.', |
|
| 291 | + 'event_espresso' |
|
| 292 | + ) . '</span></div><!-- .ee-event-expired-notice -->'; |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * noTicketAvailableMessage |
|
| 298 | + * notice displayed if event has no more tickets available |
|
| 299 | + * |
|
| 300 | + * @return string |
|
| 301 | + * @throws EE_Error |
|
| 302 | + */ |
|
| 303 | + protected function noTicketAvailableMessage() |
|
| 304 | + { |
|
| 305 | + $no_ticket_available_msg = esc_html__('We\'re sorry, but all ticket sales have ended.', 'event_espresso'); |
|
| 306 | + if (current_user_can('edit_post', $this->event->ID())) { |
|
| 307 | + $no_ticket_available_msg .= sprintf( |
|
| 308 | + esc_html__( |
|
| 309 | + '%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s', |
|
| 310 | + 'event_espresso' |
|
| 311 | + ), |
|
| 312 | + '<div class="ee-attention" style="text-align: left;"><b>', |
|
| 313 | + '</b><br />', |
|
| 314 | + '<span class="edit-link"><a class="post-edit-link" href="' |
|
| 315 | + . get_edit_post_link($this->event->ID()) |
|
| 316 | + . '">', |
|
| 317 | + '</a></span></div><!-- .ee-attention noTicketAvailableMessage -->' |
|
| 318 | + ); |
|
| 319 | + } |
|
| 320 | + return ' |
|
| 321 | 321 | <div class="ee-event-expired-notice"> |
| 322 | 322 | <span class="important-notice">' . $no_ticket_available_msg . '</span> |
| 323 | 323 | </div><!-- .ee-event-expired-notice -->'; |
| 324 | - } |
|
| 325 | - |
|
| 326 | - |
|
| 327 | - /** |
|
| 328 | - * ticketSalesClosed |
|
| 329 | - * notice displayed if event ticket sales are turned off |
|
| 330 | - * |
|
| 331 | - * @return string |
|
| 332 | - * @throws EE_Error |
|
| 333 | - */ |
|
| 334 | - protected function ticketSalesClosedMessage() |
|
| 335 | - { |
|
| 336 | - $sales_closed_msg = esc_html__( |
|
| 337 | - 'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.', |
|
| 338 | - 'event_espresso' |
|
| 339 | - ); |
|
| 340 | - if (current_user_can('edit_post', $this->event->ID())) { |
|
| 341 | - $sales_closed_msg .= sprintf( |
|
| 342 | - esc_html__( |
|
| 343 | - '%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s', |
|
| 344 | - 'event_espresso' |
|
| 345 | - ), |
|
| 346 | - '<div class="ee-attention" style="text-align: left;"><b>', |
|
| 347 | - '</b><br />', |
|
| 348 | - '<span class="edit-link"><a class="post-edit-link" href="' |
|
| 349 | - . get_edit_post_link($this->event->ID()) |
|
| 350 | - . '">', |
|
| 351 | - '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->' |
|
| 352 | - ); |
|
| 353 | - } |
|
| 354 | - return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>'; |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - |
|
| 358 | - /** |
|
| 359 | - * getTickets |
|
| 360 | - * |
|
| 361 | - * @return \EE_Base_Class[]|\EE_Ticket[] |
|
| 362 | - * @throws EE_Error |
|
| 363 | - * @throws InvalidDataTypeException |
|
| 364 | - * @throws InvalidInterfaceException |
|
| 365 | - * @throws InvalidArgumentException |
|
| 366 | - */ |
|
| 367 | - protected function getTickets() |
|
| 368 | - { |
|
| 369 | - $show_expired_tickets = is_admin() || ( |
|
| 370 | - EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config |
|
| 371 | - && EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets |
|
| 372 | - ); |
|
| 373 | - |
|
| 374 | - $ticket_query_args = array( |
|
| 375 | - array('Datetime.EVT_ID' => $this->event->ID()), |
|
| 376 | - 'order_by' => array( |
|
| 377 | - 'TKT_order' => 'ASC', |
|
| 378 | - 'TKT_required' => 'DESC', |
|
| 379 | - 'TKT_start_date' => 'ASC', |
|
| 380 | - 'TKT_end_date' => 'ASC', |
|
| 381 | - 'Datetime.DTT_EVT_start' => 'DESC', |
|
| 382 | - ), |
|
| 383 | - ); |
|
| 384 | - if (! $show_expired_tickets) { |
|
| 385 | - // use the correct applicable time query depending on what version of core is being run. |
|
| 386 | - $current_time = method_exists('EEM_Datetime', 'current_time_for_query') |
|
| 387 | - ? time() |
|
| 388 | - : current_time('timestamp'); |
|
| 389 | - $ticket_query_args[0]['TKT_end_date'] = array('>', $current_time); |
|
| 390 | - } |
|
| 391 | - return EEM_Ticket::instance()->get_all($ticket_query_args); |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - |
|
| 395 | - /** |
|
| 396 | - * loadTicketSelector |
|
| 397 | - * begins to assemble template arguments |
|
| 398 | - * and decides whether to load a "simple" ticket selector, or the standard |
|
| 399 | - * |
|
| 400 | - * @param \EE_Ticket[] $tickets |
|
| 401 | - * @param array $template_args |
|
| 402 | - * @return string |
|
| 403 | - * @throws EE_Error |
|
| 404 | - */ |
|
| 405 | - protected function loadTicketSelector(array $tickets, array $template_args) |
|
| 406 | - { |
|
| 407 | - $template_args['event'] = $this->event; |
|
| 408 | - $template_args['EVT_ID'] = $this->event->ID(); |
|
| 409 | - $template_args['event_is_expired'] = $this->event->is_expired(); |
|
| 410 | - $template_args['max_atndz'] = $this->getMaxAttendees(); |
|
| 411 | - $template_args['date_format'] = $this->date_format; |
|
| 412 | - $template_args['time_format'] = $this->time_format; |
|
| 413 | - /** |
|
| 414 | - * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected |
|
| 415 | - * |
|
| 416 | - * @since 4.9.13 |
|
| 417 | - * @param string '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to |
|
| 418 | - * @param int $EVT_ID The Event ID |
|
| 419 | - */ |
|
| 420 | - $template_args['anchor_id'] = apply_filters( |
|
| 421 | - 'FHEE__EE_Ticket_Selector__redirect_anchor_id', |
|
| 422 | - '#tkt-slctr-tbl-' . $this->event->ID(), |
|
| 423 | - $this->event->ID() |
|
| 424 | - ); |
|
| 425 | - $template_args['tickets'] = $tickets; |
|
| 426 | - $template_args['ticket_count'] = count($tickets); |
|
| 427 | - $ticket_selector = $this->simpleTicketSelector($tickets, $template_args); |
|
| 428 | - return $ticket_selector instanceof TicketSelectorSimple |
|
| 429 | - ? $ticket_selector |
|
| 430 | - : new TicketSelectorStandard( |
|
| 431 | - $this->event, |
|
| 432 | - $tickets, |
|
| 433 | - $this->getMaxAttendees(), |
|
| 434 | - $template_args, |
|
| 435 | - $this->date_format, |
|
| 436 | - $this->time_format |
|
| 437 | - ); |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - |
|
| 441 | - /** |
|
| 442 | - * simpleTicketSelector |
|
| 443 | - * there's one ticket, and max attendees is set to one, |
|
| 444 | - * so if the event is free, then this is a "simple" ticket selector |
|
| 445 | - * a.k.a. "Dude Where's my Ticket Selector?" |
|
| 446 | - * |
|
| 447 | - * @param \EE_Ticket[] $tickets |
|
| 448 | - * @param array $template_args |
|
| 449 | - * @return string |
|
| 450 | - * @throws EE_Error |
|
| 451 | - */ |
|
| 452 | - protected function simpleTicketSelector($tickets, array $template_args) |
|
| 453 | - { |
|
| 454 | - // if there is only ONE ticket with a max qty of ONE |
|
| 455 | - if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) { |
|
| 456 | - return ''; |
|
| 457 | - } |
|
| 458 | - /** @var \EE_Ticket $ticket */ |
|
| 459 | - $ticket = reset($tickets); |
|
| 460 | - // if the ticket is free... then not much need for the ticket selector |
|
| 461 | - if (apply_filters( |
|
| 462 | - 'FHEE__ticket_selector_chart_template__hide_ticket_selector', |
|
| 463 | - $ticket->is_free(), |
|
| 464 | - $this->event->ID() |
|
| 465 | - )) { |
|
| 466 | - return new TicketSelectorSimple( |
|
| 467 | - $this->event, |
|
| 468 | - $ticket, |
|
| 469 | - $this->getMaxAttendees(), |
|
| 470 | - $template_args |
|
| 471 | - ); |
|
| 472 | - } |
|
| 473 | - return ''; |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - |
|
| 477 | - /** |
|
| 478 | - * externalEventRegistration |
|
| 479 | - * |
|
| 480 | - * @return string |
|
| 481 | - */ |
|
| 482 | - public function externalEventRegistration() |
|
| 483 | - { |
|
| 484 | - // if not we still need to trigger the display of the submit button |
|
| 485 | - add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
| 486 | - // display notice to admin that registration is external |
|
| 487 | - return $this->display_full_ui() |
|
| 488 | - ? esc_html__( |
|
| 489 | - 'Registration is at an external URL for this event.', |
|
| 490 | - 'event_espresso' |
|
| 491 | - ) |
|
| 492 | - : ''; |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - |
|
| 496 | - /** |
|
| 497 | - * formOpen |
|
| 498 | - * |
|
| 499 | - * @param int $ID |
|
| 500 | - * @param string $external_url |
|
| 501 | - * @return string |
|
| 502 | - */ |
|
| 503 | - public function formOpen($ID = 0, $external_url = '') |
|
| 504 | - { |
|
| 505 | - // if redirecting, we don't need any anything else |
|
| 506 | - if ($external_url) { |
|
| 507 | - $html = '<form method="GET" '; |
|
| 508 | - $html .= 'action="' . EEH_URL::refactor_url($external_url) . '" '; |
|
| 509 | - $html .= 'name="ticket-selector-form-' . $ID . '"'; |
|
| 510 | - // open link in new window ? |
|
| 511 | - $html .= apply_filters( |
|
| 512 | - 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank', |
|
| 513 | - $this->isIframe(), |
|
| 514 | - $this |
|
| 515 | - ) |
|
| 516 | - ? ' target="_blank"' |
|
| 517 | - : ''; |
|
| 518 | - $html .= '>'; |
|
| 519 | - $query_args = EEH_URL::get_query_string($external_url); |
|
| 520 | - foreach ((array) $query_args as $query_arg => $value) { |
|
| 521 | - $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">'; |
|
| 522 | - } |
|
| 523 | - return $html; |
|
| 524 | - } |
|
| 525 | - // if there is no submit button, then don't start building a form |
|
| 526 | - // because the "View Details" button will build its own form |
|
| 527 | - if (! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
| 528 | - return ''; |
|
| 529 | - } |
|
| 530 | - $checkout_url = EEH_Event_View::event_link_url($ID); |
|
| 531 | - if (! $checkout_url) { |
|
| 532 | - EE_Error::add_error( |
|
| 533 | - esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'), |
|
| 534 | - __FILE__, |
|
| 535 | - __FUNCTION__, |
|
| 536 | - __LINE__ |
|
| 537 | - ); |
|
| 538 | - } |
|
| 539 | - // set no cache headers and constants |
|
| 540 | - EE_System::do_not_cache(); |
|
| 541 | - $html = '<form method="POST" '; |
|
| 542 | - $html .= 'action="' . $checkout_url . '" '; |
|
| 543 | - $html .= 'name="ticket-selector-form-' . $ID . '"'; |
|
| 544 | - $html .= $this->iframe ? ' target="_blank"' : ''; |
|
| 545 | - $html .= '>'; |
|
| 546 | - $html .= '<input type="hidden" name="ee" value="process_ticket_selections">'; |
|
| 547 | - $html = apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event); |
|
| 548 | - return $html; |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - |
|
| 552 | - /** |
|
| 553 | - * displaySubmitButton |
|
| 554 | - * |
|
| 555 | - * @param string $external_url |
|
| 556 | - * @return string |
|
| 557 | - * @throws EE_Error |
|
| 558 | - */ |
|
| 559 | - public function displaySubmitButton($external_url = '') |
|
| 560 | - { |
|
| 561 | - $html = ''; |
|
| 562 | - if ($this->display_full_ui()) { |
|
| 563 | - // standard TS displayed with submit button, ie: "Register Now" |
|
| 564 | - if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
| 565 | - $html .= $this->displayRegisterNowButton(); |
|
| 566 | - $html .= empty($external_url) |
|
| 567 | - ? $this->ticketSelectorEndDiv() |
|
| 568 | - : $this->clearTicketSelector(); |
|
| 569 | - $html .= '<br/>' . $this->formClose(); |
|
| 570 | - } elseif ($this->getMaxAttendees() === 1) { |
|
| 571 | - // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1) |
|
| 572 | - if ($this->event->is_sold_out()) { |
|
| 573 | - // then instead of a View Details or Submit button, just display a "Sold Out" message |
|
| 574 | - $html .= apply_filters( |
|
| 575 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg', |
|
| 576 | - sprintf( |
|
| 577 | - __( |
|
| 578 | - '%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s', |
|
| 579 | - 'event_espresso' |
|
| 580 | - ), |
|
| 581 | - '<p class="no-ticket-selector-msg clear-float">', |
|
| 582 | - $this->event->name(), |
|
| 583 | - '</p>', |
|
| 584 | - '<br />' |
|
| 585 | - ), |
|
| 586 | - $this->event |
|
| 587 | - ); |
|
| 588 | - if (apply_filters( |
|
| 589 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
| 590 | - false, |
|
| 591 | - $this->event |
|
| 592 | - )) { |
|
| 593 | - $html .= $this->displayRegisterNowButton(); |
|
| 594 | - } |
|
| 595 | - // sold out DWMTS event, no TS, no submit or view details button, but has additional content |
|
| 596 | - $html .= $this->ticketSelectorEndDiv(); |
|
| 597 | - } elseif (apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false) |
|
| 598 | - && ! is_single() |
|
| 599 | - ) { |
|
| 600 | - // this is a "Dude Where's my Ticket Selector?" (DWMTS) type event, |
|
| 601 | - // but no tickets are available, so display event's "View Details" button. |
|
| 602 | - // it is being viewed via somewhere other than a single post |
|
| 603 | - $html .= $this->displayViewDetailsButton(true); |
|
| 604 | - } else { |
|
| 605 | - $html .= $this->ticketSelectorEndDiv(); |
|
| 606 | - } |
|
| 607 | - } elseif (is_archive()) { |
|
| 608 | - // event list, no tickets available so display event's "View Details" button |
|
| 609 | - $html .= $this->ticketSelectorEndDiv(); |
|
| 610 | - $html .= $this->displayViewDetailsButton(); |
|
| 611 | - } else { |
|
| 612 | - if (apply_filters( |
|
| 613 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
| 614 | - false, |
|
| 615 | - $this->event |
|
| 616 | - )) { |
|
| 617 | - $html .= $this->displayRegisterNowButton(); |
|
| 618 | - } |
|
| 619 | - // no submit or view details button, and no additional content |
|
| 620 | - $html .= $this->ticketSelectorEndDiv(); |
|
| 621 | - } |
|
| 622 | - if (! $this->iframe && ! is_archive()) { |
|
| 623 | - $html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector')); |
|
| 624 | - } |
|
| 625 | - } |
|
| 626 | - return apply_filters( |
|
| 627 | - 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displaySubmitButton__html', |
|
| 628 | - $html, |
|
| 629 | - $this->event, |
|
| 630 | - $this |
|
| 631 | - ); |
|
| 632 | - } |
|
| 633 | - |
|
| 634 | - |
|
| 635 | - /** |
|
| 636 | - * @return string |
|
| 637 | - * @throws EE_Error |
|
| 638 | - */ |
|
| 639 | - public function displayRegisterNowButton() |
|
| 640 | - { |
|
| 641 | - $btn_text = apply_filters( |
|
| 642 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text', |
|
| 643 | - __('Register Now', 'event_espresso'), |
|
| 644 | - $this->event |
|
| 645 | - ); |
|
| 646 | - $external_url = (string) $this->event->external_url() |
|
| 647 | - && $this->event->external_url() !== get_the_permalink() |
|
| 648 | - ? $this->event->external_url() |
|
| 649 | - : ''; |
|
| 650 | - $html = EEH_HTML::div( |
|
| 651 | - '', |
|
| 652 | - 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', |
|
| 653 | - 'ticket-selector-submit-btn-wrap' |
|
| 654 | - ); |
|
| 655 | - $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"'; |
|
| 656 | - $html .= ' class="ticket-selector-submit-btn '; |
|
| 657 | - $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"'; |
|
| 658 | - $html .= ' type="submit" value="' . $btn_text . '" data-ee-disable-after-recaptcha="true" />'; |
|
| 659 | - $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->'; |
|
| 660 | - $html .= apply_filters( |
|
| 661 | - 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
|
| 662 | - '', |
|
| 663 | - $this->event, |
|
| 664 | - $this->iframe |
|
| 665 | - ); |
|
| 666 | - return $html; |
|
| 667 | - } |
|
| 668 | - |
|
| 669 | - |
|
| 670 | - /** |
|
| 671 | - * displayViewDetailsButton |
|
| 672 | - * |
|
| 673 | - * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event |
|
| 674 | - * (ie: $_max_atndz === 1) where there are no available tickets, |
|
| 675 | - * either because they are sold out, expired, or not yet on sale. |
|
| 676 | - * In this case, we need to close the form BEFORE adding any closing divs |
|
| 677 | - * @return string |
|
| 678 | - * @throws EE_Error |
|
| 679 | - */ |
|
| 680 | - public function displayViewDetailsButton($DWMTS = false) |
|
| 681 | - { |
|
| 682 | - if (! $this->event->get_permalink()) { |
|
| 683 | - EE_Error::add_error( |
|
| 684 | - esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'), |
|
| 685 | - __FILE__, |
|
| 686 | - __FUNCTION__, |
|
| 687 | - __LINE__ |
|
| 688 | - ); |
|
| 689 | - } |
|
| 690 | - $view_details_btn = '<form method="GET" action="'; |
|
| 691 | - $view_details_btn .= apply_filters( |
|
| 692 | - 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url', |
|
| 693 | - $this->event->get_permalink(), |
|
| 694 | - $this->event |
|
| 695 | - ); |
|
| 696 | - $view_details_btn .= '"'; |
|
| 697 | - // open link in new window ? |
|
| 698 | - $view_details_btn .= apply_filters( |
|
| 699 | - 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank', |
|
| 700 | - $this->isIframe(), |
|
| 701 | - $this |
|
| 702 | - ) |
|
| 703 | - ? ' target="_blank"' |
|
| 704 | - : ''; |
|
| 705 | - $view_details_btn .= '>'; |
|
| 706 | - $btn_text = apply_filters( |
|
| 707 | - 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text', |
|
| 708 | - esc_html__('View Details', 'event_espresso'), |
|
| 709 | - $this->event |
|
| 710 | - ); |
|
| 711 | - $view_details_btn .= '<input id="ticket-selector-submit-' |
|
| 712 | - . $this->event->ID() |
|
| 713 | - . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="' |
|
| 714 | - . $btn_text |
|
| 715 | - . '" />'; |
|
| 716 | - $view_details_btn .= apply_filters('FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event); |
|
| 717 | - if ($DWMTS) { |
|
| 718 | - $view_details_btn .= $this->formClose(); |
|
| 719 | - $view_details_btn .= $this->ticketSelectorEndDiv(); |
|
| 720 | - $view_details_btn .= '<br/>'; |
|
| 721 | - } else { |
|
| 722 | - $view_details_btn .= $this->clearTicketSelector(); |
|
| 723 | - $view_details_btn .= '<br/>'; |
|
| 724 | - $view_details_btn .= $this->formClose(); |
|
| 725 | - } |
|
| 726 | - return $view_details_btn; |
|
| 727 | - } |
|
| 728 | - |
|
| 729 | - |
|
| 730 | - /** |
|
| 731 | - * @return string |
|
| 732 | - */ |
|
| 733 | - public function ticketSelectorEndDiv() |
|
| 734 | - { |
|
| 735 | - return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->'; |
|
| 736 | - } |
|
| 737 | - |
|
| 738 | - |
|
| 739 | - /** |
|
| 740 | - * @return string |
|
| 741 | - */ |
|
| 742 | - public function clearTicketSelector() |
|
| 743 | - { |
|
| 744 | - // standard TS displayed, appears after a "Register Now" or "view Details" button |
|
| 745 | - return '<div class="clear"></div><!-- clearTicketSelector -->'; |
|
| 746 | - } |
|
| 747 | - |
|
| 748 | - |
|
| 749 | - /** |
|
| 750 | - * @access public |
|
| 751 | - * @return string |
|
| 752 | - */ |
|
| 753 | - public function formClose() |
|
| 754 | - { |
|
| 755 | - return '</form>'; |
|
| 756 | - } |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + |
|
| 327 | + /** |
|
| 328 | + * ticketSalesClosed |
|
| 329 | + * notice displayed if event ticket sales are turned off |
|
| 330 | + * |
|
| 331 | + * @return string |
|
| 332 | + * @throws EE_Error |
|
| 333 | + */ |
|
| 334 | + protected function ticketSalesClosedMessage() |
|
| 335 | + { |
|
| 336 | + $sales_closed_msg = esc_html__( |
|
| 337 | + 'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.', |
|
| 338 | + 'event_espresso' |
|
| 339 | + ); |
|
| 340 | + if (current_user_can('edit_post', $this->event->ID())) { |
|
| 341 | + $sales_closed_msg .= sprintf( |
|
| 342 | + esc_html__( |
|
| 343 | + '%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s', |
|
| 344 | + 'event_espresso' |
|
| 345 | + ), |
|
| 346 | + '<div class="ee-attention" style="text-align: left;"><b>', |
|
| 347 | + '</b><br />', |
|
| 348 | + '<span class="edit-link"><a class="post-edit-link" href="' |
|
| 349 | + . get_edit_post_link($this->event->ID()) |
|
| 350 | + . '">', |
|
| 351 | + '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->' |
|
| 352 | + ); |
|
| 353 | + } |
|
| 354 | + return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>'; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + |
|
| 358 | + /** |
|
| 359 | + * getTickets |
|
| 360 | + * |
|
| 361 | + * @return \EE_Base_Class[]|\EE_Ticket[] |
|
| 362 | + * @throws EE_Error |
|
| 363 | + * @throws InvalidDataTypeException |
|
| 364 | + * @throws InvalidInterfaceException |
|
| 365 | + * @throws InvalidArgumentException |
|
| 366 | + */ |
|
| 367 | + protected function getTickets() |
|
| 368 | + { |
|
| 369 | + $show_expired_tickets = is_admin() || ( |
|
| 370 | + EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config |
|
| 371 | + && EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets |
|
| 372 | + ); |
|
| 373 | + |
|
| 374 | + $ticket_query_args = array( |
|
| 375 | + array('Datetime.EVT_ID' => $this->event->ID()), |
|
| 376 | + 'order_by' => array( |
|
| 377 | + 'TKT_order' => 'ASC', |
|
| 378 | + 'TKT_required' => 'DESC', |
|
| 379 | + 'TKT_start_date' => 'ASC', |
|
| 380 | + 'TKT_end_date' => 'ASC', |
|
| 381 | + 'Datetime.DTT_EVT_start' => 'DESC', |
|
| 382 | + ), |
|
| 383 | + ); |
|
| 384 | + if (! $show_expired_tickets) { |
|
| 385 | + // use the correct applicable time query depending on what version of core is being run. |
|
| 386 | + $current_time = method_exists('EEM_Datetime', 'current_time_for_query') |
|
| 387 | + ? time() |
|
| 388 | + : current_time('timestamp'); |
|
| 389 | + $ticket_query_args[0]['TKT_end_date'] = array('>', $current_time); |
|
| 390 | + } |
|
| 391 | + return EEM_Ticket::instance()->get_all($ticket_query_args); |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + |
|
| 395 | + /** |
|
| 396 | + * loadTicketSelector |
|
| 397 | + * begins to assemble template arguments |
|
| 398 | + * and decides whether to load a "simple" ticket selector, or the standard |
|
| 399 | + * |
|
| 400 | + * @param \EE_Ticket[] $tickets |
|
| 401 | + * @param array $template_args |
|
| 402 | + * @return string |
|
| 403 | + * @throws EE_Error |
|
| 404 | + */ |
|
| 405 | + protected function loadTicketSelector(array $tickets, array $template_args) |
|
| 406 | + { |
|
| 407 | + $template_args['event'] = $this->event; |
|
| 408 | + $template_args['EVT_ID'] = $this->event->ID(); |
|
| 409 | + $template_args['event_is_expired'] = $this->event->is_expired(); |
|
| 410 | + $template_args['max_atndz'] = $this->getMaxAttendees(); |
|
| 411 | + $template_args['date_format'] = $this->date_format; |
|
| 412 | + $template_args['time_format'] = $this->time_format; |
|
| 413 | + /** |
|
| 414 | + * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected |
|
| 415 | + * |
|
| 416 | + * @since 4.9.13 |
|
| 417 | + * @param string '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to |
|
| 418 | + * @param int $EVT_ID The Event ID |
|
| 419 | + */ |
|
| 420 | + $template_args['anchor_id'] = apply_filters( |
|
| 421 | + 'FHEE__EE_Ticket_Selector__redirect_anchor_id', |
|
| 422 | + '#tkt-slctr-tbl-' . $this->event->ID(), |
|
| 423 | + $this->event->ID() |
|
| 424 | + ); |
|
| 425 | + $template_args['tickets'] = $tickets; |
|
| 426 | + $template_args['ticket_count'] = count($tickets); |
|
| 427 | + $ticket_selector = $this->simpleTicketSelector($tickets, $template_args); |
|
| 428 | + return $ticket_selector instanceof TicketSelectorSimple |
|
| 429 | + ? $ticket_selector |
|
| 430 | + : new TicketSelectorStandard( |
|
| 431 | + $this->event, |
|
| 432 | + $tickets, |
|
| 433 | + $this->getMaxAttendees(), |
|
| 434 | + $template_args, |
|
| 435 | + $this->date_format, |
|
| 436 | + $this->time_format |
|
| 437 | + ); |
|
| 438 | + } |
|
| 439 | + |
|
| 440 | + |
|
| 441 | + /** |
|
| 442 | + * simpleTicketSelector |
|
| 443 | + * there's one ticket, and max attendees is set to one, |
|
| 444 | + * so if the event is free, then this is a "simple" ticket selector |
|
| 445 | + * a.k.a. "Dude Where's my Ticket Selector?" |
|
| 446 | + * |
|
| 447 | + * @param \EE_Ticket[] $tickets |
|
| 448 | + * @param array $template_args |
|
| 449 | + * @return string |
|
| 450 | + * @throws EE_Error |
|
| 451 | + */ |
|
| 452 | + protected function simpleTicketSelector($tickets, array $template_args) |
|
| 453 | + { |
|
| 454 | + // if there is only ONE ticket with a max qty of ONE |
|
| 455 | + if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) { |
|
| 456 | + return ''; |
|
| 457 | + } |
|
| 458 | + /** @var \EE_Ticket $ticket */ |
|
| 459 | + $ticket = reset($tickets); |
|
| 460 | + // if the ticket is free... then not much need for the ticket selector |
|
| 461 | + if (apply_filters( |
|
| 462 | + 'FHEE__ticket_selector_chart_template__hide_ticket_selector', |
|
| 463 | + $ticket->is_free(), |
|
| 464 | + $this->event->ID() |
|
| 465 | + )) { |
|
| 466 | + return new TicketSelectorSimple( |
|
| 467 | + $this->event, |
|
| 468 | + $ticket, |
|
| 469 | + $this->getMaxAttendees(), |
|
| 470 | + $template_args |
|
| 471 | + ); |
|
| 472 | + } |
|
| 473 | + return ''; |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + |
|
| 477 | + /** |
|
| 478 | + * externalEventRegistration |
|
| 479 | + * |
|
| 480 | + * @return string |
|
| 481 | + */ |
|
| 482 | + public function externalEventRegistration() |
|
| 483 | + { |
|
| 484 | + // if not we still need to trigger the display of the submit button |
|
| 485 | + add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
| 486 | + // display notice to admin that registration is external |
|
| 487 | + return $this->display_full_ui() |
|
| 488 | + ? esc_html__( |
|
| 489 | + 'Registration is at an external URL for this event.', |
|
| 490 | + 'event_espresso' |
|
| 491 | + ) |
|
| 492 | + : ''; |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + |
|
| 496 | + /** |
|
| 497 | + * formOpen |
|
| 498 | + * |
|
| 499 | + * @param int $ID |
|
| 500 | + * @param string $external_url |
|
| 501 | + * @return string |
|
| 502 | + */ |
|
| 503 | + public function formOpen($ID = 0, $external_url = '') |
|
| 504 | + { |
|
| 505 | + // if redirecting, we don't need any anything else |
|
| 506 | + if ($external_url) { |
|
| 507 | + $html = '<form method="GET" '; |
|
| 508 | + $html .= 'action="' . EEH_URL::refactor_url($external_url) . '" '; |
|
| 509 | + $html .= 'name="ticket-selector-form-' . $ID . '"'; |
|
| 510 | + // open link in new window ? |
|
| 511 | + $html .= apply_filters( |
|
| 512 | + 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank', |
|
| 513 | + $this->isIframe(), |
|
| 514 | + $this |
|
| 515 | + ) |
|
| 516 | + ? ' target="_blank"' |
|
| 517 | + : ''; |
|
| 518 | + $html .= '>'; |
|
| 519 | + $query_args = EEH_URL::get_query_string($external_url); |
|
| 520 | + foreach ((array) $query_args as $query_arg => $value) { |
|
| 521 | + $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">'; |
|
| 522 | + } |
|
| 523 | + return $html; |
|
| 524 | + } |
|
| 525 | + // if there is no submit button, then don't start building a form |
|
| 526 | + // because the "View Details" button will build its own form |
|
| 527 | + if (! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
| 528 | + return ''; |
|
| 529 | + } |
|
| 530 | + $checkout_url = EEH_Event_View::event_link_url($ID); |
|
| 531 | + if (! $checkout_url) { |
|
| 532 | + EE_Error::add_error( |
|
| 533 | + esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'), |
|
| 534 | + __FILE__, |
|
| 535 | + __FUNCTION__, |
|
| 536 | + __LINE__ |
|
| 537 | + ); |
|
| 538 | + } |
|
| 539 | + // set no cache headers and constants |
|
| 540 | + EE_System::do_not_cache(); |
|
| 541 | + $html = '<form method="POST" '; |
|
| 542 | + $html .= 'action="' . $checkout_url . '" '; |
|
| 543 | + $html .= 'name="ticket-selector-form-' . $ID . '"'; |
|
| 544 | + $html .= $this->iframe ? ' target="_blank"' : ''; |
|
| 545 | + $html .= '>'; |
|
| 546 | + $html .= '<input type="hidden" name="ee" value="process_ticket_selections">'; |
|
| 547 | + $html = apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event); |
|
| 548 | + return $html; |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + |
|
| 552 | + /** |
|
| 553 | + * displaySubmitButton |
|
| 554 | + * |
|
| 555 | + * @param string $external_url |
|
| 556 | + * @return string |
|
| 557 | + * @throws EE_Error |
|
| 558 | + */ |
|
| 559 | + public function displaySubmitButton($external_url = '') |
|
| 560 | + { |
|
| 561 | + $html = ''; |
|
| 562 | + if ($this->display_full_ui()) { |
|
| 563 | + // standard TS displayed with submit button, ie: "Register Now" |
|
| 564 | + if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
| 565 | + $html .= $this->displayRegisterNowButton(); |
|
| 566 | + $html .= empty($external_url) |
|
| 567 | + ? $this->ticketSelectorEndDiv() |
|
| 568 | + : $this->clearTicketSelector(); |
|
| 569 | + $html .= '<br/>' . $this->formClose(); |
|
| 570 | + } elseif ($this->getMaxAttendees() === 1) { |
|
| 571 | + // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1) |
|
| 572 | + if ($this->event->is_sold_out()) { |
|
| 573 | + // then instead of a View Details or Submit button, just display a "Sold Out" message |
|
| 574 | + $html .= apply_filters( |
|
| 575 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg', |
|
| 576 | + sprintf( |
|
| 577 | + __( |
|
| 578 | + '%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s', |
|
| 579 | + 'event_espresso' |
|
| 580 | + ), |
|
| 581 | + '<p class="no-ticket-selector-msg clear-float">', |
|
| 582 | + $this->event->name(), |
|
| 583 | + '</p>', |
|
| 584 | + '<br />' |
|
| 585 | + ), |
|
| 586 | + $this->event |
|
| 587 | + ); |
|
| 588 | + if (apply_filters( |
|
| 589 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
| 590 | + false, |
|
| 591 | + $this->event |
|
| 592 | + )) { |
|
| 593 | + $html .= $this->displayRegisterNowButton(); |
|
| 594 | + } |
|
| 595 | + // sold out DWMTS event, no TS, no submit or view details button, but has additional content |
|
| 596 | + $html .= $this->ticketSelectorEndDiv(); |
|
| 597 | + } elseif (apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false) |
|
| 598 | + && ! is_single() |
|
| 599 | + ) { |
|
| 600 | + // this is a "Dude Where's my Ticket Selector?" (DWMTS) type event, |
|
| 601 | + // but no tickets are available, so display event's "View Details" button. |
|
| 602 | + // it is being viewed via somewhere other than a single post |
|
| 603 | + $html .= $this->displayViewDetailsButton(true); |
|
| 604 | + } else { |
|
| 605 | + $html .= $this->ticketSelectorEndDiv(); |
|
| 606 | + } |
|
| 607 | + } elseif (is_archive()) { |
|
| 608 | + // event list, no tickets available so display event's "View Details" button |
|
| 609 | + $html .= $this->ticketSelectorEndDiv(); |
|
| 610 | + $html .= $this->displayViewDetailsButton(); |
|
| 611 | + } else { |
|
| 612 | + if (apply_filters( |
|
| 613 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
| 614 | + false, |
|
| 615 | + $this->event |
|
| 616 | + )) { |
|
| 617 | + $html .= $this->displayRegisterNowButton(); |
|
| 618 | + } |
|
| 619 | + // no submit or view details button, and no additional content |
|
| 620 | + $html .= $this->ticketSelectorEndDiv(); |
|
| 621 | + } |
|
| 622 | + if (! $this->iframe && ! is_archive()) { |
|
| 623 | + $html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector')); |
|
| 624 | + } |
|
| 625 | + } |
|
| 626 | + return apply_filters( |
|
| 627 | + 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displaySubmitButton__html', |
|
| 628 | + $html, |
|
| 629 | + $this->event, |
|
| 630 | + $this |
|
| 631 | + ); |
|
| 632 | + } |
|
| 633 | + |
|
| 634 | + |
|
| 635 | + /** |
|
| 636 | + * @return string |
|
| 637 | + * @throws EE_Error |
|
| 638 | + */ |
|
| 639 | + public function displayRegisterNowButton() |
|
| 640 | + { |
|
| 641 | + $btn_text = apply_filters( |
|
| 642 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text', |
|
| 643 | + __('Register Now', 'event_espresso'), |
|
| 644 | + $this->event |
|
| 645 | + ); |
|
| 646 | + $external_url = (string) $this->event->external_url() |
|
| 647 | + && $this->event->external_url() !== get_the_permalink() |
|
| 648 | + ? $this->event->external_url() |
|
| 649 | + : ''; |
|
| 650 | + $html = EEH_HTML::div( |
|
| 651 | + '', |
|
| 652 | + 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', |
|
| 653 | + 'ticket-selector-submit-btn-wrap' |
|
| 654 | + ); |
|
| 655 | + $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"'; |
|
| 656 | + $html .= ' class="ticket-selector-submit-btn '; |
|
| 657 | + $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"'; |
|
| 658 | + $html .= ' type="submit" value="' . $btn_text . '" data-ee-disable-after-recaptcha="true" />'; |
|
| 659 | + $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->'; |
|
| 660 | + $html .= apply_filters( |
|
| 661 | + 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
|
| 662 | + '', |
|
| 663 | + $this->event, |
|
| 664 | + $this->iframe |
|
| 665 | + ); |
|
| 666 | + return $html; |
|
| 667 | + } |
|
| 668 | + |
|
| 669 | + |
|
| 670 | + /** |
|
| 671 | + * displayViewDetailsButton |
|
| 672 | + * |
|
| 673 | + * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event |
|
| 674 | + * (ie: $_max_atndz === 1) where there are no available tickets, |
|
| 675 | + * either because they are sold out, expired, or not yet on sale. |
|
| 676 | + * In this case, we need to close the form BEFORE adding any closing divs |
|
| 677 | + * @return string |
|
| 678 | + * @throws EE_Error |
|
| 679 | + */ |
|
| 680 | + public function displayViewDetailsButton($DWMTS = false) |
|
| 681 | + { |
|
| 682 | + if (! $this->event->get_permalink()) { |
|
| 683 | + EE_Error::add_error( |
|
| 684 | + esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'), |
|
| 685 | + __FILE__, |
|
| 686 | + __FUNCTION__, |
|
| 687 | + __LINE__ |
|
| 688 | + ); |
|
| 689 | + } |
|
| 690 | + $view_details_btn = '<form method="GET" action="'; |
|
| 691 | + $view_details_btn .= apply_filters( |
|
| 692 | + 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url', |
|
| 693 | + $this->event->get_permalink(), |
|
| 694 | + $this->event |
|
| 695 | + ); |
|
| 696 | + $view_details_btn .= '"'; |
|
| 697 | + // open link in new window ? |
|
| 698 | + $view_details_btn .= apply_filters( |
|
| 699 | + 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank', |
|
| 700 | + $this->isIframe(), |
|
| 701 | + $this |
|
| 702 | + ) |
|
| 703 | + ? ' target="_blank"' |
|
| 704 | + : ''; |
|
| 705 | + $view_details_btn .= '>'; |
|
| 706 | + $btn_text = apply_filters( |
|
| 707 | + 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text', |
|
| 708 | + esc_html__('View Details', 'event_espresso'), |
|
| 709 | + $this->event |
|
| 710 | + ); |
|
| 711 | + $view_details_btn .= '<input id="ticket-selector-submit-' |
|
| 712 | + . $this->event->ID() |
|
| 713 | + . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="' |
|
| 714 | + . $btn_text |
|
| 715 | + . '" />'; |
|
| 716 | + $view_details_btn .= apply_filters('FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event); |
|
| 717 | + if ($DWMTS) { |
|
| 718 | + $view_details_btn .= $this->formClose(); |
|
| 719 | + $view_details_btn .= $this->ticketSelectorEndDiv(); |
|
| 720 | + $view_details_btn .= '<br/>'; |
|
| 721 | + } else { |
|
| 722 | + $view_details_btn .= $this->clearTicketSelector(); |
|
| 723 | + $view_details_btn .= '<br/>'; |
|
| 724 | + $view_details_btn .= $this->formClose(); |
|
| 725 | + } |
|
| 726 | + return $view_details_btn; |
|
| 727 | + } |
|
| 728 | + |
|
| 729 | + |
|
| 730 | + /** |
|
| 731 | + * @return string |
|
| 732 | + */ |
|
| 733 | + public function ticketSelectorEndDiv() |
|
| 734 | + { |
|
| 735 | + return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->'; |
|
| 736 | + } |
|
| 737 | + |
|
| 738 | + |
|
| 739 | + /** |
|
| 740 | + * @return string |
|
| 741 | + */ |
|
| 742 | + public function clearTicketSelector() |
|
| 743 | + { |
|
| 744 | + // standard TS displayed, appears after a "Register Now" or "view Details" button |
|
| 745 | + return '<div class="clear"></div><!-- clearTicketSelector -->'; |
|
| 746 | + } |
|
| 747 | + |
|
| 748 | + |
|
| 749 | + /** |
|
| 750 | + * @access public |
|
| 751 | + * @return string |
|
| 752 | + */ |
|
| 753 | + public function formClose() |
|
| 754 | + { |
|
| 755 | + return '</form>'; |
|
| 756 | + } |
|
| 757 | 757 | } |
@@ -13,1702 +13,1702 @@ |
||
| 13 | 13 | class EE_Transaction extends EE_Base_Class implements EEI_Transaction |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * The length of time in seconds that a lock is applied before being considered expired. |
|
| 18 | - * It is not long because a transaction should only be locked for the duration of the request that locked it |
|
| 19 | - */ |
|
| 20 | - const LOCK_EXPIRATION = 2; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * txn status upon initial construction. |
|
| 24 | - * |
|
| 25 | - * @var string |
|
| 26 | - */ |
|
| 27 | - protected $_old_txn_status; |
|
| 28 | - |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @param array $props_n_values incoming values |
|
| 32 | - * @param string $timezone incoming timezone |
|
| 33 | - * (if not set the timezone set for the website will be used.) |
|
| 34 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 35 | - * date_format and the second value is the time format |
|
| 36 | - * @return EE_Transaction |
|
| 37 | - * @throws EE_Error |
|
| 38 | - * @throws InvalidArgumentException |
|
| 39 | - * @throws InvalidDataTypeException |
|
| 40 | - * @throws InvalidInterfaceException |
|
| 41 | - * @throws ReflectionException |
|
| 42 | - */ |
|
| 43 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 44 | - { |
|
| 45 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 46 | - $txn = $has_object |
|
| 47 | - ? $has_object |
|
| 48 | - : new self($props_n_values, false, $timezone, $date_formats); |
|
| 49 | - if (! $has_object) { |
|
| 50 | - $txn->set_old_txn_status($txn->status_ID()); |
|
| 51 | - } |
|
| 52 | - return $txn; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @param array $props_n_values incoming values from the database |
|
| 58 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 59 | - * the website will be used. |
|
| 60 | - * @return EE_Transaction |
|
| 61 | - * @throws EE_Error |
|
| 62 | - * @throws InvalidArgumentException |
|
| 63 | - * @throws InvalidDataTypeException |
|
| 64 | - * @throws InvalidInterfaceException |
|
| 65 | - * @throws ReflectionException |
|
| 66 | - */ |
|
| 67 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 68 | - { |
|
| 69 | - $txn = new self($props_n_values, true, $timezone); |
|
| 70 | - $txn->set_old_txn_status($txn->status_ID()); |
|
| 71 | - return $txn; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Sets a meta field indicating that this TXN is locked and should not be updated in the db. |
|
| 77 | - * If a lock has already been set, then we will attempt to remove it in case it has expired. |
|
| 78 | - * If that also fails, then an exception is thrown. |
|
| 79 | - * |
|
| 80 | - * @throws EE_Error |
|
| 81 | - * @throws InvalidArgumentException |
|
| 82 | - * @throws InvalidDataTypeException |
|
| 83 | - * @throws InvalidInterfaceException |
|
| 84 | - * @throws ReflectionException |
|
| 85 | - */ |
|
| 86 | - public function lock() |
|
| 87 | - { |
|
| 88 | - // attempt to set lock, but if that fails... |
|
| 89 | - if (! $this->add_extra_meta('lock', time(), true)) { |
|
| 90 | - // then attempt to remove the lock in case it is expired |
|
| 91 | - if ($this->_remove_expired_lock()) { |
|
| 92 | - // if removal was successful, then try setting lock again |
|
| 93 | - $this->lock(); |
|
| 94 | - } else { |
|
| 95 | - // but if the lock can not be removed, then throw an exception |
|
| 96 | - throw new EE_Error( |
|
| 97 | - sprintf( |
|
| 98 | - __( |
|
| 99 | - 'Could not lock Transaction %1$d because it is already locked, meaning another part of the system is currently editing it. It should already be unlocked by the time you read this, so please refresh the page and try again.', |
|
| 100 | - 'event_espresso' |
|
| 101 | - ), |
|
| 102 | - $this->ID() |
|
| 103 | - ) |
|
| 104 | - ); |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * removes transaction lock applied in EE_Transaction::lock() |
|
| 112 | - * |
|
| 113 | - * @return int |
|
| 114 | - * @throws EE_Error |
|
| 115 | - * @throws InvalidArgumentException |
|
| 116 | - * @throws InvalidDataTypeException |
|
| 117 | - * @throws InvalidInterfaceException |
|
| 118 | - * @throws ReflectionException |
|
| 119 | - */ |
|
| 120 | - public function unlock() |
|
| 121 | - { |
|
| 122 | - return $this->delete_extra_meta('lock'); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Decides whether or not now is the right time to update the transaction. |
|
| 128 | - * This is useful because we don't always know if it is safe to update the transaction |
|
| 129 | - * and its related data. why? |
|
| 130 | - * because it's possible that the transaction is being used in another |
|
| 131 | - * request and could overwrite anything we save. |
|
| 132 | - * So we want to only update the txn once we know that won't happen. |
|
| 133 | - * We also check that the lock isn't expired, and remove it if it is |
|
| 134 | - * |
|
| 135 | - * @return boolean |
|
| 136 | - * @throws EE_Error |
|
| 137 | - * @throws InvalidArgumentException |
|
| 138 | - * @throws InvalidDataTypeException |
|
| 139 | - * @throws InvalidInterfaceException |
|
| 140 | - * @throws ReflectionException |
|
| 141 | - */ |
|
| 142 | - public function is_locked() |
|
| 143 | - { |
|
| 144 | - // if TXN is not locked, then return false immediately |
|
| 145 | - if (! $this->_get_lock()) { |
|
| 146 | - return false; |
|
| 147 | - } |
|
| 148 | - // if not, then let's try and remove the lock in case it's expired... |
|
| 149 | - // _remove_expired_lock() returns 0 when lock is valid (ie: removed = false) |
|
| 150 | - // and a positive number if the lock was removed (ie: number of locks deleted), |
|
| 151 | - // so we need to return the opposite |
|
| 152 | - return ! $this->_remove_expired_lock() ? true : false; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Gets the meta field indicating that this TXN is locked |
|
| 158 | - * |
|
| 159 | - * @return int |
|
| 160 | - * @throws EE_Error |
|
| 161 | - * @throws InvalidArgumentException |
|
| 162 | - * @throws InvalidDataTypeException |
|
| 163 | - * @throws InvalidInterfaceException |
|
| 164 | - * @throws ReflectionException |
|
| 165 | - */ |
|
| 166 | - protected function _get_lock() |
|
| 167 | - { |
|
| 168 | - return (int) $this->get_extra_meta('lock', true, 0); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * If the lock on this transaction is expired, then we want to remove it so that the transaction can be updated |
|
| 174 | - * |
|
| 175 | - * @return int |
|
| 176 | - * @throws EE_Error |
|
| 177 | - * @throws InvalidArgumentException |
|
| 178 | - * @throws InvalidDataTypeException |
|
| 179 | - * @throws InvalidInterfaceException |
|
| 180 | - * @throws ReflectionException |
|
| 181 | - */ |
|
| 182 | - protected function _remove_expired_lock() |
|
| 183 | - { |
|
| 184 | - $locked = $this->_get_lock(); |
|
| 185 | - if ($locked && time() - EE_Transaction::LOCK_EXPIRATION > $locked) { |
|
| 186 | - return $this->unlock(); |
|
| 187 | - } |
|
| 188 | - return 0; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * Set transaction total |
|
| 194 | - * |
|
| 195 | - * @param float $total total value of transaction |
|
| 196 | - * @throws EE_Error |
|
| 197 | - * @throws InvalidArgumentException |
|
| 198 | - * @throws InvalidDataTypeException |
|
| 199 | - * @throws InvalidInterfaceException |
|
| 200 | - * @throws ReflectionException |
|
| 201 | - */ |
|
| 202 | - public function set_total($total = 0.00) |
|
| 203 | - { |
|
| 204 | - $this->set('TXN_total', (float) $total); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * Set Total Amount Paid to Date |
|
| 210 | - * |
|
| 211 | - * @param float $total_paid total amount paid to date (sum of all payments) |
|
| 212 | - * @throws EE_Error |
|
| 213 | - * @throws InvalidArgumentException |
|
| 214 | - * @throws InvalidDataTypeException |
|
| 215 | - * @throws InvalidInterfaceException |
|
| 216 | - * @throws ReflectionException |
|
| 217 | - */ |
|
| 218 | - public function set_paid($total_paid = 0.00) |
|
| 219 | - { |
|
| 220 | - $this->set('TXN_paid', (float) $total_paid); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * Set transaction status |
|
| 226 | - * |
|
| 227 | - * @param string $status whether the transaction is open, declined, accepted, |
|
| 228 | - * or any number of custom values that can be set |
|
| 229 | - * @throws EE_Error |
|
| 230 | - * @throws InvalidArgumentException |
|
| 231 | - * @throws InvalidDataTypeException |
|
| 232 | - * @throws InvalidInterfaceException |
|
| 233 | - * @throws ReflectionException |
|
| 234 | - */ |
|
| 235 | - public function set_status($status = '') |
|
| 236 | - { |
|
| 237 | - $this->set('STS_ID', $status); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * Set hash salt |
|
| 243 | - * |
|
| 244 | - * @param string $hash_salt required for some payment gateways |
|
| 245 | - * @throws EE_Error |
|
| 246 | - * @throws InvalidArgumentException |
|
| 247 | - * @throws InvalidDataTypeException |
|
| 248 | - * @throws InvalidInterfaceException |
|
| 249 | - * @throws ReflectionException |
|
| 250 | - */ |
|
| 251 | - public function set_hash_salt($hash_salt = '') |
|
| 252 | - { |
|
| 253 | - $this->set('TXN_hash_salt', $hash_salt); |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * Sets TXN_reg_steps array |
|
| 259 | - * |
|
| 260 | - * @param array $txn_reg_steps |
|
| 261 | - * @throws EE_Error |
|
| 262 | - * @throws InvalidArgumentException |
|
| 263 | - * @throws InvalidDataTypeException |
|
| 264 | - * @throws InvalidInterfaceException |
|
| 265 | - * @throws ReflectionException |
|
| 266 | - */ |
|
| 267 | - public function set_reg_steps(array $txn_reg_steps) |
|
| 268 | - { |
|
| 269 | - $this->set('TXN_reg_steps', $txn_reg_steps); |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - |
|
| 273 | - /** |
|
| 274 | - * Gets TXN_reg_steps |
|
| 275 | - * |
|
| 276 | - * @return array |
|
| 277 | - * @throws EE_Error |
|
| 278 | - * @throws InvalidArgumentException |
|
| 279 | - * @throws InvalidDataTypeException |
|
| 280 | - * @throws InvalidInterfaceException |
|
| 281 | - * @throws ReflectionException |
|
| 282 | - */ |
|
| 283 | - public function reg_steps() |
|
| 284 | - { |
|
| 285 | - $TXN_reg_steps = $this->get('TXN_reg_steps'); |
|
| 286 | - return is_array($TXN_reg_steps) ? (array) $TXN_reg_steps : array(); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * @return string of transaction's total cost, with currency symbol and decimal |
|
| 292 | - * @throws EE_Error |
|
| 293 | - * @throws InvalidArgumentException |
|
| 294 | - * @throws InvalidDataTypeException |
|
| 295 | - * @throws InvalidInterfaceException |
|
| 296 | - * @throws ReflectionException |
|
| 297 | - */ |
|
| 298 | - public function pretty_total() |
|
| 299 | - { |
|
| 300 | - return $this->get_pretty('TXN_total'); |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * Gets the amount paid in a pretty string (formatted and with currency symbol) |
|
| 306 | - * |
|
| 307 | - * @return string |
|
| 308 | - * @throws EE_Error |
|
| 309 | - * @throws InvalidArgumentException |
|
| 310 | - * @throws InvalidDataTypeException |
|
| 311 | - * @throws InvalidInterfaceException |
|
| 312 | - * @throws ReflectionException |
|
| 313 | - */ |
|
| 314 | - public function pretty_paid() |
|
| 315 | - { |
|
| 316 | - return $this->get_pretty('TXN_paid'); |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - |
|
| 320 | - /** |
|
| 321 | - * calculate the amount remaining for this transaction and return; |
|
| 322 | - * |
|
| 323 | - * @return float amount remaining |
|
| 324 | - * @throws EE_Error |
|
| 325 | - * @throws InvalidArgumentException |
|
| 326 | - * @throws InvalidDataTypeException |
|
| 327 | - * @throws InvalidInterfaceException |
|
| 328 | - * @throws ReflectionException |
|
| 329 | - */ |
|
| 330 | - public function remaining() |
|
| 331 | - { |
|
| 332 | - return $this->total() - $this->paid(); |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * get Transaction Total |
|
| 338 | - * |
|
| 339 | - * @return float |
|
| 340 | - * @throws EE_Error |
|
| 341 | - * @throws InvalidArgumentException |
|
| 342 | - * @throws InvalidDataTypeException |
|
| 343 | - * @throws InvalidInterfaceException |
|
| 344 | - * @throws ReflectionException |
|
| 345 | - */ |
|
| 346 | - public function total() |
|
| 347 | - { |
|
| 348 | - return (float) $this->get('TXN_total'); |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * get Total Amount Paid to Date |
|
| 354 | - * |
|
| 355 | - * @return float |
|
| 356 | - * @throws EE_Error |
|
| 357 | - * @throws InvalidArgumentException |
|
| 358 | - * @throws InvalidDataTypeException |
|
| 359 | - * @throws InvalidInterfaceException |
|
| 360 | - * @throws ReflectionException |
|
| 361 | - */ |
|
| 362 | - public function paid() |
|
| 363 | - { |
|
| 364 | - return (float) $this->get('TXN_paid'); |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - |
|
| 368 | - /** |
|
| 369 | - * @return mixed|null |
|
| 370 | - * @throws EE_Error |
|
| 371 | - * @throws InvalidArgumentException |
|
| 372 | - * @throws InvalidDataTypeException |
|
| 373 | - * @throws InvalidInterfaceException |
|
| 374 | - * @throws ReflectionException |
|
| 375 | - */ |
|
| 376 | - public function get_cart_session() |
|
| 377 | - { |
|
| 378 | - $session_data = (array) $this->get('TXN_session_data'); |
|
| 379 | - return isset($session_data['cart']) && $session_data['cart'] instanceof EE_Cart |
|
| 380 | - ? $session_data['cart'] |
|
| 381 | - : null; |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * get Transaction session data |
|
| 387 | - * |
|
| 388 | - * @return array|mixed |
|
| 389 | - * @throws EE_Error |
|
| 390 | - * @throws InvalidArgumentException |
|
| 391 | - * @throws InvalidDataTypeException |
|
| 392 | - * @throws InvalidInterfaceException |
|
| 393 | - * @throws ReflectionException |
|
| 394 | - */ |
|
| 395 | - public function session_data() |
|
| 396 | - { |
|
| 397 | - $session_data = $this->get('TXN_session_data'); |
|
| 398 | - if (empty($session_data)) { |
|
| 399 | - $session_data = array( |
|
| 400 | - 'id' => null, |
|
| 401 | - 'user_id' => null, |
|
| 402 | - 'ip_address' => null, |
|
| 403 | - 'user_agent' => null, |
|
| 404 | - 'init_access' => null, |
|
| 405 | - 'last_access' => null, |
|
| 406 | - 'pages_visited' => array(), |
|
| 407 | - ); |
|
| 408 | - } |
|
| 409 | - return $session_data; |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - |
|
| 413 | - /** |
|
| 414 | - * Set session data within the TXN object |
|
| 415 | - * |
|
| 416 | - * @param EE_Session|array $session_data |
|
| 417 | - * @throws EE_Error |
|
| 418 | - * @throws InvalidArgumentException |
|
| 419 | - * @throws InvalidDataTypeException |
|
| 420 | - * @throws InvalidInterfaceException |
|
| 421 | - * @throws ReflectionException |
|
| 422 | - */ |
|
| 423 | - public function set_txn_session_data($session_data) |
|
| 424 | - { |
|
| 425 | - if ($session_data instanceof EE_Session) { |
|
| 426 | - $this->set('TXN_session_data', $session_data->get_session_data(null, true)); |
|
| 427 | - } else { |
|
| 428 | - $this->set('TXN_session_data', $session_data); |
|
| 429 | - } |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - |
|
| 433 | - /** |
|
| 434 | - * get Transaction hash salt |
|
| 435 | - * |
|
| 436 | - * @return mixed |
|
| 437 | - * @throws EE_Error |
|
| 438 | - * @throws InvalidArgumentException |
|
| 439 | - * @throws InvalidDataTypeException |
|
| 440 | - * @throws InvalidInterfaceException |
|
| 441 | - * @throws ReflectionException |
|
| 442 | - */ |
|
| 443 | - public function hash_salt_() |
|
| 444 | - { |
|
| 445 | - return $this->get('TXN_hash_salt'); |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - |
|
| 449 | - /** |
|
| 450 | - * Returns the transaction datetime as either: |
|
| 451 | - * - unix timestamp format ($format = false, $gmt = true) |
|
| 452 | - * - formatted date string including the UTC (timezone) offset ($format = true ($gmt |
|
| 453 | - * has no affect with this option)), this also may include a timezone abbreviation if the |
|
| 454 | - * set timezone in this class differs from what the timezone is on the blog. |
|
| 455 | - * - formatted date string including the UTC (timezone) offset (default). |
|
| 456 | - * |
|
| 457 | - * @param boolean $format - whether to return a unix timestamp (default) or formatted date string |
|
| 458 | - * @param boolean $gmt - whether to return a unix timestamp with UTC offset applied (default) |
|
| 459 | - * or no UTC offset applied |
|
| 460 | - * @return string | int |
|
| 461 | - * @throws EE_Error |
|
| 462 | - * @throws InvalidArgumentException |
|
| 463 | - * @throws InvalidDataTypeException |
|
| 464 | - * @throws InvalidInterfaceException |
|
| 465 | - * @throws ReflectionException |
|
| 466 | - */ |
|
| 467 | - public function datetime($format = false, $gmt = false) |
|
| 468 | - { |
|
| 469 | - if ($format) { |
|
| 470 | - return $this->get_pretty('TXN_timestamp'); |
|
| 471 | - } |
|
| 472 | - if ($gmt) { |
|
| 473 | - return $this->get_raw('TXN_timestamp'); |
|
| 474 | - } |
|
| 475 | - return $this->get('TXN_timestamp'); |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - |
|
| 479 | - /** |
|
| 480 | - * Gets registrations on this transaction |
|
| 481 | - * |
|
| 482 | - * @param array $query_params array of query parameters |
|
| 483 | - * @param boolean $get_cached TRUE to retrieve cached registrations or FALSE to pull from the db |
|
| 484 | - * @return EE_Base_Class[]|EE_Registration[] |
|
| 485 | - * @throws EE_Error |
|
| 486 | - * @throws InvalidArgumentException |
|
| 487 | - * @throws InvalidDataTypeException |
|
| 488 | - * @throws InvalidInterfaceException |
|
| 489 | - * @throws ReflectionException |
|
| 490 | - */ |
|
| 491 | - public function registrations($query_params = array(), $get_cached = false) |
|
| 492 | - { |
|
| 493 | - $query_params = (empty($query_params) || ! is_array($query_params)) |
|
| 494 | - ? array( |
|
| 495 | - 'order_by' => array( |
|
| 496 | - 'Event.EVT_name' => 'ASC', |
|
| 497 | - 'Attendee.ATT_lname' => 'ASC', |
|
| 498 | - 'Attendee.ATT_fname' => 'ASC', |
|
| 499 | - ), |
|
| 500 | - ) |
|
| 501 | - : $query_params; |
|
| 502 | - $query_params = $get_cached ? array() : $query_params; |
|
| 503 | - return $this->get_many_related('Registration', $query_params); |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - |
|
| 507 | - /** |
|
| 508 | - * Gets all the attendees for this transaction (handy for use with EE_Attendee's get_registrations_for_event |
|
| 509 | - * function for getting attendees and how many registrations they each have for an event) |
|
| 510 | - * |
|
| 511 | - * @return mixed EE_Attendee[] by default, int if $output is set to 'COUNT' |
|
| 512 | - * @throws EE_Error |
|
| 513 | - * @throws InvalidArgumentException |
|
| 514 | - * @throws InvalidDataTypeException |
|
| 515 | - * @throws InvalidInterfaceException |
|
| 516 | - * @throws ReflectionException |
|
| 517 | - */ |
|
| 518 | - public function attendees() |
|
| 519 | - { |
|
| 520 | - return $this->get_many_related('Attendee', array(array('Registration.Transaction.TXN_ID' => $this->ID()))); |
|
| 521 | - } |
|
| 522 | - |
|
| 523 | - |
|
| 524 | - /** |
|
| 525 | - * Gets payments for this transaction. Unlike other such functions, order by 'DESC' by default |
|
| 526 | - * |
|
| 527 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 528 | - * @return EE_Base_Class[]|EE_Payment[] |
|
| 529 | - * @throws EE_Error |
|
| 530 | - * @throws InvalidArgumentException |
|
| 531 | - * @throws InvalidDataTypeException |
|
| 532 | - * @throws InvalidInterfaceException |
|
| 533 | - * @throws ReflectionException |
|
| 534 | - */ |
|
| 535 | - public function payments($query_params = array()) |
|
| 536 | - { |
|
| 537 | - return $this->get_many_related('Payment', $query_params); |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - |
|
| 541 | - /** |
|
| 542 | - * gets only approved payments for this transaction |
|
| 543 | - * |
|
| 544 | - * @return EE_Base_Class[]|EE_Payment[] |
|
| 545 | - * @throws EE_Error |
|
| 546 | - * @throws InvalidArgumentException |
|
| 547 | - * @throws ReflectionException |
|
| 548 | - * @throws InvalidDataTypeException |
|
| 549 | - * @throws InvalidInterfaceException |
|
| 550 | - */ |
|
| 551 | - public function approved_payments() |
|
| 552 | - { |
|
| 553 | - EE_Registry::instance()->load_model('Payment'); |
|
| 554 | - return $this->get_many_related( |
|
| 555 | - 'Payment', |
|
| 556 | - array( |
|
| 557 | - array('STS_ID' => EEM_Payment::status_id_approved), |
|
| 558 | - 'order_by' => array('PAY_timestamp' => 'DESC'), |
|
| 559 | - ) |
|
| 560 | - ); |
|
| 561 | - } |
|
| 562 | - |
|
| 563 | - |
|
| 564 | - /** |
|
| 565 | - * Gets all payments which have not been approved |
|
| 566 | - * |
|
| 567 | - * @return EE_Base_Class[]|EEI_Payment[] |
|
| 568 | - * @throws EE_Error if a model is misconfigured somehow |
|
| 569 | - * @throws InvalidArgumentException |
|
| 570 | - * @throws InvalidDataTypeException |
|
| 571 | - * @throws InvalidInterfaceException |
|
| 572 | - * @throws ReflectionException |
|
| 573 | - */ |
|
| 574 | - public function pending_payments() |
|
| 575 | - { |
|
| 576 | - return $this->get_many_related( |
|
| 577 | - 'Payment', |
|
| 578 | - array( |
|
| 579 | - array( |
|
| 580 | - 'STS_ID' => EEM_Payment::status_id_pending, |
|
| 581 | - ), |
|
| 582 | - 'order_by' => array( |
|
| 583 | - 'PAY_timestamp' => 'DESC', |
|
| 584 | - ), |
|
| 585 | - ) |
|
| 586 | - ); |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - |
|
| 590 | - /** |
|
| 591 | - * echoes $this->pretty_status() |
|
| 592 | - * |
|
| 593 | - * @param bool $show_icons |
|
| 594 | - * @throws EE_Error |
|
| 595 | - * @throws InvalidArgumentException |
|
| 596 | - * @throws InvalidDataTypeException |
|
| 597 | - * @throws InvalidInterfaceException |
|
| 598 | - * @throws ReflectionException |
|
| 599 | - */ |
|
| 600 | - public function e_pretty_status($show_icons = false) |
|
| 601 | - { |
|
| 602 | - echo $this->pretty_status($show_icons); |
|
| 603 | - } |
|
| 604 | - |
|
| 605 | - |
|
| 606 | - /** |
|
| 607 | - * returns a pretty version of the status, good for displaying to users |
|
| 608 | - * |
|
| 609 | - * @param bool $show_icons |
|
| 610 | - * @return string |
|
| 611 | - * @throws EE_Error |
|
| 612 | - * @throws InvalidArgumentException |
|
| 613 | - * @throws InvalidDataTypeException |
|
| 614 | - * @throws InvalidInterfaceException |
|
| 615 | - * @throws ReflectionException |
|
| 616 | - */ |
|
| 617 | - public function pretty_status($show_icons = false) |
|
| 618 | - { |
|
| 619 | - $status = EEM_Status::instance()->localized_status( |
|
| 620 | - array($this->status_ID() => __('unknown', 'event_espresso')), |
|
| 621 | - false, |
|
| 622 | - 'sentence' |
|
| 623 | - ); |
|
| 624 | - $icon = ''; |
|
| 625 | - switch ($this->status_ID()) { |
|
| 626 | - case EEM_Transaction::complete_status_code: |
|
| 627 | - $icon = $show_icons ? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>' : ''; |
|
| 628 | - break; |
|
| 629 | - case EEM_Transaction::incomplete_status_code: |
|
| 630 | - $icon = $show_icons ? '<span class="dashicons dashicons-marker ee-icon-size-16 lt-blue-text"></span>' |
|
| 631 | - : ''; |
|
| 632 | - break; |
|
| 633 | - case EEM_Transaction::abandoned_status_code: |
|
| 634 | - $icon = $show_icons ? '<span class="dashicons dashicons-marker ee-icon-size-16 red-text"></span>' : ''; |
|
| 635 | - break; |
|
| 636 | - case EEM_Transaction::failed_status_code: |
|
| 637 | - $icon = $show_icons ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' : ''; |
|
| 638 | - break; |
|
| 639 | - case EEM_Transaction::overpaid_status_code: |
|
| 640 | - $icon = $show_icons ? '<span class="dashicons dashicons-plus ee-icon-size-16 orange-text"></span>' : ''; |
|
| 641 | - break; |
|
| 642 | - } |
|
| 643 | - return $icon . $status[ $this->status_ID() ]; |
|
| 644 | - } |
|
| 645 | - |
|
| 646 | - |
|
| 647 | - /** |
|
| 648 | - * get Transaction Status |
|
| 649 | - * |
|
| 650 | - * @return mixed |
|
| 651 | - * @throws EE_Error |
|
| 652 | - * @throws InvalidArgumentException |
|
| 653 | - * @throws InvalidDataTypeException |
|
| 654 | - * @throws InvalidInterfaceException |
|
| 655 | - * @throws ReflectionException |
|
| 656 | - */ |
|
| 657 | - public function status_ID() |
|
| 658 | - { |
|
| 659 | - return $this->get('STS_ID'); |
|
| 660 | - } |
|
| 661 | - |
|
| 662 | - |
|
| 663 | - /** |
|
| 664 | - * Returns TRUE or FALSE for whether or not this transaction cost any money |
|
| 665 | - * |
|
| 666 | - * @return boolean |
|
| 667 | - * @throws EE_Error |
|
| 668 | - * @throws InvalidArgumentException |
|
| 669 | - * @throws InvalidDataTypeException |
|
| 670 | - * @throws InvalidInterfaceException |
|
| 671 | - * @throws ReflectionException |
|
| 672 | - */ |
|
| 673 | - public function is_free() |
|
| 674 | - { |
|
| 675 | - return EEH_Money::compare_floats($this->get('TXN_total'), 0, '=='); |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - |
|
| 679 | - /** |
|
| 680 | - * Returns whether this transaction is complete |
|
| 681 | - * Useful in templates and other logic for deciding if we should ask for another payment... |
|
| 682 | - * |
|
| 683 | - * @return boolean |
|
| 684 | - * @throws EE_Error |
|
| 685 | - * @throws InvalidArgumentException |
|
| 686 | - * @throws InvalidDataTypeException |
|
| 687 | - * @throws InvalidInterfaceException |
|
| 688 | - * @throws ReflectionException |
|
| 689 | - */ |
|
| 690 | - public function is_completed() |
|
| 691 | - { |
|
| 692 | - return $this->status_ID() === EEM_Transaction::complete_status_code; |
|
| 693 | - } |
|
| 694 | - |
|
| 695 | - |
|
| 696 | - /** |
|
| 697 | - * Returns whether this transaction is incomplete |
|
| 698 | - * Useful in templates and other logic for deciding if we should ask for another payment... |
|
| 699 | - * |
|
| 700 | - * @return boolean |
|
| 701 | - * @throws EE_Error |
|
| 702 | - * @throws InvalidArgumentException |
|
| 703 | - * @throws InvalidDataTypeException |
|
| 704 | - * @throws InvalidInterfaceException |
|
| 705 | - * @throws ReflectionException |
|
| 706 | - */ |
|
| 707 | - public function is_incomplete() |
|
| 708 | - { |
|
| 709 | - return $this->status_ID() === EEM_Transaction::incomplete_status_code; |
|
| 710 | - } |
|
| 711 | - |
|
| 712 | - |
|
| 713 | - /** |
|
| 714 | - * Returns whether this transaction is overpaid |
|
| 715 | - * Useful in templates and other logic for deciding if monies need to be refunded |
|
| 716 | - * |
|
| 717 | - * @return boolean |
|
| 718 | - * @throws EE_Error |
|
| 719 | - * @throws InvalidArgumentException |
|
| 720 | - * @throws InvalidDataTypeException |
|
| 721 | - * @throws InvalidInterfaceException |
|
| 722 | - * @throws ReflectionException |
|
| 723 | - */ |
|
| 724 | - public function is_overpaid() |
|
| 725 | - { |
|
| 726 | - return $this->status_ID() === EEM_Transaction::overpaid_status_code; |
|
| 727 | - } |
|
| 728 | - |
|
| 729 | - |
|
| 730 | - /** |
|
| 731 | - * Returns whether this transaction was abandoned |
|
| 732 | - * meaning that the transaction/registration process was somehow interrupted and never completed |
|
| 733 | - * but that contact information exists for at least one registrant |
|
| 734 | - * |
|
| 735 | - * @return boolean |
|
| 736 | - * @throws EE_Error |
|
| 737 | - * @throws InvalidArgumentException |
|
| 738 | - * @throws InvalidDataTypeException |
|
| 739 | - * @throws InvalidInterfaceException |
|
| 740 | - * @throws ReflectionException |
|
| 741 | - */ |
|
| 742 | - public function is_abandoned() |
|
| 743 | - { |
|
| 744 | - return $this->status_ID() === EEM_Transaction::abandoned_status_code; |
|
| 745 | - } |
|
| 746 | - |
|
| 747 | - |
|
| 748 | - /** |
|
| 749 | - * Returns whether this transaction failed |
|
| 750 | - * meaning that the transaction/registration process was somehow interrupted and never completed |
|
| 751 | - * and that NO contact information exists for any registrants |
|
| 752 | - * |
|
| 753 | - * @return boolean |
|
| 754 | - * @throws EE_Error |
|
| 755 | - * @throws InvalidArgumentException |
|
| 756 | - * @throws InvalidDataTypeException |
|
| 757 | - * @throws InvalidInterfaceException |
|
| 758 | - * @throws ReflectionException |
|
| 759 | - */ |
|
| 760 | - public function failed() |
|
| 761 | - { |
|
| 762 | - return $this->status_ID() === EEM_Transaction::failed_status_code; |
|
| 763 | - } |
|
| 764 | - |
|
| 765 | - |
|
| 766 | - /** |
|
| 767 | - * This returns the url for the invoice of this transaction |
|
| 768 | - * |
|
| 769 | - * @param string $type 'html' or 'pdf' (default is pdf) |
|
| 770 | - * @return string |
|
| 771 | - * @throws EE_Error |
|
| 772 | - * @throws InvalidArgumentException |
|
| 773 | - * @throws InvalidDataTypeException |
|
| 774 | - * @throws InvalidInterfaceException |
|
| 775 | - * @throws ReflectionException |
|
| 776 | - */ |
|
| 777 | - public function invoice_url($type = 'html') |
|
| 778 | - { |
|
| 779 | - $REG = $this->primary_registration(); |
|
| 780 | - if (! $REG instanceof EE_Registration) { |
|
| 781 | - return ''; |
|
| 782 | - } |
|
| 783 | - return $REG->invoice_url($type); |
|
| 784 | - } |
|
| 785 | - |
|
| 786 | - |
|
| 787 | - /** |
|
| 788 | - * Gets the primary registration only |
|
| 789 | - * |
|
| 790 | - * @return EE_Base_Class|EE_Registration |
|
| 791 | - * @throws EE_Error |
|
| 792 | - * @throws InvalidArgumentException |
|
| 793 | - * @throws InvalidDataTypeException |
|
| 794 | - * @throws InvalidInterfaceException |
|
| 795 | - * @throws ReflectionException |
|
| 796 | - */ |
|
| 797 | - public function primary_registration() |
|
| 798 | - { |
|
| 799 | - $registrations = (array) $this->get_many_related( |
|
| 800 | - 'Registration', |
|
| 801 | - array(array('REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT)) |
|
| 802 | - ); |
|
| 803 | - foreach ($registrations as $registration) { |
|
| 804 | - // valid registration that is NOT cancelled or declined ? |
|
| 805 | - if ($registration instanceof EE_Registration |
|
| 806 | - && ! in_array($registration->status_ID(), EEM_Registration::closed_reg_statuses(), true) |
|
| 807 | - ) { |
|
| 808 | - return $registration; |
|
| 809 | - } |
|
| 810 | - } |
|
| 811 | - // nothing valid found, so just return first thing from array of results |
|
| 812 | - return reset($registrations); |
|
| 813 | - } |
|
| 814 | - |
|
| 815 | - |
|
| 816 | - /** |
|
| 817 | - * Gets the URL for viewing the receipt |
|
| 818 | - * |
|
| 819 | - * @param string $type 'pdf' or 'html' (default is 'html') |
|
| 820 | - * @return string |
|
| 821 | - * @throws EE_Error |
|
| 822 | - * @throws InvalidArgumentException |
|
| 823 | - * @throws InvalidDataTypeException |
|
| 824 | - * @throws InvalidInterfaceException |
|
| 825 | - * @throws ReflectionException |
|
| 826 | - */ |
|
| 827 | - public function receipt_url($type = 'html') |
|
| 828 | - { |
|
| 829 | - $REG = $this->primary_registration(); |
|
| 830 | - if (! $REG instanceof EE_Registration) { |
|
| 831 | - return ''; |
|
| 832 | - } |
|
| 833 | - return $REG->receipt_url($type); |
|
| 834 | - } |
|
| 835 | - |
|
| 836 | - |
|
| 837 | - /** |
|
| 838 | - * Gets the URL of the thank you page with this registration REG_url_link added as |
|
| 839 | - * a query parameter |
|
| 840 | - * |
|
| 841 | - * @return string |
|
| 842 | - * @throws EE_Error |
|
| 843 | - * @throws InvalidArgumentException |
|
| 844 | - * @throws InvalidDataTypeException |
|
| 845 | - * @throws InvalidInterfaceException |
|
| 846 | - * @throws ReflectionException |
|
| 847 | - */ |
|
| 848 | - public function payment_overview_url() |
|
| 849 | - { |
|
| 850 | - $primary_registration = $this->primary_registration(); |
|
| 851 | - return $primary_registration instanceof EE_Registration ? $primary_registration->payment_overview_url() : false; |
|
| 852 | - } |
|
| 853 | - |
|
| 854 | - |
|
| 855 | - /** |
|
| 856 | - * @return string |
|
| 857 | - * @throws EE_Error |
|
| 858 | - * @throws InvalidArgumentException |
|
| 859 | - * @throws InvalidDataTypeException |
|
| 860 | - * @throws InvalidInterfaceException |
|
| 861 | - * @throws ReflectionException |
|
| 862 | - */ |
|
| 863 | - public function gateway_response_on_transaction() |
|
| 864 | - { |
|
| 865 | - $payment = $this->get_first_related('Payment'); |
|
| 866 | - return $payment instanceof EE_Payment ? $payment->gateway_response() : ''; |
|
| 867 | - } |
|
| 868 | - |
|
| 869 | - |
|
| 870 | - /** |
|
| 871 | - * Get the status object of this object |
|
| 872 | - * |
|
| 873 | - * @return EE_Base_Class|EE_Status |
|
| 874 | - * @throws EE_Error |
|
| 875 | - * @throws InvalidArgumentException |
|
| 876 | - * @throws InvalidDataTypeException |
|
| 877 | - * @throws InvalidInterfaceException |
|
| 878 | - * @throws ReflectionException |
|
| 879 | - */ |
|
| 880 | - public function status_obj() |
|
| 881 | - { |
|
| 882 | - return $this->get_first_related('Status'); |
|
| 883 | - } |
|
| 884 | - |
|
| 885 | - |
|
| 886 | - /** |
|
| 887 | - * Gets all the extra meta info on this payment |
|
| 888 | - * |
|
| 889 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 890 | - * @return EE_Base_Class[]|EE_Extra_Meta |
|
| 891 | - * @throws EE_Error |
|
| 892 | - * @throws InvalidArgumentException |
|
| 893 | - * @throws InvalidDataTypeException |
|
| 894 | - * @throws InvalidInterfaceException |
|
| 895 | - * @throws ReflectionException |
|
| 896 | - */ |
|
| 897 | - public function extra_meta($query_params = array()) |
|
| 898 | - { |
|
| 899 | - return $this->get_many_related('Extra_Meta', $query_params); |
|
| 900 | - } |
|
| 901 | - |
|
| 902 | - |
|
| 903 | - /** |
|
| 904 | - * Wrapper for _add_relation_to |
|
| 905 | - * |
|
| 906 | - * @param EE_Registration $registration |
|
| 907 | - * @return EE_Base_Class the relation was added to |
|
| 908 | - * @throws EE_Error |
|
| 909 | - * @throws InvalidArgumentException |
|
| 910 | - * @throws InvalidDataTypeException |
|
| 911 | - * @throws InvalidInterfaceException |
|
| 912 | - * @throws ReflectionException |
|
| 913 | - */ |
|
| 914 | - public function add_registration(EE_Registration $registration) |
|
| 915 | - { |
|
| 916 | - return $this->_add_relation_to($registration, 'Registration'); |
|
| 917 | - } |
|
| 918 | - |
|
| 919 | - |
|
| 920 | - /** |
|
| 921 | - * Removes the given registration from being related (even before saving this transaction). |
|
| 922 | - * If an ID/index is provided and this transaction isn't saved yet, removes it from list of cached relations |
|
| 923 | - * |
|
| 924 | - * @param int $registration_or_id |
|
| 925 | - * @return EE_Base_Class that was removed from being related |
|
| 926 | - * @throws EE_Error |
|
| 927 | - * @throws InvalidArgumentException |
|
| 928 | - * @throws InvalidDataTypeException |
|
| 929 | - * @throws InvalidInterfaceException |
|
| 930 | - * @throws ReflectionException |
|
| 931 | - */ |
|
| 932 | - public function remove_registration_with_id($registration_or_id) |
|
| 933 | - { |
|
| 934 | - return $this->_remove_relation_to($registration_or_id, 'Registration'); |
|
| 935 | - } |
|
| 936 | - |
|
| 937 | - |
|
| 938 | - /** |
|
| 939 | - * Gets all the line items which are for ACTUAL items |
|
| 940 | - * |
|
| 941 | - * @return EE_Line_Item[] |
|
| 942 | - * @throws EE_Error |
|
| 943 | - * @throws InvalidArgumentException |
|
| 944 | - * @throws InvalidDataTypeException |
|
| 945 | - * @throws InvalidInterfaceException |
|
| 946 | - * @throws ReflectionException |
|
| 947 | - */ |
|
| 948 | - public function items_purchased() |
|
| 949 | - { |
|
| 950 | - return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_line_item))); |
|
| 951 | - } |
|
| 952 | - |
|
| 953 | - |
|
| 954 | - /** |
|
| 955 | - * Wrapper for _add_relation_to |
|
| 956 | - * |
|
| 957 | - * @param EE_Line_Item $line_item |
|
| 958 | - * @return EE_Base_Class the relation was added to |
|
| 959 | - * @throws EE_Error |
|
| 960 | - * @throws InvalidArgumentException |
|
| 961 | - * @throws InvalidDataTypeException |
|
| 962 | - * @throws InvalidInterfaceException |
|
| 963 | - * @throws ReflectionException |
|
| 964 | - */ |
|
| 965 | - public function add_line_item(EE_Line_Item $line_item) |
|
| 966 | - { |
|
| 967 | - return $this->_add_relation_to($line_item, 'Line_Item'); |
|
| 968 | - } |
|
| 969 | - |
|
| 970 | - |
|
| 971 | - /** |
|
| 972 | - * Gets ALL the line items related to this transaction (unstructured) |
|
| 973 | - * |
|
| 974 | - * @param array $query_params |
|
| 975 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 976 | - * @throws EE_Error |
|
| 977 | - * @throws InvalidArgumentException |
|
| 978 | - * @throws InvalidDataTypeException |
|
| 979 | - * @throws InvalidInterfaceException |
|
| 980 | - * @throws ReflectionException |
|
| 981 | - */ |
|
| 982 | - public function line_items($query_params = array()) |
|
| 983 | - { |
|
| 984 | - return $this->get_many_related('Line_Item', $query_params); |
|
| 985 | - } |
|
| 986 | - |
|
| 987 | - |
|
| 988 | - /** |
|
| 989 | - * Gets all the line items which are taxes on the total |
|
| 990 | - * |
|
| 991 | - * @return EE_Line_Item[] |
|
| 992 | - * @throws EE_Error |
|
| 993 | - * @throws InvalidArgumentException |
|
| 994 | - * @throws InvalidDataTypeException |
|
| 995 | - * @throws InvalidInterfaceException |
|
| 996 | - * @throws ReflectionException |
|
| 997 | - */ |
|
| 998 | - public function tax_items() |
|
| 999 | - { |
|
| 1000 | - return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_tax))); |
|
| 1001 | - } |
|
| 1002 | - |
|
| 1003 | - |
|
| 1004 | - /** |
|
| 1005 | - * Gets the total line item (which is a parent of all other related line items, |
|
| 1006 | - * meaning it takes them all into account on its total) |
|
| 1007 | - * |
|
| 1008 | - * @param bool $create_if_not_found |
|
| 1009 | - * @return \EE_Line_Item |
|
| 1010 | - * @throws EE_Error |
|
| 1011 | - * @throws InvalidArgumentException |
|
| 1012 | - * @throws InvalidDataTypeException |
|
| 1013 | - * @throws InvalidInterfaceException |
|
| 1014 | - * @throws ReflectionException |
|
| 1015 | - */ |
|
| 1016 | - public function total_line_item($create_if_not_found = true) |
|
| 1017 | - { |
|
| 1018 | - $item = $this->get_first_related('Line_Item', array(array('LIN_type' => EEM_Line_Item::type_total))); |
|
| 1019 | - if (! $item && $create_if_not_found) { |
|
| 1020 | - $item = EEH_Line_Item::create_total_line_item($this); |
|
| 1021 | - } |
|
| 1022 | - return $item; |
|
| 1023 | - } |
|
| 1024 | - |
|
| 1025 | - |
|
| 1026 | - /** |
|
| 1027 | - * Returns the total amount of tax on this transaction |
|
| 1028 | - * (assumes there's only one tax subtotal line item) |
|
| 1029 | - * |
|
| 1030 | - * @return float |
|
| 1031 | - * @throws EE_Error |
|
| 1032 | - * @throws InvalidArgumentException |
|
| 1033 | - * @throws InvalidDataTypeException |
|
| 1034 | - * @throws InvalidInterfaceException |
|
| 1035 | - * @throws ReflectionException |
|
| 1036 | - */ |
|
| 1037 | - public function tax_total() |
|
| 1038 | - { |
|
| 1039 | - $tax_line_item = $this->tax_total_line_item(); |
|
| 1040 | - if ($tax_line_item) { |
|
| 1041 | - return (float) $tax_line_item->total(); |
|
| 1042 | - } |
|
| 1043 | - return (float) 0; |
|
| 1044 | - } |
|
| 1045 | - |
|
| 1046 | - |
|
| 1047 | - /** |
|
| 1048 | - * Gets the tax subtotal line item (assumes there's only one) |
|
| 1049 | - * |
|
| 1050 | - * @return EE_Line_Item |
|
| 1051 | - * @throws EE_Error |
|
| 1052 | - * @throws InvalidArgumentException |
|
| 1053 | - * @throws InvalidDataTypeException |
|
| 1054 | - * @throws InvalidInterfaceException |
|
| 1055 | - * @throws ReflectionException |
|
| 1056 | - */ |
|
| 1057 | - public function tax_total_line_item() |
|
| 1058 | - { |
|
| 1059 | - return EEH_Line_Item::get_taxes_subtotal($this->total_line_item()); |
|
| 1060 | - } |
|
| 1061 | - |
|
| 1062 | - |
|
| 1063 | - /** |
|
| 1064 | - * Gets the array of billing info for the gateway and for this transaction's primary registration's attendee. |
|
| 1065 | - * |
|
| 1066 | - * @return EE_Form_Section_Proper |
|
| 1067 | - * @throws EE_Error |
|
| 1068 | - * @throws InvalidArgumentException |
|
| 1069 | - * @throws InvalidDataTypeException |
|
| 1070 | - * @throws InvalidInterfaceException |
|
| 1071 | - * @throws ReflectionException |
|
| 1072 | - */ |
|
| 1073 | - public function billing_info() |
|
| 1074 | - { |
|
| 1075 | - $payment_method = $this->payment_method(); |
|
| 1076 | - if (! $payment_method) { |
|
| 1077 | - EE_Error::add_error( |
|
| 1078 | - __( |
|
| 1079 | - 'Could not find billing info for transaction because no gateway has been used for it yet', |
|
| 1080 | - 'event_espresso' |
|
| 1081 | - ), |
|
| 1082 | - __FILE__, |
|
| 1083 | - __FUNCTION__, |
|
| 1084 | - __LINE__ |
|
| 1085 | - ); |
|
| 1086 | - return null; |
|
| 1087 | - } |
|
| 1088 | - $primary_reg = $this->primary_registration(); |
|
| 1089 | - if (! $primary_reg) { |
|
| 1090 | - EE_Error::add_error( |
|
| 1091 | - __( |
|
| 1092 | - 'Cannot get billing info for gateway %s on transaction because no primary registration exists', |
|
| 1093 | - 'event_espresso' |
|
| 1094 | - ), |
|
| 1095 | - __FILE__, |
|
| 1096 | - __FUNCTION__, |
|
| 1097 | - __LINE__ |
|
| 1098 | - ); |
|
| 1099 | - return null; |
|
| 1100 | - } |
|
| 1101 | - $attendee = $primary_reg->attendee(); |
|
| 1102 | - if (! $attendee) { |
|
| 1103 | - EE_Error::add_error( |
|
| 1104 | - __( |
|
| 1105 | - 'Cannot get billing info for gateway %s on transaction because the primary registration has no attendee exists', |
|
| 1106 | - 'event_espresso' |
|
| 1107 | - ), |
|
| 1108 | - __FILE__, |
|
| 1109 | - __FUNCTION__, |
|
| 1110 | - __LINE__ |
|
| 1111 | - ); |
|
| 1112 | - return null; |
|
| 1113 | - } |
|
| 1114 | - return $attendee->billing_info_for_payment_method($payment_method); |
|
| 1115 | - } |
|
| 1116 | - |
|
| 1117 | - |
|
| 1118 | - /** |
|
| 1119 | - * Gets PMD_ID |
|
| 1120 | - * |
|
| 1121 | - * @return int |
|
| 1122 | - * @throws EE_Error |
|
| 1123 | - * @throws InvalidArgumentException |
|
| 1124 | - * @throws InvalidDataTypeException |
|
| 1125 | - * @throws InvalidInterfaceException |
|
| 1126 | - * @throws ReflectionException |
|
| 1127 | - */ |
|
| 1128 | - public function payment_method_ID() |
|
| 1129 | - { |
|
| 1130 | - return $this->get('PMD_ID'); |
|
| 1131 | - } |
|
| 1132 | - |
|
| 1133 | - |
|
| 1134 | - /** |
|
| 1135 | - * Sets PMD_ID |
|
| 1136 | - * |
|
| 1137 | - * @param int $PMD_ID |
|
| 1138 | - * @throws EE_Error |
|
| 1139 | - * @throws InvalidArgumentException |
|
| 1140 | - * @throws InvalidDataTypeException |
|
| 1141 | - * @throws InvalidInterfaceException |
|
| 1142 | - * @throws ReflectionException |
|
| 1143 | - */ |
|
| 1144 | - public function set_payment_method_ID($PMD_ID) |
|
| 1145 | - { |
|
| 1146 | - $this->set('PMD_ID', $PMD_ID); |
|
| 1147 | - } |
|
| 1148 | - |
|
| 1149 | - |
|
| 1150 | - /** |
|
| 1151 | - * Gets the last-used payment method on this transaction |
|
| 1152 | - * (we COULD just use the last-made payment, but some payment methods, namely |
|
| 1153 | - * offline ones, dont' create payments) |
|
| 1154 | - * |
|
| 1155 | - * @return EE_Payment_Method |
|
| 1156 | - * @throws EE_Error |
|
| 1157 | - * @throws InvalidArgumentException |
|
| 1158 | - * @throws InvalidDataTypeException |
|
| 1159 | - * @throws InvalidInterfaceException |
|
| 1160 | - * @throws ReflectionException |
|
| 1161 | - */ |
|
| 1162 | - public function payment_method() |
|
| 1163 | - { |
|
| 1164 | - $pm = $this->get_first_related('Payment_Method'); |
|
| 1165 | - if ($pm instanceof EE_Payment_Method) { |
|
| 1166 | - return $pm; |
|
| 1167 | - } |
|
| 1168 | - $last_payment = $this->last_payment(); |
|
| 1169 | - if ($last_payment instanceof EE_Payment && $last_payment->payment_method()) { |
|
| 1170 | - return $last_payment->payment_method(); |
|
| 1171 | - } |
|
| 1172 | - return null; |
|
| 1173 | - } |
|
| 1174 | - |
|
| 1175 | - |
|
| 1176 | - /** |
|
| 1177 | - * Gets the last payment made |
|
| 1178 | - * |
|
| 1179 | - * @return EE_Base_Class|EE_Payment |
|
| 1180 | - * @throws EE_Error |
|
| 1181 | - * @throws InvalidArgumentException |
|
| 1182 | - * @throws InvalidDataTypeException |
|
| 1183 | - * @throws InvalidInterfaceException |
|
| 1184 | - * @throws ReflectionException |
|
| 1185 | - */ |
|
| 1186 | - public function last_payment() |
|
| 1187 | - { |
|
| 1188 | - return $this->get_first_related('Payment', array('order_by' => array('PAY_ID' => 'desc'))); |
|
| 1189 | - } |
|
| 1190 | - |
|
| 1191 | - |
|
| 1192 | - /** |
|
| 1193 | - * Gets all the line items which are unrelated to tickets on this transaction |
|
| 1194 | - * |
|
| 1195 | - * @return EE_Line_Item[] |
|
| 1196 | - * @throws EE_Error |
|
| 1197 | - * @throws InvalidArgumentException |
|
| 1198 | - * @throws InvalidDataTypeException |
|
| 1199 | - * @throws InvalidInterfaceException |
|
| 1200 | - * @throws ReflectionException |
|
| 1201 | - */ |
|
| 1202 | - public function non_ticket_line_items() |
|
| 1203 | - { |
|
| 1204 | - return EEM_Line_Item::instance()->get_all_non_ticket_line_items_for_transaction($this->ID()); |
|
| 1205 | - } |
|
| 1206 | - |
|
| 1207 | - |
|
| 1208 | - /** |
|
| 1209 | - * possibly toggles TXN status |
|
| 1210 | - * |
|
| 1211 | - * @param boolean $update whether to save the TXN |
|
| 1212 | - * @return bool whether the TXN was saved |
|
| 1213 | - * @throws EE_Error |
|
| 1214 | - * @throws InvalidArgumentException |
|
| 1215 | - * @throws InvalidDataTypeException |
|
| 1216 | - * @throws InvalidInterfaceException |
|
| 1217 | - * @throws ReflectionException |
|
| 1218 | - * @throws RuntimeException |
|
| 1219 | - */ |
|
| 1220 | - public function update_status_based_on_total_paid($update = true) |
|
| 1221 | - { |
|
| 1222 | - // set transaction status based on comparison of TXN_paid vs TXN_total |
|
| 1223 | - if (EEH_Money::compare_floats($this->paid(), $this->total(), '>')) { |
|
| 1224 | - $new_txn_status = EEM_Transaction::overpaid_status_code; |
|
| 1225 | - } elseif (EEH_Money::compare_floats($this->paid(), $this->total())) { |
|
| 1226 | - $new_txn_status = EEM_Transaction::complete_status_code; |
|
| 1227 | - } elseif (EEH_Money::compare_floats($this->paid(), $this->total(), '<')) { |
|
| 1228 | - $new_txn_status = EEM_Transaction::incomplete_status_code; |
|
| 1229 | - } else { |
|
| 1230 | - throw new RuntimeException( |
|
| 1231 | - __('The total paid calculation for this transaction is inaccurate.', 'event_espresso') |
|
| 1232 | - ); |
|
| 1233 | - } |
|
| 1234 | - if ($new_txn_status !== $this->status_ID()) { |
|
| 1235 | - $this->set_status($new_txn_status); |
|
| 1236 | - if ($update) { |
|
| 1237 | - return $this->save() ? true : false; |
|
| 1238 | - } |
|
| 1239 | - } |
|
| 1240 | - return false; |
|
| 1241 | - } |
|
| 1242 | - |
|
| 1243 | - |
|
| 1244 | - /** |
|
| 1245 | - * Updates the transaction's status and total_paid based on all the payments |
|
| 1246 | - * that apply to it |
|
| 1247 | - * |
|
| 1248 | - * @deprecated |
|
| 1249 | - * @return array|bool |
|
| 1250 | - * @throws EE_Error |
|
| 1251 | - * @throws InvalidArgumentException |
|
| 1252 | - * @throws ReflectionException |
|
| 1253 | - * @throws InvalidDataTypeException |
|
| 1254 | - * @throws InvalidInterfaceException |
|
| 1255 | - */ |
|
| 1256 | - public function update_based_on_payments() |
|
| 1257 | - { |
|
| 1258 | - EE_Error::doing_it_wrong( |
|
| 1259 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 1260 | - sprintf( |
|
| 1261 | - __('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
| 1262 | - 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' |
|
| 1263 | - ), |
|
| 1264 | - '4.6.0' |
|
| 1265 | - ); |
|
| 1266 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 1267 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 1268 | - return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment($this); |
|
| 1269 | - } |
|
| 1270 | - |
|
| 1271 | - |
|
| 1272 | - /** |
|
| 1273 | - * @return string |
|
| 1274 | - */ |
|
| 1275 | - public function old_txn_status() |
|
| 1276 | - { |
|
| 1277 | - return $this->_old_txn_status; |
|
| 1278 | - } |
|
| 1279 | - |
|
| 1280 | - |
|
| 1281 | - /** |
|
| 1282 | - * @param string $old_txn_status |
|
| 1283 | - */ |
|
| 1284 | - public function set_old_txn_status($old_txn_status) |
|
| 1285 | - { |
|
| 1286 | - // only set the first time |
|
| 1287 | - if ($this->_old_txn_status === null) { |
|
| 1288 | - $this->_old_txn_status = $old_txn_status; |
|
| 1289 | - } |
|
| 1290 | - } |
|
| 1291 | - |
|
| 1292 | - |
|
| 1293 | - /** |
|
| 1294 | - * reg_status_updated |
|
| 1295 | - * |
|
| 1296 | - * @return bool |
|
| 1297 | - * @throws EE_Error |
|
| 1298 | - * @throws InvalidArgumentException |
|
| 1299 | - * @throws InvalidDataTypeException |
|
| 1300 | - * @throws InvalidInterfaceException |
|
| 1301 | - * @throws ReflectionException |
|
| 1302 | - */ |
|
| 1303 | - public function txn_status_updated() |
|
| 1304 | - { |
|
| 1305 | - return $this->status_ID() !== $this->_old_txn_status && $this->_old_txn_status !== null; |
|
| 1306 | - } |
|
| 1307 | - |
|
| 1308 | - |
|
| 1309 | - /** |
|
| 1310 | - * _reg_steps_completed |
|
| 1311 | - * if $check_all is TRUE, then returns TRUE if ALL reg steps have been marked as completed, |
|
| 1312 | - * if a $reg_step_slug is provided, then this step will be skipped when testing for completion |
|
| 1313 | - * if $check_all is FALSE and a $reg_step_slug is provided, then ONLY that reg step will be tested for completion |
|
| 1314 | - * |
|
| 1315 | - * @param string $reg_step_slug |
|
| 1316 | - * @param bool $check_all |
|
| 1317 | - * @return bool|int |
|
| 1318 | - * @throws EE_Error |
|
| 1319 | - * @throws InvalidArgumentException |
|
| 1320 | - * @throws InvalidDataTypeException |
|
| 1321 | - * @throws InvalidInterfaceException |
|
| 1322 | - * @throws ReflectionException |
|
| 1323 | - */ |
|
| 1324 | - private function _reg_steps_completed($reg_step_slug = '', $check_all = true) |
|
| 1325 | - { |
|
| 1326 | - $reg_steps = $this->reg_steps(); |
|
| 1327 | - if (! is_array($reg_steps) || empty($reg_steps)) { |
|
| 1328 | - return false; |
|
| 1329 | - } |
|
| 1330 | - // loop thru reg steps array) |
|
| 1331 | - foreach ($reg_steps as $slug => $reg_step_completed) { |
|
| 1332 | - // if NOT checking ALL steps (only checking one step) |
|
| 1333 | - if (! $check_all) { |
|
| 1334 | - // and this is the one |
|
| 1335 | - if ($slug === $reg_step_slug) { |
|
| 1336 | - return $reg_step_completed; |
|
| 1337 | - } |
|
| 1338 | - // skip to next reg step in loop |
|
| 1339 | - continue; |
|
| 1340 | - } |
|
| 1341 | - // $check_all must be true, else we would never have gotten to this point |
|
| 1342 | - if ($slug === $reg_step_slug) { |
|
| 1343 | - // if we reach this point, then we are testing either: |
|
| 1344 | - // all_reg_steps_completed_except() or |
|
| 1345 | - // all_reg_steps_completed_except_final_step(), |
|
| 1346 | - // and since this is the reg step EXCEPTION being tested |
|
| 1347 | - // we want to return true (yes true) if this reg step is NOT completed |
|
| 1348 | - // ie: "is everything completed except the final step?" |
|
| 1349 | - // "that is correct... the final step is not completed, but all others are." |
|
| 1350 | - return $reg_step_completed !== true; |
|
| 1351 | - } |
|
| 1352 | - if ($reg_step_completed !== true) { |
|
| 1353 | - // if any reg step is NOT completed, then ALL steps are not completed |
|
| 1354 | - return false; |
|
| 1355 | - } |
|
| 1356 | - } |
|
| 1357 | - return true; |
|
| 1358 | - } |
|
| 1359 | - |
|
| 1360 | - |
|
| 1361 | - /** |
|
| 1362 | - * all_reg_steps_completed |
|
| 1363 | - * returns: |
|
| 1364 | - * true if ALL reg steps have been marked as completed |
|
| 1365 | - * or false if any step is not completed |
|
| 1366 | - * |
|
| 1367 | - * @return bool |
|
| 1368 | - * @throws EE_Error |
|
| 1369 | - * @throws InvalidArgumentException |
|
| 1370 | - * @throws InvalidDataTypeException |
|
| 1371 | - * @throws InvalidInterfaceException |
|
| 1372 | - * @throws ReflectionException |
|
| 1373 | - */ |
|
| 1374 | - public function all_reg_steps_completed() |
|
| 1375 | - { |
|
| 1376 | - return $this->_reg_steps_completed(); |
|
| 1377 | - } |
|
| 1378 | - |
|
| 1379 | - |
|
| 1380 | - /** |
|
| 1381 | - * all_reg_steps_completed_except |
|
| 1382 | - * returns: |
|
| 1383 | - * true if ALL reg steps, except a particular step that you wish to skip over, have been marked as completed |
|
| 1384 | - * or false if any other step is not completed |
|
| 1385 | - * or false if ALL steps are completed including the exception you are testing !!! |
|
| 1386 | - * |
|
| 1387 | - * @param string $exception |
|
| 1388 | - * @return bool |
|
| 1389 | - * @throws EE_Error |
|
| 1390 | - * @throws InvalidArgumentException |
|
| 1391 | - * @throws InvalidDataTypeException |
|
| 1392 | - * @throws InvalidInterfaceException |
|
| 1393 | - * @throws ReflectionException |
|
| 1394 | - */ |
|
| 1395 | - public function all_reg_steps_completed_except($exception = '') |
|
| 1396 | - { |
|
| 1397 | - return $this->_reg_steps_completed($exception); |
|
| 1398 | - } |
|
| 1399 | - |
|
| 1400 | - |
|
| 1401 | - /** |
|
| 1402 | - * all_reg_steps_completed_except |
|
| 1403 | - * returns: |
|
| 1404 | - * true if ALL reg steps, except the final step, have been marked as completed |
|
| 1405 | - * or false if any step is not completed |
|
| 1406 | - * or false if ALL steps are completed including the final step !!! |
|
| 1407 | - * |
|
| 1408 | - * @return bool |
|
| 1409 | - * @throws EE_Error |
|
| 1410 | - * @throws InvalidArgumentException |
|
| 1411 | - * @throws InvalidDataTypeException |
|
| 1412 | - * @throws InvalidInterfaceException |
|
| 1413 | - * @throws ReflectionException |
|
| 1414 | - */ |
|
| 1415 | - public function all_reg_steps_completed_except_final_step() |
|
| 1416 | - { |
|
| 1417 | - return $this->_reg_steps_completed('finalize_registration'); |
|
| 1418 | - } |
|
| 1419 | - |
|
| 1420 | - |
|
| 1421 | - /** |
|
| 1422 | - * reg_step_completed |
|
| 1423 | - * returns: |
|
| 1424 | - * true if a specific reg step has been marked as completed |
|
| 1425 | - * a Unix timestamp if it has been initialized but not yet completed, |
|
| 1426 | - * or false if it has not yet been initialized |
|
| 1427 | - * |
|
| 1428 | - * @param string $reg_step_slug |
|
| 1429 | - * @return bool|int |
|
| 1430 | - * @throws EE_Error |
|
| 1431 | - * @throws InvalidArgumentException |
|
| 1432 | - * @throws InvalidDataTypeException |
|
| 1433 | - * @throws InvalidInterfaceException |
|
| 1434 | - * @throws ReflectionException |
|
| 1435 | - */ |
|
| 1436 | - public function reg_step_completed($reg_step_slug) |
|
| 1437 | - { |
|
| 1438 | - return $this->_reg_steps_completed($reg_step_slug, false); |
|
| 1439 | - } |
|
| 1440 | - |
|
| 1441 | - |
|
| 1442 | - /** |
|
| 1443 | - * completed_final_reg_step |
|
| 1444 | - * returns: |
|
| 1445 | - * true if the finalize_registration reg step has been marked as completed |
|
| 1446 | - * a Unix timestamp if it has been initialized but not yet completed, |
|
| 1447 | - * or false if it has not yet been initialized |
|
| 1448 | - * |
|
| 1449 | - * @return bool|int |
|
| 1450 | - * @throws EE_Error |
|
| 1451 | - * @throws InvalidArgumentException |
|
| 1452 | - * @throws InvalidDataTypeException |
|
| 1453 | - * @throws InvalidInterfaceException |
|
| 1454 | - * @throws ReflectionException |
|
| 1455 | - */ |
|
| 1456 | - public function final_reg_step_completed() |
|
| 1457 | - { |
|
| 1458 | - return $this->_reg_steps_completed('finalize_registration', false); |
|
| 1459 | - } |
|
| 1460 | - |
|
| 1461 | - |
|
| 1462 | - /** |
|
| 1463 | - * set_reg_step_initiated |
|
| 1464 | - * given a valid TXN_reg_step, this sets it's value to a unix timestamp |
|
| 1465 | - * |
|
| 1466 | - * @param string $reg_step_slug |
|
| 1467 | - * @return boolean |
|
| 1468 | - * @throws EE_Error |
|
| 1469 | - * @throws InvalidArgumentException |
|
| 1470 | - * @throws InvalidDataTypeException |
|
| 1471 | - * @throws InvalidInterfaceException |
|
| 1472 | - * @throws ReflectionException |
|
| 1473 | - */ |
|
| 1474 | - public function set_reg_step_initiated($reg_step_slug) |
|
| 1475 | - { |
|
| 1476 | - return $this->_set_reg_step_completed_status($reg_step_slug, time()); |
|
| 1477 | - } |
|
| 1478 | - |
|
| 1479 | - |
|
| 1480 | - /** |
|
| 1481 | - * set_reg_step_completed |
|
| 1482 | - * given a valid TXN_reg_step, this sets the step as completed |
|
| 1483 | - * |
|
| 1484 | - * @param string $reg_step_slug |
|
| 1485 | - * @return boolean |
|
| 1486 | - * @throws EE_Error |
|
| 1487 | - * @throws InvalidArgumentException |
|
| 1488 | - * @throws InvalidDataTypeException |
|
| 1489 | - * @throws InvalidInterfaceException |
|
| 1490 | - * @throws ReflectionException |
|
| 1491 | - */ |
|
| 1492 | - public function set_reg_step_completed($reg_step_slug) |
|
| 1493 | - { |
|
| 1494 | - return $this->_set_reg_step_completed_status($reg_step_slug, true); |
|
| 1495 | - } |
|
| 1496 | - |
|
| 1497 | - |
|
| 1498 | - /** |
|
| 1499 | - * set_reg_step_completed |
|
| 1500 | - * given a valid TXN_reg_step slug, this sets the step as NOT completed |
|
| 1501 | - * |
|
| 1502 | - * @param string $reg_step_slug |
|
| 1503 | - * @return boolean |
|
| 1504 | - * @throws EE_Error |
|
| 1505 | - * @throws InvalidArgumentException |
|
| 1506 | - * @throws InvalidDataTypeException |
|
| 1507 | - * @throws InvalidInterfaceException |
|
| 1508 | - * @throws ReflectionException |
|
| 1509 | - */ |
|
| 1510 | - public function set_reg_step_not_completed($reg_step_slug) |
|
| 1511 | - { |
|
| 1512 | - return $this->_set_reg_step_completed_status($reg_step_slug, false); |
|
| 1513 | - } |
|
| 1514 | - |
|
| 1515 | - |
|
| 1516 | - /** |
|
| 1517 | - * set_reg_step_completed |
|
| 1518 | - * given a valid reg step slug, this sets the TXN_reg_step completed status which is either: |
|
| 1519 | - * |
|
| 1520 | - * @param string $reg_step_slug |
|
| 1521 | - * @param boolean|int $status |
|
| 1522 | - * @return boolean |
|
| 1523 | - * @throws EE_Error |
|
| 1524 | - * @throws InvalidArgumentException |
|
| 1525 | - * @throws InvalidDataTypeException |
|
| 1526 | - * @throws InvalidInterfaceException |
|
| 1527 | - * @throws ReflectionException |
|
| 1528 | - */ |
|
| 1529 | - private function _set_reg_step_completed_status($reg_step_slug, $status) |
|
| 1530 | - { |
|
| 1531 | - // validate status |
|
| 1532 | - $status = is_bool($status) || is_int($status) ? $status : false; |
|
| 1533 | - // get reg steps array |
|
| 1534 | - $txn_reg_steps = $this->reg_steps(); |
|
| 1535 | - // if reg step does NOT exist |
|
| 1536 | - if (! isset($txn_reg_steps[ $reg_step_slug ])) { |
|
| 1537 | - return false; |
|
| 1538 | - } |
|
| 1539 | - // if we're trying to complete a step that is already completed |
|
| 1540 | - if ($txn_reg_steps[ $reg_step_slug ] === true) { |
|
| 1541 | - return true; |
|
| 1542 | - } |
|
| 1543 | - // if we're trying to complete a step that hasn't even started |
|
| 1544 | - if ($status === true && $txn_reg_steps[ $reg_step_slug ] === false) { |
|
| 1545 | - return false; |
|
| 1546 | - } |
|
| 1547 | - // if current status value matches the incoming value (no change) |
|
| 1548 | - // type casting as int means values should collapse to either 0, 1, or a timestamp like 1234567890 |
|
| 1549 | - if ((int) $txn_reg_steps[ $reg_step_slug ] === (int) $status) { |
|
| 1550 | - // this will happen in cases where multiple AJAX requests occur during the same step |
|
| 1551 | - return true; |
|
| 1552 | - } |
|
| 1553 | - // if we're trying to set a start time, but it has already been set... |
|
| 1554 | - if (is_numeric($status) && is_numeric($txn_reg_steps[ $reg_step_slug ])) { |
|
| 1555 | - // skip the update below, but don't return FALSE so that errors won't be displayed |
|
| 1556 | - return true; |
|
| 1557 | - } |
|
| 1558 | - // update completed status |
|
| 1559 | - $txn_reg_steps[ $reg_step_slug ] = $status; |
|
| 1560 | - $this->set_reg_steps($txn_reg_steps); |
|
| 1561 | - $this->save(); |
|
| 1562 | - return true; |
|
| 1563 | - } |
|
| 1564 | - |
|
| 1565 | - |
|
| 1566 | - /** |
|
| 1567 | - * remove_reg_step |
|
| 1568 | - * given a valid TXN_reg_step slug, this will remove (unset) |
|
| 1569 | - * the reg step from the TXN reg step array |
|
| 1570 | - * |
|
| 1571 | - * @param string $reg_step_slug |
|
| 1572 | - * @return void |
|
| 1573 | - * @throws EE_Error |
|
| 1574 | - * @throws InvalidArgumentException |
|
| 1575 | - * @throws InvalidDataTypeException |
|
| 1576 | - * @throws InvalidInterfaceException |
|
| 1577 | - * @throws ReflectionException |
|
| 1578 | - */ |
|
| 1579 | - public function remove_reg_step($reg_step_slug) |
|
| 1580 | - { |
|
| 1581 | - // get reg steps array |
|
| 1582 | - $txn_reg_steps = $this->reg_steps(); |
|
| 1583 | - unset($txn_reg_steps[ $reg_step_slug ]); |
|
| 1584 | - $this->set_reg_steps($txn_reg_steps); |
|
| 1585 | - } |
|
| 1586 | - |
|
| 1587 | - |
|
| 1588 | - /** |
|
| 1589 | - * toggle_failed_transaction_status |
|
| 1590 | - * upgrades a TXNs status from failed to abandoned, |
|
| 1591 | - * meaning that contact information has been captured for at least one registrant |
|
| 1592 | - * |
|
| 1593 | - * @param bool $save |
|
| 1594 | - * @return bool |
|
| 1595 | - * @throws EE_Error |
|
| 1596 | - * @throws InvalidArgumentException |
|
| 1597 | - * @throws InvalidDataTypeException |
|
| 1598 | - * @throws InvalidInterfaceException |
|
| 1599 | - * @throws ReflectionException |
|
| 1600 | - */ |
|
| 1601 | - public function toggle_failed_transaction_status($save = true) |
|
| 1602 | - { |
|
| 1603 | - // if TXN status is still set as "failed"... |
|
| 1604 | - if ($this->status_ID() === EEM_Transaction::failed_status_code) { |
|
| 1605 | - $this->set_status(EEM_Transaction::abandoned_status_code); |
|
| 1606 | - if ($save) { |
|
| 1607 | - $this->save(); |
|
| 1608 | - } |
|
| 1609 | - return true; |
|
| 1610 | - } |
|
| 1611 | - return false; |
|
| 1612 | - } |
|
| 1613 | - |
|
| 1614 | - |
|
| 1615 | - /** |
|
| 1616 | - * toggle_abandoned_transaction_status |
|
| 1617 | - * upgrades a TXNs status from failed or abandoned to incomplete |
|
| 1618 | - * |
|
| 1619 | - * @return bool |
|
| 1620 | - * @throws EE_Error |
|
| 1621 | - * @throws InvalidArgumentException |
|
| 1622 | - * @throws InvalidDataTypeException |
|
| 1623 | - * @throws InvalidInterfaceException |
|
| 1624 | - * @throws ReflectionException |
|
| 1625 | - */ |
|
| 1626 | - public function toggle_abandoned_transaction_status() |
|
| 1627 | - { |
|
| 1628 | - // if TXN status has not been updated already due to a payment, and is still set as "failed" or "abandoned"... |
|
| 1629 | - $txn_status = $this->status_ID(); |
|
| 1630 | - if ($txn_status === EEM_Transaction::failed_status_code |
|
| 1631 | - || $txn_status === EEM_Transaction::abandoned_status_code |
|
| 1632 | - ) { |
|
| 1633 | - // if a contact record for the primary registrant has been created |
|
| 1634 | - if ($this->primary_registration() instanceof EE_Registration |
|
| 1635 | - && $this->primary_registration()->attendee() instanceof EE_Attendee |
|
| 1636 | - ) { |
|
| 1637 | - $this->set_status(EEM_Transaction::incomplete_status_code); |
|
| 1638 | - } else { |
|
| 1639 | - // no contact record? yer abandoned! |
|
| 1640 | - $this->set_status(EEM_Transaction::abandoned_status_code); |
|
| 1641 | - } |
|
| 1642 | - return true; |
|
| 1643 | - } |
|
| 1644 | - return false; |
|
| 1645 | - } |
|
| 1646 | - |
|
| 1647 | - |
|
| 1648 | - /** |
|
| 1649 | - * checks if an Abandoned TXN has any related payments, and if so, |
|
| 1650 | - * updates the TXN status based on the amount paid |
|
| 1651 | - * |
|
| 1652 | - * @throws EE_Error |
|
| 1653 | - * @throws InvalidDataTypeException |
|
| 1654 | - * @throws InvalidInterfaceException |
|
| 1655 | - * @throws InvalidArgumentException |
|
| 1656 | - * @throws RuntimeException |
|
| 1657 | - * @throws ReflectionException |
|
| 1658 | - */ |
|
| 1659 | - public function verify_abandoned_transaction_status() |
|
| 1660 | - { |
|
| 1661 | - if ($this->status_ID() !== EEM_Transaction::abandoned_status_code) { |
|
| 1662 | - return; |
|
| 1663 | - } |
|
| 1664 | - $payments = $this->get_many_related('Payment'); |
|
| 1665 | - if (! empty($payments)) { |
|
| 1666 | - foreach ($payments as $payment) { |
|
| 1667 | - if ($payment instanceof EE_Payment) { |
|
| 1668 | - // kk this TXN should NOT be abandoned |
|
| 1669 | - $this->update_status_based_on_total_paid(); |
|
| 1670 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 1671 | - EE_Error::add_attention( |
|
| 1672 | - sprintf( |
|
| 1673 | - esc_html__( |
|
| 1674 | - 'The status for Transaction #%1$d has been updated from "Abandoned" to "%2$s", because at least one payment has been made towards it. If the payment appears in the "Payment Details" table below, you may need to edit its status and/or other details as well.', |
|
| 1675 | - 'event_espresso' |
|
| 1676 | - ), |
|
| 1677 | - $this->ID(), |
|
| 1678 | - $this->pretty_status() |
|
| 1679 | - ) |
|
| 1680 | - ); |
|
| 1681 | - } |
|
| 1682 | - // get final reg step status |
|
| 1683 | - $finalized = $this->final_reg_step_completed(); |
|
| 1684 | - // if the 'finalize_registration' step has been initiated (has a timestamp) |
|
| 1685 | - // but has not yet been fully completed (TRUE) |
|
| 1686 | - if (is_int($finalized) && $finalized !== false && $finalized !== true) { |
|
| 1687 | - $this->set_reg_step_completed('finalize_registration'); |
|
| 1688 | - $this->save(); |
|
| 1689 | - } |
|
| 1690 | - } |
|
| 1691 | - } |
|
| 1692 | - } |
|
| 1693 | - } |
|
| 1694 | - |
|
| 1695 | - |
|
| 1696 | - /** |
|
| 1697 | - * @since 4.10.4.p |
|
| 1698 | - * @throws EE_Error |
|
| 1699 | - * @throws InvalidArgumentException |
|
| 1700 | - * @throws InvalidDataTypeException |
|
| 1701 | - * @throws InvalidInterfaceException |
|
| 1702 | - * @throws ReflectionException |
|
| 1703 | - * @throws RuntimeException |
|
| 1704 | - */ |
|
| 1705 | - public function recalculateLineItems() |
|
| 1706 | - { |
|
| 1707 | - $total_line_item = $this->total_line_item(false); |
|
| 1708 | - if ($total_line_item instanceof EE_Line_Item) { |
|
| 1709 | - EEH_Line_Item::resetIsTaxableForTickets($total_line_item); |
|
| 1710 | - return EEH_Line_Item::apply_taxes($total_line_item, true); |
|
| 1711 | - } |
|
| 1712 | - return false; |
|
| 1713 | - } |
|
| 16 | + /** |
|
| 17 | + * The length of time in seconds that a lock is applied before being considered expired. |
|
| 18 | + * It is not long because a transaction should only be locked for the duration of the request that locked it |
|
| 19 | + */ |
|
| 20 | + const LOCK_EXPIRATION = 2; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * txn status upon initial construction. |
|
| 24 | + * |
|
| 25 | + * @var string |
|
| 26 | + */ |
|
| 27 | + protected $_old_txn_status; |
|
| 28 | + |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @param array $props_n_values incoming values |
|
| 32 | + * @param string $timezone incoming timezone |
|
| 33 | + * (if not set the timezone set for the website will be used.) |
|
| 34 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 35 | + * date_format and the second value is the time format |
|
| 36 | + * @return EE_Transaction |
|
| 37 | + * @throws EE_Error |
|
| 38 | + * @throws InvalidArgumentException |
|
| 39 | + * @throws InvalidDataTypeException |
|
| 40 | + * @throws InvalidInterfaceException |
|
| 41 | + * @throws ReflectionException |
|
| 42 | + */ |
|
| 43 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 44 | + { |
|
| 45 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 46 | + $txn = $has_object |
|
| 47 | + ? $has_object |
|
| 48 | + : new self($props_n_values, false, $timezone, $date_formats); |
|
| 49 | + if (! $has_object) { |
|
| 50 | + $txn->set_old_txn_status($txn->status_ID()); |
|
| 51 | + } |
|
| 52 | + return $txn; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @param array $props_n_values incoming values from the database |
|
| 58 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 59 | + * the website will be used. |
|
| 60 | + * @return EE_Transaction |
|
| 61 | + * @throws EE_Error |
|
| 62 | + * @throws InvalidArgumentException |
|
| 63 | + * @throws InvalidDataTypeException |
|
| 64 | + * @throws InvalidInterfaceException |
|
| 65 | + * @throws ReflectionException |
|
| 66 | + */ |
|
| 67 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 68 | + { |
|
| 69 | + $txn = new self($props_n_values, true, $timezone); |
|
| 70 | + $txn->set_old_txn_status($txn->status_ID()); |
|
| 71 | + return $txn; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Sets a meta field indicating that this TXN is locked and should not be updated in the db. |
|
| 77 | + * If a lock has already been set, then we will attempt to remove it in case it has expired. |
|
| 78 | + * If that also fails, then an exception is thrown. |
|
| 79 | + * |
|
| 80 | + * @throws EE_Error |
|
| 81 | + * @throws InvalidArgumentException |
|
| 82 | + * @throws InvalidDataTypeException |
|
| 83 | + * @throws InvalidInterfaceException |
|
| 84 | + * @throws ReflectionException |
|
| 85 | + */ |
|
| 86 | + public function lock() |
|
| 87 | + { |
|
| 88 | + // attempt to set lock, but if that fails... |
|
| 89 | + if (! $this->add_extra_meta('lock', time(), true)) { |
|
| 90 | + // then attempt to remove the lock in case it is expired |
|
| 91 | + if ($this->_remove_expired_lock()) { |
|
| 92 | + // if removal was successful, then try setting lock again |
|
| 93 | + $this->lock(); |
|
| 94 | + } else { |
|
| 95 | + // but if the lock can not be removed, then throw an exception |
|
| 96 | + throw new EE_Error( |
|
| 97 | + sprintf( |
|
| 98 | + __( |
|
| 99 | + 'Could not lock Transaction %1$d because it is already locked, meaning another part of the system is currently editing it. It should already be unlocked by the time you read this, so please refresh the page and try again.', |
|
| 100 | + 'event_espresso' |
|
| 101 | + ), |
|
| 102 | + $this->ID() |
|
| 103 | + ) |
|
| 104 | + ); |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * removes transaction lock applied in EE_Transaction::lock() |
|
| 112 | + * |
|
| 113 | + * @return int |
|
| 114 | + * @throws EE_Error |
|
| 115 | + * @throws InvalidArgumentException |
|
| 116 | + * @throws InvalidDataTypeException |
|
| 117 | + * @throws InvalidInterfaceException |
|
| 118 | + * @throws ReflectionException |
|
| 119 | + */ |
|
| 120 | + public function unlock() |
|
| 121 | + { |
|
| 122 | + return $this->delete_extra_meta('lock'); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Decides whether or not now is the right time to update the transaction. |
|
| 128 | + * This is useful because we don't always know if it is safe to update the transaction |
|
| 129 | + * and its related data. why? |
|
| 130 | + * because it's possible that the transaction is being used in another |
|
| 131 | + * request and could overwrite anything we save. |
|
| 132 | + * So we want to only update the txn once we know that won't happen. |
|
| 133 | + * We also check that the lock isn't expired, and remove it if it is |
|
| 134 | + * |
|
| 135 | + * @return boolean |
|
| 136 | + * @throws EE_Error |
|
| 137 | + * @throws InvalidArgumentException |
|
| 138 | + * @throws InvalidDataTypeException |
|
| 139 | + * @throws InvalidInterfaceException |
|
| 140 | + * @throws ReflectionException |
|
| 141 | + */ |
|
| 142 | + public function is_locked() |
|
| 143 | + { |
|
| 144 | + // if TXN is not locked, then return false immediately |
|
| 145 | + if (! $this->_get_lock()) { |
|
| 146 | + return false; |
|
| 147 | + } |
|
| 148 | + // if not, then let's try and remove the lock in case it's expired... |
|
| 149 | + // _remove_expired_lock() returns 0 when lock is valid (ie: removed = false) |
|
| 150 | + // and a positive number if the lock was removed (ie: number of locks deleted), |
|
| 151 | + // so we need to return the opposite |
|
| 152 | + return ! $this->_remove_expired_lock() ? true : false; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Gets the meta field indicating that this TXN is locked |
|
| 158 | + * |
|
| 159 | + * @return int |
|
| 160 | + * @throws EE_Error |
|
| 161 | + * @throws InvalidArgumentException |
|
| 162 | + * @throws InvalidDataTypeException |
|
| 163 | + * @throws InvalidInterfaceException |
|
| 164 | + * @throws ReflectionException |
|
| 165 | + */ |
|
| 166 | + protected function _get_lock() |
|
| 167 | + { |
|
| 168 | + return (int) $this->get_extra_meta('lock', true, 0); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * If the lock on this transaction is expired, then we want to remove it so that the transaction can be updated |
|
| 174 | + * |
|
| 175 | + * @return int |
|
| 176 | + * @throws EE_Error |
|
| 177 | + * @throws InvalidArgumentException |
|
| 178 | + * @throws InvalidDataTypeException |
|
| 179 | + * @throws InvalidInterfaceException |
|
| 180 | + * @throws ReflectionException |
|
| 181 | + */ |
|
| 182 | + protected function _remove_expired_lock() |
|
| 183 | + { |
|
| 184 | + $locked = $this->_get_lock(); |
|
| 185 | + if ($locked && time() - EE_Transaction::LOCK_EXPIRATION > $locked) { |
|
| 186 | + return $this->unlock(); |
|
| 187 | + } |
|
| 188 | + return 0; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * Set transaction total |
|
| 194 | + * |
|
| 195 | + * @param float $total total value of transaction |
|
| 196 | + * @throws EE_Error |
|
| 197 | + * @throws InvalidArgumentException |
|
| 198 | + * @throws InvalidDataTypeException |
|
| 199 | + * @throws InvalidInterfaceException |
|
| 200 | + * @throws ReflectionException |
|
| 201 | + */ |
|
| 202 | + public function set_total($total = 0.00) |
|
| 203 | + { |
|
| 204 | + $this->set('TXN_total', (float) $total); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * Set Total Amount Paid to Date |
|
| 210 | + * |
|
| 211 | + * @param float $total_paid total amount paid to date (sum of all payments) |
|
| 212 | + * @throws EE_Error |
|
| 213 | + * @throws InvalidArgumentException |
|
| 214 | + * @throws InvalidDataTypeException |
|
| 215 | + * @throws InvalidInterfaceException |
|
| 216 | + * @throws ReflectionException |
|
| 217 | + */ |
|
| 218 | + public function set_paid($total_paid = 0.00) |
|
| 219 | + { |
|
| 220 | + $this->set('TXN_paid', (float) $total_paid); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * Set transaction status |
|
| 226 | + * |
|
| 227 | + * @param string $status whether the transaction is open, declined, accepted, |
|
| 228 | + * or any number of custom values that can be set |
|
| 229 | + * @throws EE_Error |
|
| 230 | + * @throws InvalidArgumentException |
|
| 231 | + * @throws InvalidDataTypeException |
|
| 232 | + * @throws InvalidInterfaceException |
|
| 233 | + * @throws ReflectionException |
|
| 234 | + */ |
|
| 235 | + public function set_status($status = '') |
|
| 236 | + { |
|
| 237 | + $this->set('STS_ID', $status); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * Set hash salt |
|
| 243 | + * |
|
| 244 | + * @param string $hash_salt required for some payment gateways |
|
| 245 | + * @throws EE_Error |
|
| 246 | + * @throws InvalidArgumentException |
|
| 247 | + * @throws InvalidDataTypeException |
|
| 248 | + * @throws InvalidInterfaceException |
|
| 249 | + * @throws ReflectionException |
|
| 250 | + */ |
|
| 251 | + public function set_hash_salt($hash_salt = '') |
|
| 252 | + { |
|
| 253 | + $this->set('TXN_hash_salt', $hash_salt); |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * Sets TXN_reg_steps array |
|
| 259 | + * |
|
| 260 | + * @param array $txn_reg_steps |
|
| 261 | + * @throws EE_Error |
|
| 262 | + * @throws InvalidArgumentException |
|
| 263 | + * @throws InvalidDataTypeException |
|
| 264 | + * @throws InvalidInterfaceException |
|
| 265 | + * @throws ReflectionException |
|
| 266 | + */ |
|
| 267 | + public function set_reg_steps(array $txn_reg_steps) |
|
| 268 | + { |
|
| 269 | + $this->set('TXN_reg_steps', $txn_reg_steps); |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + |
|
| 273 | + /** |
|
| 274 | + * Gets TXN_reg_steps |
|
| 275 | + * |
|
| 276 | + * @return array |
|
| 277 | + * @throws EE_Error |
|
| 278 | + * @throws InvalidArgumentException |
|
| 279 | + * @throws InvalidDataTypeException |
|
| 280 | + * @throws InvalidInterfaceException |
|
| 281 | + * @throws ReflectionException |
|
| 282 | + */ |
|
| 283 | + public function reg_steps() |
|
| 284 | + { |
|
| 285 | + $TXN_reg_steps = $this->get('TXN_reg_steps'); |
|
| 286 | + return is_array($TXN_reg_steps) ? (array) $TXN_reg_steps : array(); |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * @return string of transaction's total cost, with currency symbol and decimal |
|
| 292 | + * @throws EE_Error |
|
| 293 | + * @throws InvalidArgumentException |
|
| 294 | + * @throws InvalidDataTypeException |
|
| 295 | + * @throws InvalidInterfaceException |
|
| 296 | + * @throws ReflectionException |
|
| 297 | + */ |
|
| 298 | + public function pretty_total() |
|
| 299 | + { |
|
| 300 | + return $this->get_pretty('TXN_total'); |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * Gets the amount paid in a pretty string (formatted and with currency symbol) |
|
| 306 | + * |
|
| 307 | + * @return string |
|
| 308 | + * @throws EE_Error |
|
| 309 | + * @throws InvalidArgumentException |
|
| 310 | + * @throws InvalidDataTypeException |
|
| 311 | + * @throws InvalidInterfaceException |
|
| 312 | + * @throws ReflectionException |
|
| 313 | + */ |
|
| 314 | + public function pretty_paid() |
|
| 315 | + { |
|
| 316 | + return $this->get_pretty('TXN_paid'); |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + |
|
| 320 | + /** |
|
| 321 | + * calculate the amount remaining for this transaction and return; |
|
| 322 | + * |
|
| 323 | + * @return float amount remaining |
|
| 324 | + * @throws EE_Error |
|
| 325 | + * @throws InvalidArgumentException |
|
| 326 | + * @throws InvalidDataTypeException |
|
| 327 | + * @throws InvalidInterfaceException |
|
| 328 | + * @throws ReflectionException |
|
| 329 | + */ |
|
| 330 | + public function remaining() |
|
| 331 | + { |
|
| 332 | + return $this->total() - $this->paid(); |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * get Transaction Total |
|
| 338 | + * |
|
| 339 | + * @return float |
|
| 340 | + * @throws EE_Error |
|
| 341 | + * @throws InvalidArgumentException |
|
| 342 | + * @throws InvalidDataTypeException |
|
| 343 | + * @throws InvalidInterfaceException |
|
| 344 | + * @throws ReflectionException |
|
| 345 | + */ |
|
| 346 | + public function total() |
|
| 347 | + { |
|
| 348 | + return (float) $this->get('TXN_total'); |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * get Total Amount Paid to Date |
|
| 354 | + * |
|
| 355 | + * @return float |
|
| 356 | + * @throws EE_Error |
|
| 357 | + * @throws InvalidArgumentException |
|
| 358 | + * @throws InvalidDataTypeException |
|
| 359 | + * @throws InvalidInterfaceException |
|
| 360 | + * @throws ReflectionException |
|
| 361 | + */ |
|
| 362 | + public function paid() |
|
| 363 | + { |
|
| 364 | + return (float) $this->get('TXN_paid'); |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + |
|
| 368 | + /** |
|
| 369 | + * @return mixed|null |
|
| 370 | + * @throws EE_Error |
|
| 371 | + * @throws InvalidArgumentException |
|
| 372 | + * @throws InvalidDataTypeException |
|
| 373 | + * @throws InvalidInterfaceException |
|
| 374 | + * @throws ReflectionException |
|
| 375 | + */ |
|
| 376 | + public function get_cart_session() |
|
| 377 | + { |
|
| 378 | + $session_data = (array) $this->get('TXN_session_data'); |
|
| 379 | + return isset($session_data['cart']) && $session_data['cart'] instanceof EE_Cart |
|
| 380 | + ? $session_data['cart'] |
|
| 381 | + : null; |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * get Transaction session data |
|
| 387 | + * |
|
| 388 | + * @return array|mixed |
|
| 389 | + * @throws EE_Error |
|
| 390 | + * @throws InvalidArgumentException |
|
| 391 | + * @throws InvalidDataTypeException |
|
| 392 | + * @throws InvalidInterfaceException |
|
| 393 | + * @throws ReflectionException |
|
| 394 | + */ |
|
| 395 | + public function session_data() |
|
| 396 | + { |
|
| 397 | + $session_data = $this->get('TXN_session_data'); |
|
| 398 | + if (empty($session_data)) { |
|
| 399 | + $session_data = array( |
|
| 400 | + 'id' => null, |
|
| 401 | + 'user_id' => null, |
|
| 402 | + 'ip_address' => null, |
|
| 403 | + 'user_agent' => null, |
|
| 404 | + 'init_access' => null, |
|
| 405 | + 'last_access' => null, |
|
| 406 | + 'pages_visited' => array(), |
|
| 407 | + ); |
|
| 408 | + } |
|
| 409 | + return $session_data; |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + |
|
| 413 | + /** |
|
| 414 | + * Set session data within the TXN object |
|
| 415 | + * |
|
| 416 | + * @param EE_Session|array $session_data |
|
| 417 | + * @throws EE_Error |
|
| 418 | + * @throws InvalidArgumentException |
|
| 419 | + * @throws InvalidDataTypeException |
|
| 420 | + * @throws InvalidInterfaceException |
|
| 421 | + * @throws ReflectionException |
|
| 422 | + */ |
|
| 423 | + public function set_txn_session_data($session_data) |
|
| 424 | + { |
|
| 425 | + if ($session_data instanceof EE_Session) { |
|
| 426 | + $this->set('TXN_session_data', $session_data->get_session_data(null, true)); |
|
| 427 | + } else { |
|
| 428 | + $this->set('TXN_session_data', $session_data); |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + |
|
| 433 | + /** |
|
| 434 | + * get Transaction hash salt |
|
| 435 | + * |
|
| 436 | + * @return mixed |
|
| 437 | + * @throws EE_Error |
|
| 438 | + * @throws InvalidArgumentException |
|
| 439 | + * @throws InvalidDataTypeException |
|
| 440 | + * @throws InvalidInterfaceException |
|
| 441 | + * @throws ReflectionException |
|
| 442 | + */ |
|
| 443 | + public function hash_salt_() |
|
| 444 | + { |
|
| 445 | + return $this->get('TXN_hash_salt'); |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + |
|
| 449 | + /** |
|
| 450 | + * Returns the transaction datetime as either: |
|
| 451 | + * - unix timestamp format ($format = false, $gmt = true) |
|
| 452 | + * - formatted date string including the UTC (timezone) offset ($format = true ($gmt |
|
| 453 | + * has no affect with this option)), this also may include a timezone abbreviation if the |
|
| 454 | + * set timezone in this class differs from what the timezone is on the blog. |
|
| 455 | + * - formatted date string including the UTC (timezone) offset (default). |
|
| 456 | + * |
|
| 457 | + * @param boolean $format - whether to return a unix timestamp (default) or formatted date string |
|
| 458 | + * @param boolean $gmt - whether to return a unix timestamp with UTC offset applied (default) |
|
| 459 | + * or no UTC offset applied |
|
| 460 | + * @return string | int |
|
| 461 | + * @throws EE_Error |
|
| 462 | + * @throws InvalidArgumentException |
|
| 463 | + * @throws InvalidDataTypeException |
|
| 464 | + * @throws InvalidInterfaceException |
|
| 465 | + * @throws ReflectionException |
|
| 466 | + */ |
|
| 467 | + public function datetime($format = false, $gmt = false) |
|
| 468 | + { |
|
| 469 | + if ($format) { |
|
| 470 | + return $this->get_pretty('TXN_timestamp'); |
|
| 471 | + } |
|
| 472 | + if ($gmt) { |
|
| 473 | + return $this->get_raw('TXN_timestamp'); |
|
| 474 | + } |
|
| 475 | + return $this->get('TXN_timestamp'); |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + |
|
| 479 | + /** |
|
| 480 | + * Gets registrations on this transaction |
|
| 481 | + * |
|
| 482 | + * @param array $query_params array of query parameters |
|
| 483 | + * @param boolean $get_cached TRUE to retrieve cached registrations or FALSE to pull from the db |
|
| 484 | + * @return EE_Base_Class[]|EE_Registration[] |
|
| 485 | + * @throws EE_Error |
|
| 486 | + * @throws InvalidArgumentException |
|
| 487 | + * @throws InvalidDataTypeException |
|
| 488 | + * @throws InvalidInterfaceException |
|
| 489 | + * @throws ReflectionException |
|
| 490 | + */ |
|
| 491 | + public function registrations($query_params = array(), $get_cached = false) |
|
| 492 | + { |
|
| 493 | + $query_params = (empty($query_params) || ! is_array($query_params)) |
|
| 494 | + ? array( |
|
| 495 | + 'order_by' => array( |
|
| 496 | + 'Event.EVT_name' => 'ASC', |
|
| 497 | + 'Attendee.ATT_lname' => 'ASC', |
|
| 498 | + 'Attendee.ATT_fname' => 'ASC', |
|
| 499 | + ), |
|
| 500 | + ) |
|
| 501 | + : $query_params; |
|
| 502 | + $query_params = $get_cached ? array() : $query_params; |
|
| 503 | + return $this->get_many_related('Registration', $query_params); |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + |
|
| 507 | + /** |
|
| 508 | + * Gets all the attendees for this transaction (handy for use with EE_Attendee's get_registrations_for_event |
|
| 509 | + * function for getting attendees and how many registrations they each have for an event) |
|
| 510 | + * |
|
| 511 | + * @return mixed EE_Attendee[] by default, int if $output is set to 'COUNT' |
|
| 512 | + * @throws EE_Error |
|
| 513 | + * @throws InvalidArgumentException |
|
| 514 | + * @throws InvalidDataTypeException |
|
| 515 | + * @throws InvalidInterfaceException |
|
| 516 | + * @throws ReflectionException |
|
| 517 | + */ |
|
| 518 | + public function attendees() |
|
| 519 | + { |
|
| 520 | + return $this->get_many_related('Attendee', array(array('Registration.Transaction.TXN_ID' => $this->ID()))); |
|
| 521 | + } |
|
| 522 | + |
|
| 523 | + |
|
| 524 | + /** |
|
| 525 | + * Gets payments for this transaction. Unlike other such functions, order by 'DESC' by default |
|
| 526 | + * |
|
| 527 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 528 | + * @return EE_Base_Class[]|EE_Payment[] |
|
| 529 | + * @throws EE_Error |
|
| 530 | + * @throws InvalidArgumentException |
|
| 531 | + * @throws InvalidDataTypeException |
|
| 532 | + * @throws InvalidInterfaceException |
|
| 533 | + * @throws ReflectionException |
|
| 534 | + */ |
|
| 535 | + public function payments($query_params = array()) |
|
| 536 | + { |
|
| 537 | + return $this->get_many_related('Payment', $query_params); |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + |
|
| 541 | + /** |
|
| 542 | + * gets only approved payments for this transaction |
|
| 543 | + * |
|
| 544 | + * @return EE_Base_Class[]|EE_Payment[] |
|
| 545 | + * @throws EE_Error |
|
| 546 | + * @throws InvalidArgumentException |
|
| 547 | + * @throws ReflectionException |
|
| 548 | + * @throws InvalidDataTypeException |
|
| 549 | + * @throws InvalidInterfaceException |
|
| 550 | + */ |
|
| 551 | + public function approved_payments() |
|
| 552 | + { |
|
| 553 | + EE_Registry::instance()->load_model('Payment'); |
|
| 554 | + return $this->get_many_related( |
|
| 555 | + 'Payment', |
|
| 556 | + array( |
|
| 557 | + array('STS_ID' => EEM_Payment::status_id_approved), |
|
| 558 | + 'order_by' => array('PAY_timestamp' => 'DESC'), |
|
| 559 | + ) |
|
| 560 | + ); |
|
| 561 | + } |
|
| 562 | + |
|
| 563 | + |
|
| 564 | + /** |
|
| 565 | + * Gets all payments which have not been approved |
|
| 566 | + * |
|
| 567 | + * @return EE_Base_Class[]|EEI_Payment[] |
|
| 568 | + * @throws EE_Error if a model is misconfigured somehow |
|
| 569 | + * @throws InvalidArgumentException |
|
| 570 | + * @throws InvalidDataTypeException |
|
| 571 | + * @throws InvalidInterfaceException |
|
| 572 | + * @throws ReflectionException |
|
| 573 | + */ |
|
| 574 | + public function pending_payments() |
|
| 575 | + { |
|
| 576 | + return $this->get_many_related( |
|
| 577 | + 'Payment', |
|
| 578 | + array( |
|
| 579 | + array( |
|
| 580 | + 'STS_ID' => EEM_Payment::status_id_pending, |
|
| 581 | + ), |
|
| 582 | + 'order_by' => array( |
|
| 583 | + 'PAY_timestamp' => 'DESC', |
|
| 584 | + ), |
|
| 585 | + ) |
|
| 586 | + ); |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + |
|
| 590 | + /** |
|
| 591 | + * echoes $this->pretty_status() |
|
| 592 | + * |
|
| 593 | + * @param bool $show_icons |
|
| 594 | + * @throws EE_Error |
|
| 595 | + * @throws InvalidArgumentException |
|
| 596 | + * @throws InvalidDataTypeException |
|
| 597 | + * @throws InvalidInterfaceException |
|
| 598 | + * @throws ReflectionException |
|
| 599 | + */ |
|
| 600 | + public function e_pretty_status($show_icons = false) |
|
| 601 | + { |
|
| 602 | + echo $this->pretty_status($show_icons); |
|
| 603 | + } |
|
| 604 | + |
|
| 605 | + |
|
| 606 | + /** |
|
| 607 | + * returns a pretty version of the status, good for displaying to users |
|
| 608 | + * |
|
| 609 | + * @param bool $show_icons |
|
| 610 | + * @return string |
|
| 611 | + * @throws EE_Error |
|
| 612 | + * @throws InvalidArgumentException |
|
| 613 | + * @throws InvalidDataTypeException |
|
| 614 | + * @throws InvalidInterfaceException |
|
| 615 | + * @throws ReflectionException |
|
| 616 | + */ |
|
| 617 | + public function pretty_status($show_icons = false) |
|
| 618 | + { |
|
| 619 | + $status = EEM_Status::instance()->localized_status( |
|
| 620 | + array($this->status_ID() => __('unknown', 'event_espresso')), |
|
| 621 | + false, |
|
| 622 | + 'sentence' |
|
| 623 | + ); |
|
| 624 | + $icon = ''; |
|
| 625 | + switch ($this->status_ID()) { |
|
| 626 | + case EEM_Transaction::complete_status_code: |
|
| 627 | + $icon = $show_icons ? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>' : ''; |
|
| 628 | + break; |
|
| 629 | + case EEM_Transaction::incomplete_status_code: |
|
| 630 | + $icon = $show_icons ? '<span class="dashicons dashicons-marker ee-icon-size-16 lt-blue-text"></span>' |
|
| 631 | + : ''; |
|
| 632 | + break; |
|
| 633 | + case EEM_Transaction::abandoned_status_code: |
|
| 634 | + $icon = $show_icons ? '<span class="dashicons dashicons-marker ee-icon-size-16 red-text"></span>' : ''; |
|
| 635 | + break; |
|
| 636 | + case EEM_Transaction::failed_status_code: |
|
| 637 | + $icon = $show_icons ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' : ''; |
|
| 638 | + break; |
|
| 639 | + case EEM_Transaction::overpaid_status_code: |
|
| 640 | + $icon = $show_icons ? '<span class="dashicons dashicons-plus ee-icon-size-16 orange-text"></span>' : ''; |
|
| 641 | + break; |
|
| 642 | + } |
|
| 643 | + return $icon . $status[ $this->status_ID() ]; |
|
| 644 | + } |
|
| 645 | + |
|
| 646 | + |
|
| 647 | + /** |
|
| 648 | + * get Transaction Status |
|
| 649 | + * |
|
| 650 | + * @return mixed |
|
| 651 | + * @throws EE_Error |
|
| 652 | + * @throws InvalidArgumentException |
|
| 653 | + * @throws InvalidDataTypeException |
|
| 654 | + * @throws InvalidInterfaceException |
|
| 655 | + * @throws ReflectionException |
|
| 656 | + */ |
|
| 657 | + public function status_ID() |
|
| 658 | + { |
|
| 659 | + return $this->get('STS_ID'); |
|
| 660 | + } |
|
| 661 | + |
|
| 662 | + |
|
| 663 | + /** |
|
| 664 | + * Returns TRUE or FALSE for whether or not this transaction cost any money |
|
| 665 | + * |
|
| 666 | + * @return boolean |
|
| 667 | + * @throws EE_Error |
|
| 668 | + * @throws InvalidArgumentException |
|
| 669 | + * @throws InvalidDataTypeException |
|
| 670 | + * @throws InvalidInterfaceException |
|
| 671 | + * @throws ReflectionException |
|
| 672 | + */ |
|
| 673 | + public function is_free() |
|
| 674 | + { |
|
| 675 | + return EEH_Money::compare_floats($this->get('TXN_total'), 0, '=='); |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + |
|
| 679 | + /** |
|
| 680 | + * Returns whether this transaction is complete |
|
| 681 | + * Useful in templates and other logic for deciding if we should ask for another payment... |
|
| 682 | + * |
|
| 683 | + * @return boolean |
|
| 684 | + * @throws EE_Error |
|
| 685 | + * @throws InvalidArgumentException |
|
| 686 | + * @throws InvalidDataTypeException |
|
| 687 | + * @throws InvalidInterfaceException |
|
| 688 | + * @throws ReflectionException |
|
| 689 | + */ |
|
| 690 | + public function is_completed() |
|
| 691 | + { |
|
| 692 | + return $this->status_ID() === EEM_Transaction::complete_status_code; |
|
| 693 | + } |
|
| 694 | + |
|
| 695 | + |
|
| 696 | + /** |
|
| 697 | + * Returns whether this transaction is incomplete |
|
| 698 | + * Useful in templates and other logic for deciding if we should ask for another payment... |
|
| 699 | + * |
|
| 700 | + * @return boolean |
|
| 701 | + * @throws EE_Error |
|
| 702 | + * @throws InvalidArgumentException |
|
| 703 | + * @throws InvalidDataTypeException |
|
| 704 | + * @throws InvalidInterfaceException |
|
| 705 | + * @throws ReflectionException |
|
| 706 | + */ |
|
| 707 | + public function is_incomplete() |
|
| 708 | + { |
|
| 709 | + return $this->status_ID() === EEM_Transaction::incomplete_status_code; |
|
| 710 | + } |
|
| 711 | + |
|
| 712 | + |
|
| 713 | + /** |
|
| 714 | + * Returns whether this transaction is overpaid |
|
| 715 | + * Useful in templates and other logic for deciding if monies need to be refunded |
|
| 716 | + * |
|
| 717 | + * @return boolean |
|
| 718 | + * @throws EE_Error |
|
| 719 | + * @throws InvalidArgumentException |
|
| 720 | + * @throws InvalidDataTypeException |
|
| 721 | + * @throws InvalidInterfaceException |
|
| 722 | + * @throws ReflectionException |
|
| 723 | + */ |
|
| 724 | + public function is_overpaid() |
|
| 725 | + { |
|
| 726 | + return $this->status_ID() === EEM_Transaction::overpaid_status_code; |
|
| 727 | + } |
|
| 728 | + |
|
| 729 | + |
|
| 730 | + /** |
|
| 731 | + * Returns whether this transaction was abandoned |
|
| 732 | + * meaning that the transaction/registration process was somehow interrupted and never completed |
|
| 733 | + * but that contact information exists for at least one registrant |
|
| 734 | + * |
|
| 735 | + * @return boolean |
|
| 736 | + * @throws EE_Error |
|
| 737 | + * @throws InvalidArgumentException |
|
| 738 | + * @throws InvalidDataTypeException |
|
| 739 | + * @throws InvalidInterfaceException |
|
| 740 | + * @throws ReflectionException |
|
| 741 | + */ |
|
| 742 | + public function is_abandoned() |
|
| 743 | + { |
|
| 744 | + return $this->status_ID() === EEM_Transaction::abandoned_status_code; |
|
| 745 | + } |
|
| 746 | + |
|
| 747 | + |
|
| 748 | + /** |
|
| 749 | + * Returns whether this transaction failed |
|
| 750 | + * meaning that the transaction/registration process was somehow interrupted and never completed |
|
| 751 | + * and that NO contact information exists for any registrants |
|
| 752 | + * |
|
| 753 | + * @return boolean |
|
| 754 | + * @throws EE_Error |
|
| 755 | + * @throws InvalidArgumentException |
|
| 756 | + * @throws InvalidDataTypeException |
|
| 757 | + * @throws InvalidInterfaceException |
|
| 758 | + * @throws ReflectionException |
|
| 759 | + */ |
|
| 760 | + public function failed() |
|
| 761 | + { |
|
| 762 | + return $this->status_ID() === EEM_Transaction::failed_status_code; |
|
| 763 | + } |
|
| 764 | + |
|
| 765 | + |
|
| 766 | + /** |
|
| 767 | + * This returns the url for the invoice of this transaction |
|
| 768 | + * |
|
| 769 | + * @param string $type 'html' or 'pdf' (default is pdf) |
|
| 770 | + * @return string |
|
| 771 | + * @throws EE_Error |
|
| 772 | + * @throws InvalidArgumentException |
|
| 773 | + * @throws InvalidDataTypeException |
|
| 774 | + * @throws InvalidInterfaceException |
|
| 775 | + * @throws ReflectionException |
|
| 776 | + */ |
|
| 777 | + public function invoice_url($type = 'html') |
|
| 778 | + { |
|
| 779 | + $REG = $this->primary_registration(); |
|
| 780 | + if (! $REG instanceof EE_Registration) { |
|
| 781 | + return ''; |
|
| 782 | + } |
|
| 783 | + return $REG->invoice_url($type); |
|
| 784 | + } |
|
| 785 | + |
|
| 786 | + |
|
| 787 | + /** |
|
| 788 | + * Gets the primary registration only |
|
| 789 | + * |
|
| 790 | + * @return EE_Base_Class|EE_Registration |
|
| 791 | + * @throws EE_Error |
|
| 792 | + * @throws InvalidArgumentException |
|
| 793 | + * @throws InvalidDataTypeException |
|
| 794 | + * @throws InvalidInterfaceException |
|
| 795 | + * @throws ReflectionException |
|
| 796 | + */ |
|
| 797 | + public function primary_registration() |
|
| 798 | + { |
|
| 799 | + $registrations = (array) $this->get_many_related( |
|
| 800 | + 'Registration', |
|
| 801 | + array(array('REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT)) |
|
| 802 | + ); |
|
| 803 | + foreach ($registrations as $registration) { |
|
| 804 | + // valid registration that is NOT cancelled or declined ? |
|
| 805 | + if ($registration instanceof EE_Registration |
|
| 806 | + && ! in_array($registration->status_ID(), EEM_Registration::closed_reg_statuses(), true) |
|
| 807 | + ) { |
|
| 808 | + return $registration; |
|
| 809 | + } |
|
| 810 | + } |
|
| 811 | + // nothing valid found, so just return first thing from array of results |
|
| 812 | + return reset($registrations); |
|
| 813 | + } |
|
| 814 | + |
|
| 815 | + |
|
| 816 | + /** |
|
| 817 | + * Gets the URL for viewing the receipt |
|
| 818 | + * |
|
| 819 | + * @param string $type 'pdf' or 'html' (default is 'html') |
|
| 820 | + * @return string |
|
| 821 | + * @throws EE_Error |
|
| 822 | + * @throws InvalidArgumentException |
|
| 823 | + * @throws InvalidDataTypeException |
|
| 824 | + * @throws InvalidInterfaceException |
|
| 825 | + * @throws ReflectionException |
|
| 826 | + */ |
|
| 827 | + public function receipt_url($type = 'html') |
|
| 828 | + { |
|
| 829 | + $REG = $this->primary_registration(); |
|
| 830 | + if (! $REG instanceof EE_Registration) { |
|
| 831 | + return ''; |
|
| 832 | + } |
|
| 833 | + return $REG->receipt_url($type); |
|
| 834 | + } |
|
| 835 | + |
|
| 836 | + |
|
| 837 | + /** |
|
| 838 | + * Gets the URL of the thank you page with this registration REG_url_link added as |
|
| 839 | + * a query parameter |
|
| 840 | + * |
|
| 841 | + * @return string |
|
| 842 | + * @throws EE_Error |
|
| 843 | + * @throws InvalidArgumentException |
|
| 844 | + * @throws InvalidDataTypeException |
|
| 845 | + * @throws InvalidInterfaceException |
|
| 846 | + * @throws ReflectionException |
|
| 847 | + */ |
|
| 848 | + public function payment_overview_url() |
|
| 849 | + { |
|
| 850 | + $primary_registration = $this->primary_registration(); |
|
| 851 | + return $primary_registration instanceof EE_Registration ? $primary_registration->payment_overview_url() : false; |
|
| 852 | + } |
|
| 853 | + |
|
| 854 | + |
|
| 855 | + /** |
|
| 856 | + * @return string |
|
| 857 | + * @throws EE_Error |
|
| 858 | + * @throws InvalidArgumentException |
|
| 859 | + * @throws InvalidDataTypeException |
|
| 860 | + * @throws InvalidInterfaceException |
|
| 861 | + * @throws ReflectionException |
|
| 862 | + */ |
|
| 863 | + public function gateway_response_on_transaction() |
|
| 864 | + { |
|
| 865 | + $payment = $this->get_first_related('Payment'); |
|
| 866 | + return $payment instanceof EE_Payment ? $payment->gateway_response() : ''; |
|
| 867 | + } |
|
| 868 | + |
|
| 869 | + |
|
| 870 | + /** |
|
| 871 | + * Get the status object of this object |
|
| 872 | + * |
|
| 873 | + * @return EE_Base_Class|EE_Status |
|
| 874 | + * @throws EE_Error |
|
| 875 | + * @throws InvalidArgumentException |
|
| 876 | + * @throws InvalidDataTypeException |
|
| 877 | + * @throws InvalidInterfaceException |
|
| 878 | + * @throws ReflectionException |
|
| 879 | + */ |
|
| 880 | + public function status_obj() |
|
| 881 | + { |
|
| 882 | + return $this->get_first_related('Status'); |
|
| 883 | + } |
|
| 884 | + |
|
| 885 | + |
|
| 886 | + /** |
|
| 887 | + * Gets all the extra meta info on this payment |
|
| 888 | + * |
|
| 889 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 890 | + * @return EE_Base_Class[]|EE_Extra_Meta |
|
| 891 | + * @throws EE_Error |
|
| 892 | + * @throws InvalidArgumentException |
|
| 893 | + * @throws InvalidDataTypeException |
|
| 894 | + * @throws InvalidInterfaceException |
|
| 895 | + * @throws ReflectionException |
|
| 896 | + */ |
|
| 897 | + public function extra_meta($query_params = array()) |
|
| 898 | + { |
|
| 899 | + return $this->get_many_related('Extra_Meta', $query_params); |
|
| 900 | + } |
|
| 901 | + |
|
| 902 | + |
|
| 903 | + /** |
|
| 904 | + * Wrapper for _add_relation_to |
|
| 905 | + * |
|
| 906 | + * @param EE_Registration $registration |
|
| 907 | + * @return EE_Base_Class the relation was added to |
|
| 908 | + * @throws EE_Error |
|
| 909 | + * @throws InvalidArgumentException |
|
| 910 | + * @throws InvalidDataTypeException |
|
| 911 | + * @throws InvalidInterfaceException |
|
| 912 | + * @throws ReflectionException |
|
| 913 | + */ |
|
| 914 | + public function add_registration(EE_Registration $registration) |
|
| 915 | + { |
|
| 916 | + return $this->_add_relation_to($registration, 'Registration'); |
|
| 917 | + } |
|
| 918 | + |
|
| 919 | + |
|
| 920 | + /** |
|
| 921 | + * Removes the given registration from being related (even before saving this transaction). |
|
| 922 | + * If an ID/index is provided and this transaction isn't saved yet, removes it from list of cached relations |
|
| 923 | + * |
|
| 924 | + * @param int $registration_or_id |
|
| 925 | + * @return EE_Base_Class that was removed from being related |
|
| 926 | + * @throws EE_Error |
|
| 927 | + * @throws InvalidArgumentException |
|
| 928 | + * @throws InvalidDataTypeException |
|
| 929 | + * @throws InvalidInterfaceException |
|
| 930 | + * @throws ReflectionException |
|
| 931 | + */ |
|
| 932 | + public function remove_registration_with_id($registration_or_id) |
|
| 933 | + { |
|
| 934 | + return $this->_remove_relation_to($registration_or_id, 'Registration'); |
|
| 935 | + } |
|
| 936 | + |
|
| 937 | + |
|
| 938 | + /** |
|
| 939 | + * Gets all the line items which are for ACTUAL items |
|
| 940 | + * |
|
| 941 | + * @return EE_Line_Item[] |
|
| 942 | + * @throws EE_Error |
|
| 943 | + * @throws InvalidArgumentException |
|
| 944 | + * @throws InvalidDataTypeException |
|
| 945 | + * @throws InvalidInterfaceException |
|
| 946 | + * @throws ReflectionException |
|
| 947 | + */ |
|
| 948 | + public function items_purchased() |
|
| 949 | + { |
|
| 950 | + return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_line_item))); |
|
| 951 | + } |
|
| 952 | + |
|
| 953 | + |
|
| 954 | + /** |
|
| 955 | + * Wrapper for _add_relation_to |
|
| 956 | + * |
|
| 957 | + * @param EE_Line_Item $line_item |
|
| 958 | + * @return EE_Base_Class the relation was added to |
|
| 959 | + * @throws EE_Error |
|
| 960 | + * @throws InvalidArgumentException |
|
| 961 | + * @throws InvalidDataTypeException |
|
| 962 | + * @throws InvalidInterfaceException |
|
| 963 | + * @throws ReflectionException |
|
| 964 | + */ |
|
| 965 | + public function add_line_item(EE_Line_Item $line_item) |
|
| 966 | + { |
|
| 967 | + return $this->_add_relation_to($line_item, 'Line_Item'); |
|
| 968 | + } |
|
| 969 | + |
|
| 970 | + |
|
| 971 | + /** |
|
| 972 | + * Gets ALL the line items related to this transaction (unstructured) |
|
| 973 | + * |
|
| 974 | + * @param array $query_params |
|
| 975 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 976 | + * @throws EE_Error |
|
| 977 | + * @throws InvalidArgumentException |
|
| 978 | + * @throws InvalidDataTypeException |
|
| 979 | + * @throws InvalidInterfaceException |
|
| 980 | + * @throws ReflectionException |
|
| 981 | + */ |
|
| 982 | + public function line_items($query_params = array()) |
|
| 983 | + { |
|
| 984 | + return $this->get_many_related('Line_Item', $query_params); |
|
| 985 | + } |
|
| 986 | + |
|
| 987 | + |
|
| 988 | + /** |
|
| 989 | + * Gets all the line items which are taxes on the total |
|
| 990 | + * |
|
| 991 | + * @return EE_Line_Item[] |
|
| 992 | + * @throws EE_Error |
|
| 993 | + * @throws InvalidArgumentException |
|
| 994 | + * @throws InvalidDataTypeException |
|
| 995 | + * @throws InvalidInterfaceException |
|
| 996 | + * @throws ReflectionException |
|
| 997 | + */ |
|
| 998 | + public function tax_items() |
|
| 999 | + { |
|
| 1000 | + return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_tax))); |
|
| 1001 | + } |
|
| 1002 | + |
|
| 1003 | + |
|
| 1004 | + /** |
|
| 1005 | + * Gets the total line item (which is a parent of all other related line items, |
|
| 1006 | + * meaning it takes them all into account on its total) |
|
| 1007 | + * |
|
| 1008 | + * @param bool $create_if_not_found |
|
| 1009 | + * @return \EE_Line_Item |
|
| 1010 | + * @throws EE_Error |
|
| 1011 | + * @throws InvalidArgumentException |
|
| 1012 | + * @throws InvalidDataTypeException |
|
| 1013 | + * @throws InvalidInterfaceException |
|
| 1014 | + * @throws ReflectionException |
|
| 1015 | + */ |
|
| 1016 | + public function total_line_item($create_if_not_found = true) |
|
| 1017 | + { |
|
| 1018 | + $item = $this->get_first_related('Line_Item', array(array('LIN_type' => EEM_Line_Item::type_total))); |
|
| 1019 | + if (! $item && $create_if_not_found) { |
|
| 1020 | + $item = EEH_Line_Item::create_total_line_item($this); |
|
| 1021 | + } |
|
| 1022 | + return $item; |
|
| 1023 | + } |
|
| 1024 | + |
|
| 1025 | + |
|
| 1026 | + /** |
|
| 1027 | + * Returns the total amount of tax on this transaction |
|
| 1028 | + * (assumes there's only one tax subtotal line item) |
|
| 1029 | + * |
|
| 1030 | + * @return float |
|
| 1031 | + * @throws EE_Error |
|
| 1032 | + * @throws InvalidArgumentException |
|
| 1033 | + * @throws InvalidDataTypeException |
|
| 1034 | + * @throws InvalidInterfaceException |
|
| 1035 | + * @throws ReflectionException |
|
| 1036 | + */ |
|
| 1037 | + public function tax_total() |
|
| 1038 | + { |
|
| 1039 | + $tax_line_item = $this->tax_total_line_item(); |
|
| 1040 | + if ($tax_line_item) { |
|
| 1041 | + return (float) $tax_line_item->total(); |
|
| 1042 | + } |
|
| 1043 | + return (float) 0; |
|
| 1044 | + } |
|
| 1045 | + |
|
| 1046 | + |
|
| 1047 | + /** |
|
| 1048 | + * Gets the tax subtotal line item (assumes there's only one) |
|
| 1049 | + * |
|
| 1050 | + * @return EE_Line_Item |
|
| 1051 | + * @throws EE_Error |
|
| 1052 | + * @throws InvalidArgumentException |
|
| 1053 | + * @throws InvalidDataTypeException |
|
| 1054 | + * @throws InvalidInterfaceException |
|
| 1055 | + * @throws ReflectionException |
|
| 1056 | + */ |
|
| 1057 | + public function tax_total_line_item() |
|
| 1058 | + { |
|
| 1059 | + return EEH_Line_Item::get_taxes_subtotal($this->total_line_item()); |
|
| 1060 | + } |
|
| 1061 | + |
|
| 1062 | + |
|
| 1063 | + /** |
|
| 1064 | + * Gets the array of billing info for the gateway and for this transaction's primary registration's attendee. |
|
| 1065 | + * |
|
| 1066 | + * @return EE_Form_Section_Proper |
|
| 1067 | + * @throws EE_Error |
|
| 1068 | + * @throws InvalidArgumentException |
|
| 1069 | + * @throws InvalidDataTypeException |
|
| 1070 | + * @throws InvalidInterfaceException |
|
| 1071 | + * @throws ReflectionException |
|
| 1072 | + */ |
|
| 1073 | + public function billing_info() |
|
| 1074 | + { |
|
| 1075 | + $payment_method = $this->payment_method(); |
|
| 1076 | + if (! $payment_method) { |
|
| 1077 | + EE_Error::add_error( |
|
| 1078 | + __( |
|
| 1079 | + 'Could not find billing info for transaction because no gateway has been used for it yet', |
|
| 1080 | + 'event_espresso' |
|
| 1081 | + ), |
|
| 1082 | + __FILE__, |
|
| 1083 | + __FUNCTION__, |
|
| 1084 | + __LINE__ |
|
| 1085 | + ); |
|
| 1086 | + return null; |
|
| 1087 | + } |
|
| 1088 | + $primary_reg = $this->primary_registration(); |
|
| 1089 | + if (! $primary_reg) { |
|
| 1090 | + EE_Error::add_error( |
|
| 1091 | + __( |
|
| 1092 | + 'Cannot get billing info for gateway %s on transaction because no primary registration exists', |
|
| 1093 | + 'event_espresso' |
|
| 1094 | + ), |
|
| 1095 | + __FILE__, |
|
| 1096 | + __FUNCTION__, |
|
| 1097 | + __LINE__ |
|
| 1098 | + ); |
|
| 1099 | + return null; |
|
| 1100 | + } |
|
| 1101 | + $attendee = $primary_reg->attendee(); |
|
| 1102 | + if (! $attendee) { |
|
| 1103 | + EE_Error::add_error( |
|
| 1104 | + __( |
|
| 1105 | + 'Cannot get billing info for gateway %s on transaction because the primary registration has no attendee exists', |
|
| 1106 | + 'event_espresso' |
|
| 1107 | + ), |
|
| 1108 | + __FILE__, |
|
| 1109 | + __FUNCTION__, |
|
| 1110 | + __LINE__ |
|
| 1111 | + ); |
|
| 1112 | + return null; |
|
| 1113 | + } |
|
| 1114 | + return $attendee->billing_info_for_payment_method($payment_method); |
|
| 1115 | + } |
|
| 1116 | + |
|
| 1117 | + |
|
| 1118 | + /** |
|
| 1119 | + * Gets PMD_ID |
|
| 1120 | + * |
|
| 1121 | + * @return int |
|
| 1122 | + * @throws EE_Error |
|
| 1123 | + * @throws InvalidArgumentException |
|
| 1124 | + * @throws InvalidDataTypeException |
|
| 1125 | + * @throws InvalidInterfaceException |
|
| 1126 | + * @throws ReflectionException |
|
| 1127 | + */ |
|
| 1128 | + public function payment_method_ID() |
|
| 1129 | + { |
|
| 1130 | + return $this->get('PMD_ID'); |
|
| 1131 | + } |
|
| 1132 | + |
|
| 1133 | + |
|
| 1134 | + /** |
|
| 1135 | + * Sets PMD_ID |
|
| 1136 | + * |
|
| 1137 | + * @param int $PMD_ID |
|
| 1138 | + * @throws EE_Error |
|
| 1139 | + * @throws InvalidArgumentException |
|
| 1140 | + * @throws InvalidDataTypeException |
|
| 1141 | + * @throws InvalidInterfaceException |
|
| 1142 | + * @throws ReflectionException |
|
| 1143 | + */ |
|
| 1144 | + public function set_payment_method_ID($PMD_ID) |
|
| 1145 | + { |
|
| 1146 | + $this->set('PMD_ID', $PMD_ID); |
|
| 1147 | + } |
|
| 1148 | + |
|
| 1149 | + |
|
| 1150 | + /** |
|
| 1151 | + * Gets the last-used payment method on this transaction |
|
| 1152 | + * (we COULD just use the last-made payment, but some payment methods, namely |
|
| 1153 | + * offline ones, dont' create payments) |
|
| 1154 | + * |
|
| 1155 | + * @return EE_Payment_Method |
|
| 1156 | + * @throws EE_Error |
|
| 1157 | + * @throws InvalidArgumentException |
|
| 1158 | + * @throws InvalidDataTypeException |
|
| 1159 | + * @throws InvalidInterfaceException |
|
| 1160 | + * @throws ReflectionException |
|
| 1161 | + */ |
|
| 1162 | + public function payment_method() |
|
| 1163 | + { |
|
| 1164 | + $pm = $this->get_first_related('Payment_Method'); |
|
| 1165 | + if ($pm instanceof EE_Payment_Method) { |
|
| 1166 | + return $pm; |
|
| 1167 | + } |
|
| 1168 | + $last_payment = $this->last_payment(); |
|
| 1169 | + if ($last_payment instanceof EE_Payment && $last_payment->payment_method()) { |
|
| 1170 | + return $last_payment->payment_method(); |
|
| 1171 | + } |
|
| 1172 | + return null; |
|
| 1173 | + } |
|
| 1174 | + |
|
| 1175 | + |
|
| 1176 | + /** |
|
| 1177 | + * Gets the last payment made |
|
| 1178 | + * |
|
| 1179 | + * @return EE_Base_Class|EE_Payment |
|
| 1180 | + * @throws EE_Error |
|
| 1181 | + * @throws InvalidArgumentException |
|
| 1182 | + * @throws InvalidDataTypeException |
|
| 1183 | + * @throws InvalidInterfaceException |
|
| 1184 | + * @throws ReflectionException |
|
| 1185 | + */ |
|
| 1186 | + public function last_payment() |
|
| 1187 | + { |
|
| 1188 | + return $this->get_first_related('Payment', array('order_by' => array('PAY_ID' => 'desc'))); |
|
| 1189 | + } |
|
| 1190 | + |
|
| 1191 | + |
|
| 1192 | + /** |
|
| 1193 | + * Gets all the line items which are unrelated to tickets on this transaction |
|
| 1194 | + * |
|
| 1195 | + * @return EE_Line_Item[] |
|
| 1196 | + * @throws EE_Error |
|
| 1197 | + * @throws InvalidArgumentException |
|
| 1198 | + * @throws InvalidDataTypeException |
|
| 1199 | + * @throws InvalidInterfaceException |
|
| 1200 | + * @throws ReflectionException |
|
| 1201 | + */ |
|
| 1202 | + public function non_ticket_line_items() |
|
| 1203 | + { |
|
| 1204 | + return EEM_Line_Item::instance()->get_all_non_ticket_line_items_for_transaction($this->ID()); |
|
| 1205 | + } |
|
| 1206 | + |
|
| 1207 | + |
|
| 1208 | + /** |
|
| 1209 | + * possibly toggles TXN status |
|
| 1210 | + * |
|
| 1211 | + * @param boolean $update whether to save the TXN |
|
| 1212 | + * @return bool whether the TXN was saved |
|
| 1213 | + * @throws EE_Error |
|
| 1214 | + * @throws InvalidArgumentException |
|
| 1215 | + * @throws InvalidDataTypeException |
|
| 1216 | + * @throws InvalidInterfaceException |
|
| 1217 | + * @throws ReflectionException |
|
| 1218 | + * @throws RuntimeException |
|
| 1219 | + */ |
|
| 1220 | + public function update_status_based_on_total_paid($update = true) |
|
| 1221 | + { |
|
| 1222 | + // set transaction status based on comparison of TXN_paid vs TXN_total |
|
| 1223 | + if (EEH_Money::compare_floats($this->paid(), $this->total(), '>')) { |
|
| 1224 | + $new_txn_status = EEM_Transaction::overpaid_status_code; |
|
| 1225 | + } elseif (EEH_Money::compare_floats($this->paid(), $this->total())) { |
|
| 1226 | + $new_txn_status = EEM_Transaction::complete_status_code; |
|
| 1227 | + } elseif (EEH_Money::compare_floats($this->paid(), $this->total(), '<')) { |
|
| 1228 | + $new_txn_status = EEM_Transaction::incomplete_status_code; |
|
| 1229 | + } else { |
|
| 1230 | + throw new RuntimeException( |
|
| 1231 | + __('The total paid calculation for this transaction is inaccurate.', 'event_espresso') |
|
| 1232 | + ); |
|
| 1233 | + } |
|
| 1234 | + if ($new_txn_status !== $this->status_ID()) { |
|
| 1235 | + $this->set_status($new_txn_status); |
|
| 1236 | + if ($update) { |
|
| 1237 | + return $this->save() ? true : false; |
|
| 1238 | + } |
|
| 1239 | + } |
|
| 1240 | + return false; |
|
| 1241 | + } |
|
| 1242 | + |
|
| 1243 | + |
|
| 1244 | + /** |
|
| 1245 | + * Updates the transaction's status and total_paid based on all the payments |
|
| 1246 | + * that apply to it |
|
| 1247 | + * |
|
| 1248 | + * @deprecated |
|
| 1249 | + * @return array|bool |
|
| 1250 | + * @throws EE_Error |
|
| 1251 | + * @throws InvalidArgumentException |
|
| 1252 | + * @throws ReflectionException |
|
| 1253 | + * @throws InvalidDataTypeException |
|
| 1254 | + * @throws InvalidInterfaceException |
|
| 1255 | + */ |
|
| 1256 | + public function update_based_on_payments() |
|
| 1257 | + { |
|
| 1258 | + EE_Error::doing_it_wrong( |
|
| 1259 | + __CLASS__ . '::' . __FUNCTION__, |
|
| 1260 | + sprintf( |
|
| 1261 | + __('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
| 1262 | + 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' |
|
| 1263 | + ), |
|
| 1264 | + '4.6.0' |
|
| 1265 | + ); |
|
| 1266 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 1267 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 1268 | + return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment($this); |
|
| 1269 | + } |
|
| 1270 | + |
|
| 1271 | + |
|
| 1272 | + /** |
|
| 1273 | + * @return string |
|
| 1274 | + */ |
|
| 1275 | + public function old_txn_status() |
|
| 1276 | + { |
|
| 1277 | + return $this->_old_txn_status; |
|
| 1278 | + } |
|
| 1279 | + |
|
| 1280 | + |
|
| 1281 | + /** |
|
| 1282 | + * @param string $old_txn_status |
|
| 1283 | + */ |
|
| 1284 | + public function set_old_txn_status($old_txn_status) |
|
| 1285 | + { |
|
| 1286 | + // only set the first time |
|
| 1287 | + if ($this->_old_txn_status === null) { |
|
| 1288 | + $this->_old_txn_status = $old_txn_status; |
|
| 1289 | + } |
|
| 1290 | + } |
|
| 1291 | + |
|
| 1292 | + |
|
| 1293 | + /** |
|
| 1294 | + * reg_status_updated |
|
| 1295 | + * |
|
| 1296 | + * @return bool |
|
| 1297 | + * @throws EE_Error |
|
| 1298 | + * @throws InvalidArgumentException |
|
| 1299 | + * @throws InvalidDataTypeException |
|
| 1300 | + * @throws InvalidInterfaceException |
|
| 1301 | + * @throws ReflectionException |
|
| 1302 | + */ |
|
| 1303 | + public function txn_status_updated() |
|
| 1304 | + { |
|
| 1305 | + return $this->status_ID() !== $this->_old_txn_status && $this->_old_txn_status !== null; |
|
| 1306 | + } |
|
| 1307 | + |
|
| 1308 | + |
|
| 1309 | + /** |
|
| 1310 | + * _reg_steps_completed |
|
| 1311 | + * if $check_all is TRUE, then returns TRUE if ALL reg steps have been marked as completed, |
|
| 1312 | + * if a $reg_step_slug is provided, then this step will be skipped when testing for completion |
|
| 1313 | + * if $check_all is FALSE and a $reg_step_slug is provided, then ONLY that reg step will be tested for completion |
|
| 1314 | + * |
|
| 1315 | + * @param string $reg_step_slug |
|
| 1316 | + * @param bool $check_all |
|
| 1317 | + * @return bool|int |
|
| 1318 | + * @throws EE_Error |
|
| 1319 | + * @throws InvalidArgumentException |
|
| 1320 | + * @throws InvalidDataTypeException |
|
| 1321 | + * @throws InvalidInterfaceException |
|
| 1322 | + * @throws ReflectionException |
|
| 1323 | + */ |
|
| 1324 | + private function _reg_steps_completed($reg_step_slug = '', $check_all = true) |
|
| 1325 | + { |
|
| 1326 | + $reg_steps = $this->reg_steps(); |
|
| 1327 | + if (! is_array($reg_steps) || empty($reg_steps)) { |
|
| 1328 | + return false; |
|
| 1329 | + } |
|
| 1330 | + // loop thru reg steps array) |
|
| 1331 | + foreach ($reg_steps as $slug => $reg_step_completed) { |
|
| 1332 | + // if NOT checking ALL steps (only checking one step) |
|
| 1333 | + if (! $check_all) { |
|
| 1334 | + // and this is the one |
|
| 1335 | + if ($slug === $reg_step_slug) { |
|
| 1336 | + return $reg_step_completed; |
|
| 1337 | + } |
|
| 1338 | + // skip to next reg step in loop |
|
| 1339 | + continue; |
|
| 1340 | + } |
|
| 1341 | + // $check_all must be true, else we would never have gotten to this point |
|
| 1342 | + if ($slug === $reg_step_slug) { |
|
| 1343 | + // if we reach this point, then we are testing either: |
|
| 1344 | + // all_reg_steps_completed_except() or |
|
| 1345 | + // all_reg_steps_completed_except_final_step(), |
|
| 1346 | + // and since this is the reg step EXCEPTION being tested |
|
| 1347 | + // we want to return true (yes true) if this reg step is NOT completed |
|
| 1348 | + // ie: "is everything completed except the final step?" |
|
| 1349 | + // "that is correct... the final step is not completed, but all others are." |
|
| 1350 | + return $reg_step_completed !== true; |
|
| 1351 | + } |
|
| 1352 | + if ($reg_step_completed !== true) { |
|
| 1353 | + // if any reg step is NOT completed, then ALL steps are not completed |
|
| 1354 | + return false; |
|
| 1355 | + } |
|
| 1356 | + } |
|
| 1357 | + return true; |
|
| 1358 | + } |
|
| 1359 | + |
|
| 1360 | + |
|
| 1361 | + /** |
|
| 1362 | + * all_reg_steps_completed |
|
| 1363 | + * returns: |
|
| 1364 | + * true if ALL reg steps have been marked as completed |
|
| 1365 | + * or false if any step is not completed |
|
| 1366 | + * |
|
| 1367 | + * @return bool |
|
| 1368 | + * @throws EE_Error |
|
| 1369 | + * @throws InvalidArgumentException |
|
| 1370 | + * @throws InvalidDataTypeException |
|
| 1371 | + * @throws InvalidInterfaceException |
|
| 1372 | + * @throws ReflectionException |
|
| 1373 | + */ |
|
| 1374 | + public function all_reg_steps_completed() |
|
| 1375 | + { |
|
| 1376 | + return $this->_reg_steps_completed(); |
|
| 1377 | + } |
|
| 1378 | + |
|
| 1379 | + |
|
| 1380 | + /** |
|
| 1381 | + * all_reg_steps_completed_except |
|
| 1382 | + * returns: |
|
| 1383 | + * true if ALL reg steps, except a particular step that you wish to skip over, have been marked as completed |
|
| 1384 | + * or false if any other step is not completed |
|
| 1385 | + * or false if ALL steps are completed including the exception you are testing !!! |
|
| 1386 | + * |
|
| 1387 | + * @param string $exception |
|
| 1388 | + * @return bool |
|
| 1389 | + * @throws EE_Error |
|
| 1390 | + * @throws InvalidArgumentException |
|
| 1391 | + * @throws InvalidDataTypeException |
|
| 1392 | + * @throws InvalidInterfaceException |
|
| 1393 | + * @throws ReflectionException |
|
| 1394 | + */ |
|
| 1395 | + public function all_reg_steps_completed_except($exception = '') |
|
| 1396 | + { |
|
| 1397 | + return $this->_reg_steps_completed($exception); |
|
| 1398 | + } |
|
| 1399 | + |
|
| 1400 | + |
|
| 1401 | + /** |
|
| 1402 | + * all_reg_steps_completed_except |
|
| 1403 | + * returns: |
|
| 1404 | + * true if ALL reg steps, except the final step, have been marked as completed |
|
| 1405 | + * or false if any step is not completed |
|
| 1406 | + * or false if ALL steps are completed including the final step !!! |
|
| 1407 | + * |
|
| 1408 | + * @return bool |
|
| 1409 | + * @throws EE_Error |
|
| 1410 | + * @throws InvalidArgumentException |
|
| 1411 | + * @throws InvalidDataTypeException |
|
| 1412 | + * @throws InvalidInterfaceException |
|
| 1413 | + * @throws ReflectionException |
|
| 1414 | + */ |
|
| 1415 | + public function all_reg_steps_completed_except_final_step() |
|
| 1416 | + { |
|
| 1417 | + return $this->_reg_steps_completed('finalize_registration'); |
|
| 1418 | + } |
|
| 1419 | + |
|
| 1420 | + |
|
| 1421 | + /** |
|
| 1422 | + * reg_step_completed |
|
| 1423 | + * returns: |
|
| 1424 | + * true if a specific reg step has been marked as completed |
|
| 1425 | + * a Unix timestamp if it has been initialized but not yet completed, |
|
| 1426 | + * or false if it has not yet been initialized |
|
| 1427 | + * |
|
| 1428 | + * @param string $reg_step_slug |
|
| 1429 | + * @return bool|int |
|
| 1430 | + * @throws EE_Error |
|
| 1431 | + * @throws InvalidArgumentException |
|
| 1432 | + * @throws InvalidDataTypeException |
|
| 1433 | + * @throws InvalidInterfaceException |
|
| 1434 | + * @throws ReflectionException |
|
| 1435 | + */ |
|
| 1436 | + public function reg_step_completed($reg_step_slug) |
|
| 1437 | + { |
|
| 1438 | + return $this->_reg_steps_completed($reg_step_slug, false); |
|
| 1439 | + } |
|
| 1440 | + |
|
| 1441 | + |
|
| 1442 | + /** |
|
| 1443 | + * completed_final_reg_step |
|
| 1444 | + * returns: |
|
| 1445 | + * true if the finalize_registration reg step has been marked as completed |
|
| 1446 | + * a Unix timestamp if it has been initialized but not yet completed, |
|
| 1447 | + * or false if it has not yet been initialized |
|
| 1448 | + * |
|
| 1449 | + * @return bool|int |
|
| 1450 | + * @throws EE_Error |
|
| 1451 | + * @throws InvalidArgumentException |
|
| 1452 | + * @throws InvalidDataTypeException |
|
| 1453 | + * @throws InvalidInterfaceException |
|
| 1454 | + * @throws ReflectionException |
|
| 1455 | + */ |
|
| 1456 | + public function final_reg_step_completed() |
|
| 1457 | + { |
|
| 1458 | + return $this->_reg_steps_completed('finalize_registration', false); |
|
| 1459 | + } |
|
| 1460 | + |
|
| 1461 | + |
|
| 1462 | + /** |
|
| 1463 | + * set_reg_step_initiated |
|
| 1464 | + * given a valid TXN_reg_step, this sets it's value to a unix timestamp |
|
| 1465 | + * |
|
| 1466 | + * @param string $reg_step_slug |
|
| 1467 | + * @return boolean |
|
| 1468 | + * @throws EE_Error |
|
| 1469 | + * @throws InvalidArgumentException |
|
| 1470 | + * @throws InvalidDataTypeException |
|
| 1471 | + * @throws InvalidInterfaceException |
|
| 1472 | + * @throws ReflectionException |
|
| 1473 | + */ |
|
| 1474 | + public function set_reg_step_initiated($reg_step_slug) |
|
| 1475 | + { |
|
| 1476 | + return $this->_set_reg_step_completed_status($reg_step_slug, time()); |
|
| 1477 | + } |
|
| 1478 | + |
|
| 1479 | + |
|
| 1480 | + /** |
|
| 1481 | + * set_reg_step_completed |
|
| 1482 | + * given a valid TXN_reg_step, this sets the step as completed |
|
| 1483 | + * |
|
| 1484 | + * @param string $reg_step_slug |
|
| 1485 | + * @return boolean |
|
| 1486 | + * @throws EE_Error |
|
| 1487 | + * @throws InvalidArgumentException |
|
| 1488 | + * @throws InvalidDataTypeException |
|
| 1489 | + * @throws InvalidInterfaceException |
|
| 1490 | + * @throws ReflectionException |
|
| 1491 | + */ |
|
| 1492 | + public function set_reg_step_completed($reg_step_slug) |
|
| 1493 | + { |
|
| 1494 | + return $this->_set_reg_step_completed_status($reg_step_slug, true); |
|
| 1495 | + } |
|
| 1496 | + |
|
| 1497 | + |
|
| 1498 | + /** |
|
| 1499 | + * set_reg_step_completed |
|
| 1500 | + * given a valid TXN_reg_step slug, this sets the step as NOT completed |
|
| 1501 | + * |
|
| 1502 | + * @param string $reg_step_slug |
|
| 1503 | + * @return boolean |
|
| 1504 | + * @throws EE_Error |
|
| 1505 | + * @throws InvalidArgumentException |
|
| 1506 | + * @throws InvalidDataTypeException |
|
| 1507 | + * @throws InvalidInterfaceException |
|
| 1508 | + * @throws ReflectionException |
|
| 1509 | + */ |
|
| 1510 | + public function set_reg_step_not_completed($reg_step_slug) |
|
| 1511 | + { |
|
| 1512 | + return $this->_set_reg_step_completed_status($reg_step_slug, false); |
|
| 1513 | + } |
|
| 1514 | + |
|
| 1515 | + |
|
| 1516 | + /** |
|
| 1517 | + * set_reg_step_completed |
|
| 1518 | + * given a valid reg step slug, this sets the TXN_reg_step completed status which is either: |
|
| 1519 | + * |
|
| 1520 | + * @param string $reg_step_slug |
|
| 1521 | + * @param boolean|int $status |
|
| 1522 | + * @return boolean |
|
| 1523 | + * @throws EE_Error |
|
| 1524 | + * @throws InvalidArgumentException |
|
| 1525 | + * @throws InvalidDataTypeException |
|
| 1526 | + * @throws InvalidInterfaceException |
|
| 1527 | + * @throws ReflectionException |
|
| 1528 | + */ |
|
| 1529 | + private function _set_reg_step_completed_status($reg_step_slug, $status) |
|
| 1530 | + { |
|
| 1531 | + // validate status |
|
| 1532 | + $status = is_bool($status) || is_int($status) ? $status : false; |
|
| 1533 | + // get reg steps array |
|
| 1534 | + $txn_reg_steps = $this->reg_steps(); |
|
| 1535 | + // if reg step does NOT exist |
|
| 1536 | + if (! isset($txn_reg_steps[ $reg_step_slug ])) { |
|
| 1537 | + return false; |
|
| 1538 | + } |
|
| 1539 | + // if we're trying to complete a step that is already completed |
|
| 1540 | + if ($txn_reg_steps[ $reg_step_slug ] === true) { |
|
| 1541 | + return true; |
|
| 1542 | + } |
|
| 1543 | + // if we're trying to complete a step that hasn't even started |
|
| 1544 | + if ($status === true && $txn_reg_steps[ $reg_step_slug ] === false) { |
|
| 1545 | + return false; |
|
| 1546 | + } |
|
| 1547 | + // if current status value matches the incoming value (no change) |
|
| 1548 | + // type casting as int means values should collapse to either 0, 1, or a timestamp like 1234567890 |
|
| 1549 | + if ((int) $txn_reg_steps[ $reg_step_slug ] === (int) $status) { |
|
| 1550 | + // this will happen in cases where multiple AJAX requests occur during the same step |
|
| 1551 | + return true; |
|
| 1552 | + } |
|
| 1553 | + // if we're trying to set a start time, but it has already been set... |
|
| 1554 | + if (is_numeric($status) && is_numeric($txn_reg_steps[ $reg_step_slug ])) { |
|
| 1555 | + // skip the update below, but don't return FALSE so that errors won't be displayed |
|
| 1556 | + return true; |
|
| 1557 | + } |
|
| 1558 | + // update completed status |
|
| 1559 | + $txn_reg_steps[ $reg_step_slug ] = $status; |
|
| 1560 | + $this->set_reg_steps($txn_reg_steps); |
|
| 1561 | + $this->save(); |
|
| 1562 | + return true; |
|
| 1563 | + } |
|
| 1564 | + |
|
| 1565 | + |
|
| 1566 | + /** |
|
| 1567 | + * remove_reg_step |
|
| 1568 | + * given a valid TXN_reg_step slug, this will remove (unset) |
|
| 1569 | + * the reg step from the TXN reg step array |
|
| 1570 | + * |
|
| 1571 | + * @param string $reg_step_slug |
|
| 1572 | + * @return void |
|
| 1573 | + * @throws EE_Error |
|
| 1574 | + * @throws InvalidArgumentException |
|
| 1575 | + * @throws InvalidDataTypeException |
|
| 1576 | + * @throws InvalidInterfaceException |
|
| 1577 | + * @throws ReflectionException |
|
| 1578 | + */ |
|
| 1579 | + public function remove_reg_step($reg_step_slug) |
|
| 1580 | + { |
|
| 1581 | + // get reg steps array |
|
| 1582 | + $txn_reg_steps = $this->reg_steps(); |
|
| 1583 | + unset($txn_reg_steps[ $reg_step_slug ]); |
|
| 1584 | + $this->set_reg_steps($txn_reg_steps); |
|
| 1585 | + } |
|
| 1586 | + |
|
| 1587 | + |
|
| 1588 | + /** |
|
| 1589 | + * toggle_failed_transaction_status |
|
| 1590 | + * upgrades a TXNs status from failed to abandoned, |
|
| 1591 | + * meaning that contact information has been captured for at least one registrant |
|
| 1592 | + * |
|
| 1593 | + * @param bool $save |
|
| 1594 | + * @return bool |
|
| 1595 | + * @throws EE_Error |
|
| 1596 | + * @throws InvalidArgumentException |
|
| 1597 | + * @throws InvalidDataTypeException |
|
| 1598 | + * @throws InvalidInterfaceException |
|
| 1599 | + * @throws ReflectionException |
|
| 1600 | + */ |
|
| 1601 | + public function toggle_failed_transaction_status($save = true) |
|
| 1602 | + { |
|
| 1603 | + // if TXN status is still set as "failed"... |
|
| 1604 | + if ($this->status_ID() === EEM_Transaction::failed_status_code) { |
|
| 1605 | + $this->set_status(EEM_Transaction::abandoned_status_code); |
|
| 1606 | + if ($save) { |
|
| 1607 | + $this->save(); |
|
| 1608 | + } |
|
| 1609 | + return true; |
|
| 1610 | + } |
|
| 1611 | + return false; |
|
| 1612 | + } |
|
| 1613 | + |
|
| 1614 | + |
|
| 1615 | + /** |
|
| 1616 | + * toggle_abandoned_transaction_status |
|
| 1617 | + * upgrades a TXNs status from failed or abandoned to incomplete |
|
| 1618 | + * |
|
| 1619 | + * @return bool |
|
| 1620 | + * @throws EE_Error |
|
| 1621 | + * @throws InvalidArgumentException |
|
| 1622 | + * @throws InvalidDataTypeException |
|
| 1623 | + * @throws InvalidInterfaceException |
|
| 1624 | + * @throws ReflectionException |
|
| 1625 | + */ |
|
| 1626 | + public function toggle_abandoned_transaction_status() |
|
| 1627 | + { |
|
| 1628 | + // if TXN status has not been updated already due to a payment, and is still set as "failed" or "abandoned"... |
|
| 1629 | + $txn_status = $this->status_ID(); |
|
| 1630 | + if ($txn_status === EEM_Transaction::failed_status_code |
|
| 1631 | + || $txn_status === EEM_Transaction::abandoned_status_code |
|
| 1632 | + ) { |
|
| 1633 | + // if a contact record for the primary registrant has been created |
|
| 1634 | + if ($this->primary_registration() instanceof EE_Registration |
|
| 1635 | + && $this->primary_registration()->attendee() instanceof EE_Attendee |
|
| 1636 | + ) { |
|
| 1637 | + $this->set_status(EEM_Transaction::incomplete_status_code); |
|
| 1638 | + } else { |
|
| 1639 | + // no contact record? yer abandoned! |
|
| 1640 | + $this->set_status(EEM_Transaction::abandoned_status_code); |
|
| 1641 | + } |
|
| 1642 | + return true; |
|
| 1643 | + } |
|
| 1644 | + return false; |
|
| 1645 | + } |
|
| 1646 | + |
|
| 1647 | + |
|
| 1648 | + /** |
|
| 1649 | + * checks if an Abandoned TXN has any related payments, and if so, |
|
| 1650 | + * updates the TXN status based on the amount paid |
|
| 1651 | + * |
|
| 1652 | + * @throws EE_Error |
|
| 1653 | + * @throws InvalidDataTypeException |
|
| 1654 | + * @throws InvalidInterfaceException |
|
| 1655 | + * @throws InvalidArgumentException |
|
| 1656 | + * @throws RuntimeException |
|
| 1657 | + * @throws ReflectionException |
|
| 1658 | + */ |
|
| 1659 | + public function verify_abandoned_transaction_status() |
|
| 1660 | + { |
|
| 1661 | + if ($this->status_ID() !== EEM_Transaction::abandoned_status_code) { |
|
| 1662 | + return; |
|
| 1663 | + } |
|
| 1664 | + $payments = $this->get_many_related('Payment'); |
|
| 1665 | + if (! empty($payments)) { |
|
| 1666 | + foreach ($payments as $payment) { |
|
| 1667 | + if ($payment instanceof EE_Payment) { |
|
| 1668 | + // kk this TXN should NOT be abandoned |
|
| 1669 | + $this->update_status_based_on_total_paid(); |
|
| 1670 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 1671 | + EE_Error::add_attention( |
|
| 1672 | + sprintf( |
|
| 1673 | + esc_html__( |
|
| 1674 | + 'The status for Transaction #%1$d has been updated from "Abandoned" to "%2$s", because at least one payment has been made towards it. If the payment appears in the "Payment Details" table below, you may need to edit its status and/or other details as well.', |
|
| 1675 | + 'event_espresso' |
|
| 1676 | + ), |
|
| 1677 | + $this->ID(), |
|
| 1678 | + $this->pretty_status() |
|
| 1679 | + ) |
|
| 1680 | + ); |
|
| 1681 | + } |
|
| 1682 | + // get final reg step status |
|
| 1683 | + $finalized = $this->final_reg_step_completed(); |
|
| 1684 | + // if the 'finalize_registration' step has been initiated (has a timestamp) |
|
| 1685 | + // but has not yet been fully completed (TRUE) |
|
| 1686 | + if (is_int($finalized) && $finalized !== false && $finalized !== true) { |
|
| 1687 | + $this->set_reg_step_completed('finalize_registration'); |
|
| 1688 | + $this->save(); |
|
| 1689 | + } |
|
| 1690 | + } |
|
| 1691 | + } |
|
| 1692 | + } |
|
| 1693 | + } |
|
| 1694 | + |
|
| 1695 | + |
|
| 1696 | + /** |
|
| 1697 | + * @since 4.10.4.p |
|
| 1698 | + * @throws EE_Error |
|
| 1699 | + * @throws InvalidArgumentException |
|
| 1700 | + * @throws InvalidDataTypeException |
|
| 1701 | + * @throws InvalidInterfaceException |
|
| 1702 | + * @throws ReflectionException |
|
| 1703 | + * @throws RuntimeException |
|
| 1704 | + */ |
|
| 1705 | + public function recalculateLineItems() |
|
| 1706 | + { |
|
| 1707 | + $total_line_item = $this->total_line_item(false); |
|
| 1708 | + if ($total_line_item instanceof EE_Line_Item) { |
|
| 1709 | + EEH_Line_Item::resetIsTaxableForTickets($total_line_item); |
|
| 1710 | + return EEH_Line_Item::apply_taxes($total_line_item, true); |
|
| 1711 | + } |
|
| 1712 | + return false; |
|
| 1713 | + } |
|
| 1714 | 1714 | } |
@@ -20,1409 +20,1409 @@ |
||
| 20 | 20 | class General_Settings_Admin_Page extends EE_Admin_Page |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * _question_group |
|
| 25 | - * holds the specific question group object for the question group details screen |
|
| 26 | - * |
|
| 27 | - * @var object |
|
| 28 | - */ |
|
| 29 | - protected $_question_group; |
|
| 30 | - |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Initialize basic properties. |
|
| 34 | - */ |
|
| 35 | - protected function _init_page_props() |
|
| 36 | - { |
|
| 37 | - $this->page_slug = GEN_SET_PG_SLUG; |
|
| 38 | - $this->page_label = GEN_SET_LABEL; |
|
| 39 | - $this->_admin_base_url = GEN_SET_ADMIN_URL; |
|
| 40 | - $this->_admin_base_path = GEN_SET_ADMIN; |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Set ajax hooks |
|
| 46 | - */ |
|
| 47 | - protected function _ajax_hooks() |
|
| 48 | - { |
|
| 49 | - add_action('wp_ajax_espresso_display_country_settings', array($this, 'display_country_settings')); |
|
| 50 | - add_action('wp_ajax_espresso_display_country_states', array($this, 'display_country_states')); |
|
| 51 | - add_action('wp_ajax_espresso_delete_state', array($this, 'delete_state'), 10, 3); |
|
| 52 | - add_action('wp_ajax_espresso_add_new_state', array($this, 'add_new_state')); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * More page properties initialization. |
|
| 58 | - */ |
|
| 59 | - protected function _define_page_props() |
|
| 60 | - { |
|
| 61 | - $this->_admin_page_title = GEN_SET_LABEL; |
|
| 62 | - $this->_labels = array( |
|
| 63 | - 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
| 64 | - ); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Set page routes property. |
|
| 70 | - */ |
|
| 71 | - protected function _set_page_routes() |
|
| 72 | - { |
|
| 73 | - $this->_page_routes = array( |
|
| 74 | - |
|
| 75 | - 'critical_pages' => array( |
|
| 76 | - 'func' => '_espresso_page_settings', |
|
| 77 | - 'capability' => 'manage_options', |
|
| 78 | - ), |
|
| 79 | - 'update_espresso_page_settings' => array( |
|
| 80 | - 'func' => '_update_espresso_page_settings', |
|
| 81 | - 'capability' => 'manage_options', |
|
| 82 | - 'noheader' => true, |
|
| 83 | - ), |
|
| 84 | - 'default' => array( |
|
| 85 | - 'func' => '_your_organization_settings', |
|
| 86 | - 'capability' => 'manage_options', |
|
| 87 | - ), |
|
| 88 | - |
|
| 89 | - 'update_your_organization_settings' => array( |
|
| 90 | - 'func' => '_update_your_organization_settings', |
|
| 91 | - 'capability' => 'manage_options', |
|
| 92 | - 'noheader' => true, |
|
| 93 | - ), |
|
| 94 | - |
|
| 95 | - 'admin_option_settings' => array( |
|
| 96 | - 'func' => '_admin_option_settings', |
|
| 97 | - 'capability' => 'manage_options', |
|
| 98 | - ), |
|
| 99 | - |
|
| 100 | - 'update_admin_option_settings' => array( |
|
| 101 | - 'func' => '_update_admin_option_settings', |
|
| 102 | - 'capability' => 'manage_options', |
|
| 103 | - 'noheader' => true, |
|
| 104 | - ), |
|
| 105 | - |
|
| 106 | - 'country_settings' => array( |
|
| 107 | - 'func' => '_country_settings', |
|
| 108 | - 'capability' => 'manage_options', |
|
| 109 | - ), |
|
| 110 | - |
|
| 111 | - 'update_country_settings' => array( |
|
| 112 | - 'func' => '_update_country_settings', |
|
| 113 | - 'capability' => 'manage_options', |
|
| 114 | - 'noheader' => true, |
|
| 115 | - ), |
|
| 116 | - |
|
| 117 | - 'display_country_settings' => array( |
|
| 118 | - 'func' => 'display_country_settings', |
|
| 119 | - 'capability' => 'manage_options', |
|
| 120 | - 'noheader' => true, |
|
| 121 | - ), |
|
| 122 | - |
|
| 123 | - 'add_new_state' => array( |
|
| 124 | - 'func' => 'add_new_state', |
|
| 125 | - 'capability' => 'manage_options', |
|
| 126 | - 'noheader' => true, |
|
| 127 | - ), |
|
| 128 | - |
|
| 129 | - 'delete_state' => array( |
|
| 130 | - 'func' => 'delete_state', |
|
| 131 | - 'capability' => 'manage_options', |
|
| 132 | - 'noheader' => true, |
|
| 133 | - ), |
|
| 134 | - 'privacy_settings' => array( |
|
| 135 | - 'func' => 'privacySettings', |
|
| 136 | - 'capability' => 'manage_options', |
|
| 137 | - ), |
|
| 138 | - 'update_privacy_settings' => array( |
|
| 139 | - 'func' => 'updatePrivacySettings', |
|
| 140 | - 'capability' => 'manage_options', |
|
| 141 | - 'noheader' => true, |
|
| 142 | - 'headers_sent_route' => 'privacy_settings', |
|
| 143 | - ), |
|
| 144 | - ); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * Set page configuration property |
|
| 150 | - */ |
|
| 151 | - protected function _set_page_config() |
|
| 152 | - { |
|
| 153 | - $this->_page_config = array( |
|
| 154 | - 'critical_pages' => array( |
|
| 155 | - 'nav' => array( |
|
| 156 | - 'label' => esc_html__('Critical Pages', 'event_espresso'), |
|
| 157 | - 'order' => 50, |
|
| 158 | - ), |
|
| 159 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 160 | - 'help_tabs' => array( |
|
| 161 | - 'general_settings_critical_pages_help_tab' => array( |
|
| 162 | - 'title' => esc_html__('Critical Pages', 'event_espresso'), |
|
| 163 | - 'filename' => 'general_settings_critical_pages', |
|
| 164 | - ), |
|
| 165 | - ), |
|
| 166 | - 'help_tour' => array('Critical_Pages_Help_Tour'), |
|
| 167 | - 'require_nonce' => false, |
|
| 168 | - ), |
|
| 169 | - 'default' => array( |
|
| 170 | - 'nav' => array( |
|
| 171 | - 'label' => esc_html__('Your Organization', 'event_espresso'), |
|
| 172 | - 'order' => 20, |
|
| 173 | - ), |
|
| 174 | - 'help_tabs' => array( |
|
| 175 | - 'general_settings_your_organization_help_tab' => array( |
|
| 176 | - 'title' => esc_html__('Your Organization', 'event_espresso'), |
|
| 177 | - 'filename' => 'general_settings_your_organization', |
|
| 178 | - ), |
|
| 179 | - ), |
|
| 180 | - 'help_tour' => array('Your_Organization_Help_Tour'), |
|
| 181 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 182 | - 'require_nonce' => false, |
|
| 183 | - ), |
|
| 184 | - 'admin_option_settings' => array( |
|
| 185 | - 'nav' => array( |
|
| 186 | - 'label' => esc_html__('Admin Options', 'event_espresso'), |
|
| 187 | - 'order' => 60, |
|
| 188 | - ), |
|
| 189 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 190 | - 'help_tabs' => array( |
|
| 191 | - 'general_settings_admin_options_help_tab' => array( |
|
| 192 | - 'title' => esc_html__('Admin Options', 'event_espresso'), |
|
| 193 | - 'filename' => 'general_settings_admin_options', |
|
| 194 | - ), |
|
| 195 | - ), |
|
| 196 | - 'help_tour' => array('Admin_Options_Help_Tour'), |
|
| 197 | - 'require_nonce' => false, |
|
| 198 | - ), |
|
| 199 | - 'country_settings' => array( |
|
| 200 | - 'nav' => array( |
|
| 201 | - 'label' => esc_html__('Countries', 'event_espresso'), |
|
| 202 | - 'order' => 70, |
|
| 203 | - ), |
|
| 204 | - 'help_tabs' => array( |
|
| 205 | - 'general_settings_countries_help_tab' => array( |
|
| 206 | - 'title' => esc_html__('Countries', 'event_espresso'), |
|
| 207 | - 'filename' => 'general_settings_countries', |
|
| 208 | - ), |
|
| 209 | - ), |
|
| 210 | - 'help_tour' => array('Countries_Help_Tour'), |
|
| 211 | - 'require_nonce' => false, |
|
| 212 | - ), |
|
| 213 | - 'privacy_settings' => array( |
|
| 214 | - 'nav' => array( |
|
| 215 | - 'label' => esc_html__('Privacy', 'event_espresso'), |
|
| 216 | - 'order' => 80, |
|
| 217 | - ), |
|
| 218 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 219 | - 'require_nonce' => false, |
|
| 220 | - ), |
|
| 221 | - ); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - |
|
| 225 | - protected function _add_screen_options() |
|
| 226 | - { |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - |
|
| 230 | - protected function _add_feature_pointers() |
|
| 231 | - { |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * Enqueue global scripts and styles for all routes in the General Settings Admin Pages. |
|
| 237 | - */ |
|
| 238 | - public function load_scripts_styles() |
|
| 239 | - { |
|
| 240 | - // styles |
|
| 241 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 242 | - // scripts |
|
| 243 | - wp_enqueue_script('ee_admin_js'); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * Execute logic running on `admin_init` |
|
| 249 | - */ |
|
| 250 | - public function admin_init() |
|
| 251 | - { |
|
| 252 | - EE_Registry::$i18n_js_strings['invalid_server_response'] = wp_strip_all_tags(__( |
|
| 253 | - 'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.', |
|
| 254 | - 'event_espresso' |
|
| 255 | - )); |
|
| 256 | - EE_Registry::$i18n_js_strings['error_occurred'] = wp_strip_all_tags(__( |
|
| 257 | - 'An error occurred! Please refresh the page and try again.', |
|
| 258 | - 'event_espresso' |
|
| 259 | - )); |
|
| 260 | - EE_Registry::$i18n_js_strings['confirm_delete_state'] = wp_strip_all_tags(__( |
|
| 261 | - 'Are you sure you want to delete this State / Province?', |
|
| 262 | - 'event_espresso' |
|
| 263 | - )); |
|
| 264 | - $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
| 265 | - EE_Registry::$i18n_js_strings['ajax_url'] = admin_url( |
|
| 266 | - 'admin-ajax.php?page=espresso_general_settings', |
|
| 267 | - $protocol |
|
| 268 | - ); |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - |
|
| 272 | - public function admin_notices() |
|
| 273 | - { |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - |
|
| 277 | - public function admin_footer_scripts() |
|
| 278 | - { |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - |
|
| 282 | - /** |
|
| 283 | - * Enqueue scripts and styles for the default route. |
|
| 284 | - */ |
|
| 285 | - public function load_scripts_styles_default() |
|
| 286 | - { |
|
| 287 | - // styles |
|
| 288 | - wp_enqueue_style('thickbox'); |
|
| 289 | - // scripts |
|
| 290 | - wp_enqueue_script('media-upload'); |
|
| 291 | - wp_enqueue_script('thickbox'); |
|
| 292 | - wp_register_script( |
|
| 293 | - 'organization_settings', |
|
| 294 | - GEN_SET_ASSETS_URL . 'your_organization_settings.js', |
|
| 295 | - array('jquery', 'media-upload', 'thickbox'), |
|
| 296 | - EVENT_ESPRESSO_VERSION, |
|
| 297 | - true |
|
| 298 | - ); |
|
| 299 | - wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 300 | - wp_enqueue_script('organization_settings'); |
|
| 301 | - wp_enqueue_style('organization-css'); |
|
| 302 | - $confirm_image_delete = array( |
|
| 303 | - 'text' => wp_strip_all_tags( |
|
| 304 | - __( |
|
| 305 | - 'Do you really want to delete this image? Please remember to save your settings to complete the removal.', |
|
| 306 | - 'event_espresso' |
|
| 307 | - ) |
|
| 308 | - ), |
|
| 309 | - ); |
|
| 310 | - wp_localize_script('organization_settings', 'confirm_image_delete', $confirm_image_delete); |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - |
|
| 314 | - /** |
|
| 315 | - * Enqueue scripts and styles for the country settings route. |
|
| 316 | - */ |
|
| 317 | - public function load_scripts_styles_country_settings() |
|
| 318 | - { |
|
| 319 | - // scripts |
|
| 320 | - wp_register_script( |
|
| 321 | - 'gen_settings_countries', |
|
| 322 | - GEN_SET_ASSETS_URL . 'gen_settings_countries.js', |
|
| 323 | - array('ee_admin_js'), |
|
| 324 | - EVENT_ESPRESSO_VERSION, |
|
| 325 | - true |
|
| 326 | - ); |
|
| 327 | - wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 328 | - wp_enqueue_script('gen_settings_countries'); |
|
| 329 | - wp_enqueue_style('organization-css'); |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - |
|
| 333 | - /************* Espresso Pages *************/ |
|
| 334 | - /** |
|
| 335 | - * _espresso_page_settings |
|
| 336 | - * |
|
| 337 | - * @throws \EE_Error |
|
| 338 | - * @throws DomainException |
|
| 339 | - * @throws DomainException |
|
| 340 | - * @throws InvalidDataTypeException |
|
| 341 | - * @throws InvalidArgumentException |
|
| 342 | - */ |
|
| 343 | - protected function _espresso_page_settings() |
|
| 344 | - { |
|
| 345 | - // Check to make sure all of the main pages are setup properly, |
|
| 346 | - // if not create the default pages and display an admin notice |
|
| 347 | - EEH_Activation::verify_default_pages_exist(); |
|
| 348 | - $this->_transient_garbage_collection(); |
|
| 349 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
| 350 | - $this->_template_args['reg_page_id'] = isset(EE_Registry::instance()->CFG->core->reg_page_id) |
|
| 351 | - ? EE_Registry::instance()->CFG->core->reg_page_id |
|
| 352 | - : null; |
|
| 353 | - $this->_template_args['reg_page_obj'] = isset(EE_Registry::instance()->CFG->core->reg_page_id) |
|
| 354 | - ? get_page(EE_Registry::instance()->CFG->core->reg_page_id) |
|
| 355 | - : false; |
|
| 356 | - $this->_template_args['txn_page_id'] = isset(EE_Registry::instance()->CFG->core->txn_page_id) |
|
| 357 | - ? EE_Registry::instance()->CFG->core->txn_page_id |
|
| 358 | - : null; |
|
| 359 | - $this->_template_args['txn_page_obj'] = isset(EE_Registry::instance()->CFG->core->txn_page_id) |
|
| 360 | - ? get_page(EE_Registry::instance()->CFG->core->txn_page_id) |
|
| 361 | - : false; |
|
| 362 | - $this->_template_args['thank_you_page_id'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id) |
|
| 363 | - ? EE_Registry::instance()->CFG->core->thank_you_page_id |
|
| 364 | - : null; |
|
| 365 | - $this->_template_args['thank_you_page_obj'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id) |
|
| 366 | - ? get_page(EE_Registry::instance()->CFG->core->thank_you_page_id) |
|
| 367 | - : false; |
|
| 368 | - $this->_template_args['cancel_page_id'] = isset(EE_Registry::instance()->CFG->core->cancel_page_id) |
|
| 369 | - ? EE_Registry::instance()->CFG->core->cancel_page_id |
|
| 370 | - : null; |
|
| 371 | - $this->_template_args['cancel_page_obj'] = isset(EE_Registry::instance()->CFG->core->cancel_page_id) |
|
| 372 | - ? get_page(EE_Registry::instance()->CFG->core->cancel_page_id) |
|
| 373 | - : false; |
|
| 374 | - $this->_set_add_edit_form_tags('update_espresso_page_settings'); |
|
| 375 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 376 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 377 | - GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php', |
|
| 378 | - $this->_template_args, |
|
| 379 | - true |
|
| 380 | - ); |
|
| 381 | - $this->display_admin_page_with_sidebar(); |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * Handler for updating espresso page settings. |
|
| 387 | - * |
|
| 388 | - * @throws EE_Error |
|
| 389 | - */ |
|
| 390 | - protected function _update_espresso_page_settings() |
|
| 391 | - { |
|
| 392 | - // capture incoming request data && set page IDs |
|
| 393 | - EE_Registry::instance()->CFG->core->reg_page_id = isset($this->_req_data['reg_page_id']) |
|
| 394 | - ? absint($this->_req_data['reg_page_id']) |
|
| 395 | - : EE_Registry::instance()->CFG->core->reg_page_id; |
|
| 396 | - EE_Registry::instance()->CFG->core->txn_page_id = isset($this->_req_data['txn_page_id']) |
|
| 397 | - ? absint($this->_req_data['txn_page_id']) |
|
| 398 | - : EE_Registry::instance()->CFG->core->txn_page_id; |
|
| 399 | - EE_Registry::instance()->CFG->core->thank_you_page_id = isset($this->_req_data['thank_you_page_id']) |
|
| 400 | - ? absint($this->_req_data['thank_you_page_id']) |
|
| 401 | - : EE_Registry::instance()->CFG->core->thank_you_page_id; |
|
| 402 | - EE_Registry::instance()->CFG->core->cancel_page_id = isset($this->_req_data['cancel_page_id']) |
|
| 403 | - ? absint($this->_req_data['cancel_page_id']) |
|
| 404 | - : EE_Registry::instance()->CFG->core->cancel_page_id; |
|
| 405 | - |
|
| 406 | - EE_Registry::instance()->CFG->core = apply_filters( |
|
| 407 | - 'FHEE__General_Settings_Admin_Page___update_espresso_page_settings__CFG_core', |
|
| 408 | - EE_Registry::instance()->CFG->core, |
|
| 409 | - $this->_req_data |
|
| 410 | - ); |
|
| 411 | - $what = esc_html__('Critical Pages & Shortcodes', 'event_espresso'); |
|
| 412 | - $this->_redirect_after_action( |
|
| 413 | - $this->_update_espresso_configuration( |
|
| 414 | - $what, |
|
| 415 | - EE_Registry::instance()->CFG->core, |
|
| 416 | - __FILE__, |
|
| 417 | - __FUNCTION__, |
|
| 418 | - __LINE__ |
|
| 419 | - ), |
|
| 420 | - $what, |
|
| 421 | - '', |
|
| 422 | - array( |
|
| 423 | - 'action' => 'critical_pages', |
|
| 424 | - ), |
|
| 425 | - true |
|
| 426 | - ); |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - |
|
| 430 | - /************* Your Organization *************/ |
|
| 431 | - |
|
| 432 | - |
|
| 433 | - /** |
|
| 434 | - * @throws DomainException |
|
| 435 | - * @throws EE_Error |
|
| 436 | - * @throws InvalidArgumentException |
|
| 437 | - * @throws InvalidDataTypeException |
|
| 438 | - * @throws InvalidInterfaceException |
|
| 439 | - */ |
|
| 440 | - protected function _your_organization_settings() |
|
| 441 | - { |
|
| 442 | - $this->_template_args['admin_page_content'] = ''; |
|
| 443 | - try { |
|
| 444 | - /** @var EventEspresso\admin_pages\general_settings\OrganizationSettings $organization_settings_form */ |
|
| 445 | - $organization_settings_form = $this->loader->getShared( |
|
| 446 | - 'EventEspresso\admin_pages\general_settings\OrganizationSettings' |
|
| 447 | - ); |
|
| 448 | - $this->_template_args['admin_page_content'] = $organization_settings_form->display(); |
|
| 449 | - } catch (Exception $e) { |
|
| 450 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 451 | - } |
|
| 452 | - $this->_set_add_edit_form_tags('update_your_organization_settings'); |
|
| 453 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 454 | - $this->display_admin_page_with_sidebar(); |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * Handler for updating organization settings. |
|
| 460 | - * |
|
| 461 | - * @throws EE_Error |
|
| 462 | - */ |
|
| 463 | - protected function _update_your_organization_settings() |
|
| 464 | - { |
|
| 465 | - try { |
|
| 466 | - /** @var EventEspresso\admin_pages\general_settings\OrganizationSettings $organization_settings_form */ |
|
| 467 | - $organization_settings_form = $this->loader->getShared( |
|
| 468 | - 'EventEspresso\admin_pages\general_settings\OrganizationSettings' |
|
| 469 | - ); |
|
| 470 | - $success = $organization_settings_form->process($this->_req_data); |
|
| 471 | - EE_Registry::instance()->CFG = apply_filters( |
|
| 472 | - 'FHEE__General_Settings_Admin_Page___update_your_organization_settings__CFG', |
|
| 473 | - EE_Registry::instance()->CFG |
|
| 474 | - ); |
|
| 475 | - } catch (Exception $e) { |
|
| 476 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 477 | - $success = false; |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - if ($success) { |
|
| 481 | - $success = $this->_update_espresso_configuration( |
|
| 482 | - esc_html__('Your Organization Settings', 'event_espresso'), |
|
| 483 | - EE_Registry::instance()->CFG, |
|
| 484 | - __FILE__, |
|
| 485 | - __FUNCTION__, |
|
| 486 | - __LINE__ |
|
| 487 | - ); |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - $this->_redirect_after_action($success, '', '', array('action' => 'default'), true); |
|
| 491 | - } |
|
| 492 | - |
|
| 493 | - |
|
| 494 | - |
|
| 495 | - /************* Admin Options *************/ |
|
| 496 | - |
|
| 497 | - |
|
| 498 | - /** |
|
| 499 | - * _admin_option_settings |
|
| 500 | - * |
|
| 501 | - * @throws \EE_Error |
|
| 502 | - * @throws \LogicException |
|
| 503 | - */ |
|
| 504 | - protected function _admin_option_settings() |
|
| 505 | - { |
|
| 506 | - $this->_template_args['admin_page_content'] = ''; |
|
| 507 | - try { |
|
| 508 | - $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance()); |
|
| 509 | - // still need this for the old school form in Extend_General_Settings_Admin_Page |
|
| 510 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
| 511 | - // also need to account for the do_action that was in the old template |
|
| 512 | - $admin_options_settings_form->setTemplateArgs($this->_template_args); |
|
| 513 | - $this->_template_args['admin_page_content'] = $admin_options_settings_form->display(); |
|
| 514 | - } catch (Exception $e) { |
|
| 515 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 516 | - } |
|
| 517 | - $this->_set_add_edit_form_tags('update_admin_option_settings'); |
|
| 518 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 519 | - $this->display_admin_page_with_sidebar(); |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - |
|
| 523 | - /** |
|
| 524 | - * _update_admin_option_settings |
|
| 525 | - * |
|
| 526 | - * @throws \EE_Error |
|
| 527 | - * @throws InvalidDataTypeException |
|
| 528 | - * @throws \EventEspresso\core\exceptions\InvalidFormSubmissionException |
|
| 529 | - * @throws \InvalidArgumentException |
|
| 530 | - * @throws \LogicException |
|
| 531 | - */ |
|
| 532 | - protected function _update_admin_option_settings() |
|
| 533 | - { |
|
| 534 | - try { |
|
| 535 | - $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance()); |
|
| 536 | - $admin_options_settings_form->process($this->_req_data[ $admin_options_settings_form->slug() ]); |
|
| 537 | - EE_Registry::instance()->CFG->admin = apply_filters( |
|
| 538 | - 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__CFG_admin', |
|
| 539 | - EE_Registry::instance()->CFG->admin |
|
| 540 | - ); |
|
| 541 | - } catch (Exception $e) { |
|
| 542 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 543 | - } |
|
| 544 | - $this->_redirect_after_action( |
|
| 545 | - apply_filters( |
|
| 546 | - 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__success', |
|
| 547 | - $this->_update_espresso_configuration( |
|
| 548 | - 'Admin Options', |
|
| 549 | - EE_Registry::instance()->CFG->admin, |
|
| 550 | - __FILE__, |
|
| 551 | - __FUNCTION__, |
|
| 552 | - __LINE__ |
|
| 553 | - ) |
|
| 554 | - ), |
|
| 555 | - 'Admin Options', |
|
| 556 | - 'updated', |
|
| 557 | - array('action' => 'admin_option_settings') |
|
| 558 | - ); |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - |
|
| 562 | - /************* Countries *************/ |
|
| 563 | - |
|
| 564 | - |
|
| 565 | - /** |
|
| 566 | - * @return string |
|
| 567 | - */ |
|
| 568 | - protected function getCountryIsoForSite() |
|
| 569 | - { |
|
| 570 | - return ! empty(EE_Registry::instance()->CFG->organization->CNT_ISO) |
|
| 571 | - ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 572 | - : 'US'; |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - |
|
| 576 | - /** |
|
| 577 | - * @param string $CNT_ISO |
|
| 578 | - * @param EE_Country|null $country |
|
| 579 | - * @return EE_Base_Class|EE_Country |
|
| 580 | - * @throws EE_Error |
|
| 581 | - * @throws InvalidArgumentException |
|
| 582 | - * @throws InvalidDataTypeException |
|
| 583 | - * @throws InvalidInterfaceException |
|
| 584 | - * @throws ReflectionException |
|
| 585 | - */ |
|
| 586 | - protected function verifyOrGetCountryFromIso($CNT_ISO, EE_Country $country = null) |
|
| 587 | - { |
|
| 588 | - /** @var EE_Country $country */ |
|
| 589 | - return $country instanceof EE_Country && $country->ID() === $CNT_ISO |
|
| 590 | - ? $country |
|
| 591 | - : EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - |
|
| 595 | - /** |
|
| 596 | - * Output Country Settings view. |
|
| 597 | - * |
|
| 598 | - * @throws DomainException |
|
| 599 | - * @throws EE_Error |
|
| 600 | - * @throws InvalidArgumentException |
|
| 601 | - * @throws InvalidDataTypeException |
|
| 602 | - * @throws InvalidInterfaceException |
|
| 603 | - * @throws ReflectionException |
|
| 604 | - */ |
|
| 605 | - protected function _country_settings() |
|
| 606 | - { |
|
| 607 | - $CNT_ISO_for_site = $this->getCountryIsoForSite(); |
|
| 608 | - $CNT_ISO = isset($this->_req_data['country']) |
|
| 609 | - ? strtoupper(sanitize_text_field($this->_req_data['country'])) |
|
| 610 | - : $CNT_ISO_for_site; |
|
| 611 | - |
|
| 612 | - // load field generator helper |
|
| 613 | - |
|
| 614 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
| 615 | - |
|
| 616 | - $this->_template_args['countries'] = new EE_Question_Form_Input( |
|
| 617 | - EE_Question::new_instance( |
|
| 618 | - array( |
|
| 619 | - 'QST_ID' => 0, |
|
| 620 | - 'QST_display_text' => esc_html__('Select Country', 'event_espresso'), |
|
| 621 | - 'QST_system' => 'admin-country', |
|
| 622 | - ) |
|
| 623 | - ), |
|
| 624 | - EE_Answer::new_instance( |
|
| 625 | - array( |
|
| 626 | - 'ANS_ID' => 0, |
|
| 627 | - 'ANS_value' => $CNT_ISO, |
|
| 628 | - ) |
|
| 629 | - ), |
|
| 630 | - array( |
|
| 631 | - 'input_id' => 'country', |
|
| 632 | - 'input_name' => 'country', |
|
| 633 | - 'input_prefix' => '', |
|
| 634 | - 'append_qstn_id' => false, |
|
| 635 | - ) |
|
| 636 | - ); |
|
| 637 | - $country = $this->verifyOrGetCountryFromIso($CNT_ISO_for_site); |
|
| 638 | - add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2); |
|
| 639 | - add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2); |
|
| 640 | - $this->_template_args['country_details_settings'] = $this->display_country_settings( |
|
| 641 | - $country->ID(), |
|
| 642 | - $country |
|
| 643 | - ); |
|
| 644 | - $this->_template_args['country_states_settings'] = $this->display_country_states( |
|
| 645 | - $country->ID(), |
|
| 646 | - $country |
|
| 647 | - ); |
|
| 648 | - $this->_template_args['CNT_name_for_site'] = $country->name(); |
|
| 649 | - |
|
| 650 | - $this->_set_add_edit_form_tags('update_country_settings'); |
|
| 651 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 652 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 653 | - GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php', |
|
| 654 | - $this->_template_args, |
|
| 655 | - true |
|
| 656 | - ); |
|
| 657 | - $this->display_admin_page_with_no_sidebar(); |
|
| 658 | - } |
|
| 659 | - |
|
| 660 | - |
|
| 661 | - /** |
|
| 662 | - * display_country_settings |
|
| 663 | - * |
|
| 664 | - * @param string $CNT_ISO |
|
| 665 | - * @param EE_Country|null $country |
|
| 666 | - * @return mixed string | array$country |
|
| 667 | - * @throws DomainException |
|
| 668 | - * @throws EE_Error |
|
| 669 | - * @throws InvalidArgumentException |
|
| 670 | - * @throws InvalidDataTypeException |
|
| 671 | - * @throws InvalidInterfaceException |
|
| 672 | - * @throws ReflectionException |
|
| 673 | - */ |
|
| 674 | - public function display_country_settings($CNT_ISO = '', EE_Country $country = null) |
|
| 675 | - { |
|
| 676 | - $CNT_ISO_for_site = $this->getCountryIsoForSite(); |
|
| 677 | - |
|
| 678 | - $CNT_ISO = isset($this->_req_data['country']) |
|
| 679 | - ? strtoupper(sanitize_text_field($this->_req_data['country'])) |
|
| 680 | - : $CNT_ISO; |
|
| 681 | - if (! $CNT_ISO) { |
|
| 682 | - return ''; |
|
| 683 | - } |
|
| 684 | - |
|
| 685 | - // for ajax |
|
| 686 | - remove_all_filters('FHEE__EEH_Form_Fields__label_html'); |
|
| 687 | - remove_all_filters('FHEE__EEH_Form_Fields__input_html'); |
|
| 688 | - add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2); |
|
| 689 | - add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2); |
|
| 690 | - $country = $this->verifyOrGetCountryFromIso($CNT_ISO, $country); |
|
| 691 | - $CNT_cur_disabled = $CNT_ISO !== $CNT_ISO_for_site; |
|
| 692 | - $this->_template_args['CNT_cur_disabled'] = $CNT_cur_disabled; |
|
| 693 | - |
|
| 694 | - $country_input_types = array( |
|
| 695 | - 'CNT_active' => array( |
|
| 696 | - 'type' => 'RADIO_BTN', |
|
| 697 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 698 | - 'class' => '', |
|
| 699 | - 'options' => $this->_yes_no_values, |
|
| 700 | - 'use_desc_4_label' => true, |
|
| 701 | - ), |
|
| 702 | - 'CNT_ISO' => array( |
|
| 703 | - 'type' => 'TEXT', |
|
| 704 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 705 | - 'class' => 'small-text', |
|
| 706 | - ), |
|
| 707 | - 'CNT_ISO3' => array( |
|
| 708 | - 'type' => 'TEXT', |
|
| 709 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 710 | - 'class' => 'small-text', |
|
| 711 | - ), |
|
| 712 | - 'RGN_ID' => array( |
|
| 713 | - 'type' => 'TEXT', |
|
| 714 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 715 | - 'class' => 'small-text', |
|
| 716 | - ), |
|
| 717 | - 'CNT_name' => array( |
|
| 718 | - 'type' => 'TEXT', |
|
| 719 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 720 | - 'class' => 'regular-text', |
|
| 721 | - ), |
|
| 722 | - 'CNT_cur_code' => array( |
|
| 723 | - 'type' => 'TEXT', |
|
| 724 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 725 | - 'class' => 'small-text', |
|
| 726 | - 'disabled' => $CNT_cur_disabled, |
|
| 727 | - ), |
|
| 728 | - 'CNT_cur_single' => array( |
|
| 729 | - 'type' => 'TEXT', |
|
| 730 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 731 | - 'class' => 'medium-text', |
|
| 732 | - 'disabled' => $CNT_cur_disabled, |
|
| 733 | - ), |
|
| 734 | - 'CNT_cur_plural' => array( |
|
| 735 | - 'type' => 'TEXT', |
|
| 736 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 737 | - 'class' => 'medium-text', |
|
| 738 | - 'disabled' => $CNT_cur_disabled, |
|
| 739 | - ), |
|
| 740 | - 'CNT_cur_sign' => array( |
|
| 741 | - 'type' => 'TEXT', |
|
| 742 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 743 | - 'class' => 'small-text', |
|
| 744 | - 'htmlentities' => false, |
|
| 745 | - 'disabled' => $CNT_cur_disabled, |
|
| 746 | - ), |
|
| 747 | - 'CNT_cur_sign_b4' => array( |
|
| 748 | - 'type' => 'RADIO_BTN', |
|
| 749 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 750 | - 'class' => '', |
|
| 751 | - 'options' => $this->_yes_no_values, |
|
| 752 | - 'use_desc_4_label' => true, |
|
| 753 | - 'disabled' => $CNT_cur_disabled, |
|
| 754 | - ), |
|
| 755 | - 'CNT_cur_dec_plc' => array( |
|
| 756 | - 'type' => 'RADIO_BTN', |
|
| 757 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 758 | - 'class' => '', |
|
| 759 | - 'options' => array( |
|
| 760 | - array('id' => 0, 'text' => ''), |
|
| 761 | - array('id' => 1, 'text' => ''), |
|
| 762 | - array('id' => 2, 'text' => ''), |
|
| 763 | - array('id' => 3, 'text' => ''), |
|
| 764 | - ), |
|
| 765 | - 'disabled' => $CNT_cur_disabled, |
|
| 766 | - ), |
|
| 767 | - 'CNT_cur_dec_mrk' => array( |
|
| 768 | - 'type' => 'RADIO_BTN', |
|
| 769 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 770 | - 'class' => '', |
|
| 771 | - 'options' => array( |
|
| 772 | - array( |
|
| 773 | - 'id' => ',', |
|
| 774 | - 'text' => esc_html__(', (comma)', 'event_espresso'), |
|
| 775 | - ), |
|
| 776 | - array('id' => '.', 'text' => esc_html__('. (decimal)', 'event_espresso')), |
|
| 777 | - ), |
|
| 778 | - 'use_desc_4_label' => true, |
|
| 779 | - 'disabled' => $CNT_cur_disabled, |
|
| 780 | - ), |
|
| 781 | - 'CNT_cur_thsnds' => array( |
|
| 782 | - 'type' => 'RADIO_BTN', |
|
| 783 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 784 | - 'class' => '', |
|
| 785 | - 'options' => array( |
|
| 786 | - array( |
|
| 787 | - 'id' => ',', |
|
| 788 | - 'text' => esc_html__(', (comma)', 'event_espresso'), |
|
| 789 | - ), |
|
| 790 | - array( |
|
| 791 | - 'id' => '.', |
|
| 792 | - 'text' => esc_html__('. (decimal)', 'event_espresso') |
|
| 793 | - ), |
|
| 794 | - array( |
|
| 795 | - 'id' => ' ', |
|
| 796 | - 'text' => esc_html__('(space)', 'event_espresso') |
|
| 797 | - ) |
|
| 798 | - ), |
|
| 799 | - 'use_desc_4_label' => true, |
|
| 800 | - 'disabled' => $CNT_cur_disabled, |
|
| 801 | - ), |
|
| 802 | - 'CNT_tel_code' => array( |
|
| 803 | - 'type' => 'TEXT', |
|
| 804 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 805 | - 'class' => 'small-text', |
|
| 806 | - ), |
|
| 807 | - 'CNT_is_EU' => array( |
|
| 808 | - 'type' => 'RADIO_BTN', |
|
| 809 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 810 | - 'class' => '', |
|
| 811 | - 'options' => $this->_yes_no_values, |
|
| 812 | - 'use_desc_4_label' => true, |
|
| 813 | - ), |
|
| 814 | - ); |
|
| 815 | - $this->_template_args['inputs'] = EE_Question_Form_Input::generate_question_form_inputs_for_object( |
|
| 816 | - $country, |
|
| 817 | - $country_input_types |
|
| 818 | - ); |
|
| 819 | - $country_details_settings = EEH_Template::display_template( |
|
| 820 | - GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php', |
|
| 821 | - $this->_template_args, |
|
| 822 | - true |
|
| 823 | - ); |
|
| 824 | - |
|
| 825 | - if (defined('DOING_AJAX')) { |
|
| 826 | - $notices = EE_Error::get_notices(false, false, false); |
|
| 827 | - echo wp_json_encode( |
|
| 828 | - array( |
|
| 829 | - 'return_data' => $country_details_settings, |
|
| 830 | - 'success' => $notices['success'], |
|
| 831 | - 'errors' => $notices['errors'], |
|
| 832 | - ) |
|
| 833 | - ); |
|
| 834 | - die(); |
|
| 835 | - } else { |
|
| 836 | - return $country_details_settings; |
|
| 837 | - } |
|
| 838 | - } |
|
| 839 | - |
|
| 840 | - |
|
| 841 | - /** |
|
| 842 | - * @param string $CNT_ISO |
|
| 843 | - * @param EE_Country|null $country |
|
| 844 | - * @return string |
|
| 845 | - * @throws DomainException |
|
| 846 | - * @throws EE_Error |
|
| 847 | - * @throws InvalidArgumentException |
|
| 848 | - * @throws InvalidDataTypeException |
|
| 849 | - * @throws InvalidInterfaceException |
|
| 850 | - * @throws ReflectionException |
|
| 851 | - */ |
|
| 852 | - public function display_country_states($CNT_ISO = '', EE_Country $country = null) |
|
| 853 | - { |
|
| 854 | - |
|
| 855 | - $CNT_ISO = isset($this->_req_data['country']) |
|
| 856 | - ? sanitize_text_field($this->_req_data['country']) |
|
| 857 | - : $CNT_ISO; |
|
| 858 | - if (! $CNT_ISO) { |
|
| 859 | - return ''; |
|
| 860 | - } |
|
| 861 | - // for ajax |
|
| 862 | - remove_all_filters('FHEE__EEH_Form_Fields__label_html'); |
|
| 863 | - remove_all_filters('FHEE__EEH_Form_Fields__input_html'); |
|
| 864 | - add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'state_form_field_label_wrap'), 10, 2); |
|
| 865 | - add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'state_form_field_input__wrap'), 10, 2); |
|
| 866 | - $states = EEM_State::instance()->get_all_states_for_these_countries(array($CNT_ISO => $CNT_ISO)); |
|
| 867 | - if (empty($states)) { |
|
| 868 | - /** @var EventEspresso\core\services\address\CountrySubRegionDao $countrySubRegionDao */ |
|
| 869 | - $countrySubRegionDao = $this->loader->getShared( |
|
| 870 | - 'EventEspresso\core\services\address\CountrySubRegionDao' |
|
| 871 | - ); |
|
| 872 | - if ($countrySubRegionDao instanceof EventEspresso\core\services\address\CountrySubRegionDao) { |
|
| 873 | - $country = $this->verifyOrGetCountryFromIso($CNT_ISO, $country); |
|
| 874 | - if ($countrySubRegionDao->saveCountrySubRegions($country)) { |
|
| 875 | - $states = EEM_State::instance()->get_all_states_for_these_countries( |
|
| 876 | - array($CNT_ISO => $CNT_ISO) |
|
| 877 | - ); |
|
| 878 | - } |
|
| 879 | - } |
|
| 880 | - } |
|
| 881 | - if (is_array($states)) { |
|
| 882 | - foreach ($states as $STA_ID => $state) { |
|
| 883 | - if ($state instanceof EE_State) { |
|
| 884 | - // STA_abbrev STA_name STA_active |
|
| 885 | - $state_input_types = array( |
|
| 886 | - 'STA_abbrev' => array( |
|
| 887 | - 'type' => 'TEXT', |
|
| 888 | - 'input_name' => 'states[' . $STA_ID . ']', |
|
| 889 | - 'class' => 'mid-text', |
|
| 890 | - ), |
|
| 891 | - 'STA_name' => array( |
|
| 892 | - 'type' => 'TEXT', |
|
| 893 | - 'input_name' => 'states[' . $STA_ID . ']', |
|
| 894 | - 'class' => 'regular-text', |
|
| 895 | - ), |
|
| 896 | - 'STA_active' => array( |
|
| 897 | - 'type' => 'RADIO_BTN', |
|
| 898 | - 'input_name' => 'states[' . $STA_ID . ']', |
|
| 899 | - 'options' => $this->_yes_no_values, |
|
| 900 | - 'use_desc_4_label' => true, |
|
| 901 | - ), |
|
| 902 | - ); |
|
| 903 | - $this->_template_args['states'][ $STA_ID ]['inputs'] = |
|
| 904 | - EE_Question_Form_Input::generate_question_form_inputs_for_object( |
|
| 905 | - $state, |
|
| 906 | - $state_input_types |
|
| 907 | - ); |
|
| 908 | - $query_args = array( |
|
| 909 | - 'action' => 'delete_state', |
|
| 910 | - 'STA_ID' => $STA_ID, |
|
| 911 | - 'CNT_ISO' => $CNT_ISO, |
|
| 912 | - 'STA_abbrev' => $state->abbrev(), |
|
| 913 | - ); |
|
| 914 | - $this->_template_args['states'][ $STA_ID ]['delete_state_url'] = |
|
| 915 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 916 | - $query_args, |
|
| 917 | - GEN_SET_ADMIN_URL |
|
| 918 | - ); |
|
| 919 | - } |
|
| 920 | - } |
|
| 921 | - } else { |
|
| 922 | - $this->_template_args['states'] = false; |
|
| 923 | - } |
|
| 924 | - |
|
| 925 | - $this->_template_args['add_new_state_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 926 | - array('action' => 'add_new_state'), |
|
| 927 | - GEN_SET_ADMIN_URL |
|
| 928 | - ); |
|
| 929 | - |
|
| 930 | - $state_details_settings = EEH_Template::display_template( |
|
| 931 | - GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php', |
|
| 932 | - $this->_template_args, |
|
| 933 | - true |
|
| 934 | - ); |
|
| 935 | - |
|
| 936 | - if (defined('DOING_AJAX')) { |
|
| 937 | - $notices = EE_Error::get_notices(false, false, false); |
|
| 938 | - echo wp_json_encode( |
|
| 939 | - array( |
|
| 940 | - 'return_data' => $state_details_settings, |
|
| 941 | - 'success' => $notices['success'], |
|
| 942 | - 'errors' => $notices['errors'], |
|
| 943 | - ) |
|
| 944 | - ); |
|
| 945 | - die(); |
|
| 946 | - } else { |
|
| 947 | - return $state_details_settings; |
|
| 948 | - } |
|
| 949 | - } |
|
| 950 | - |
|
| 951 | - |
|
| 952 | - /** |
|
| 953 | - * add_new_state |
|
| 954 | - * |
|
| 955 | - * @access public |
|
| 956 | - * @return void |
|
| 957 | - * @throws EE_Error |
|
| 958 | - * @throws InvalidArgumentException |
|
| 959 | - * @throws InvalidDataTypeException |
|
| 960 | - * @throws InvalidInterfaceException |
|
| 961 | - */ |
|
| 962 | - public function add_new_state() |
|
| 963 | - { |
|
| 964 | - |
|
| 965 | - $success = true; |
|
| 966 | - |
|
| 967 | - $CNT_ISO = isset($this->_req_data['CNT_ISO']) |
|
| 968 | - ? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO'])) |
|
| 969 | - : false; |
|
| 970 | - if (! $CNT_ISO) { |
|
| 971 | - EE_Error::add_error( |
|
| 972 | - esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
|
| 973 | - __FILE__, |
|
| 974 | - __FUNCTION__, |
|
| 975 | - __LINE__ |
|
| 976 | - ); |
|
| 977 | - $success = false; |
|
| 978 | - } |
|
| 979 | - $STA_abbrev = isset($this->_req_data['STA_abbrev']) |
|
| 980 | - ? sanitize_text_field($this->_req_data['STA_abbrev']) |
|
| 981 | - : false; |
|
| 982 | - if (! $STA_abbrev) { |
|
| 983 | - EE_Error::add_error( |
|
| 984 | - esc_html__('No State ISO code or an invalid State ISO code was received.', 'event_espresso'), |
|
| 985 | - __FILE__, |
|
| 986 | - __FUNCTION__, |
|
| 987 | - __LINE__ |
|
| 988 | - ); |
|
| 989 | - $success = false; |
|
| 990 | - } |
|
| 991 | - $STA_name = isset($this->_req_data['STA_name']) |
|
| 992 | - ? sanitize_text_field($this->_req_data['STA_name']) |
|
| 993 | - : false; |
|
| 994 | - if (! $STA_name) { |
|
| 995 | - EE_Error::add_error( |
|
| 996 | - esc_html__('No State name or an invalid State name was received.', 'event_espresso'), |
|
| 997 | - __FILE__, |
|
| 998 | - __FUNCTION__, |
|
| 999 | - __LINE__ |
|
| 1000 | - ); |
|
| 1001 | - $success = false; |
|
| 1002 | - } |
|
| 1003 | - |
|
| 1004 | - if ($success) { |
|
| 1005 | - $cols_n_values = array( |
|
| 1006 | - 'CNT_ISO' => $CNT_ISO, |
|
| 1007 | - 'STA_abbrev' => $STA_abbrev, |
|
| 1008 | - 'STA_name' => $STA_name, |
|
| 1009 | - 'STA_active' => true, |
|
| 1010 | - ); |
|
| 1011 | - $success = EEM_State::instance()->insert($cols_n_values); |
|
| 1012 | - EE_Error::add_success(esc_html__('The State was added successfully.', 'event_espresso')); |
|
| 1013 | - } |
|
| 1014 | - |
|
| 1015 | - if (defined('DOING_AJAX')) { |
|
| 1016 | - $notices = EE_Error::get_notices(false, false, false); |
|
| 1017 | - echo wp_json_encode(array_merge($notices, array('return_data' => $CNT_ISO))); |
|
| 1018 | - die(); |
|
| 1019 | - } else { |
|
| 1020 | - $this->_redirect_after_action($success, 'State', 'added', array('action' => 'country_settings')); |
|
| 1021 | - } |
|
| 1022 | - } |
|
| 1023 | - |
|
| 1024 | - |
|
| 1025 | - /** |
|
| 1026 | - * delete_state |
|
| 1027 | - * |
|
| 1028 | - * @access public |
|
| 1029 | - * @return boolean |
|
| 1030 | - * @throws EE_Error |
|
| 1031 | - * @throws InvalidArgumentException |
|
| 1032 | - * @throws InvalidDataTypeException |
|
| 1033 | - * @throws InvalidInterfaceException |
|
| 1034 | - */ |
|
| 1035 | - public function delete_state() |
|
| 1036 | - { |
|
| 1037 | - $CNT_ISO = isset($this->_req_data['CNT_ISO']) |
|
| 1038 | - ? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO'])) |
|
| 1039 | - : false; |
|
| 1040 | - $STA_ID = isset($this->_req_data['STA_ID']) |
|
| 1041 | - ? sanitize_text_field($this->_req_data['STA_ID']) |
|
| 1042 | - : false; |
|
| 1043 | - $STA_abbrev = isset($this->_req_data['STA_abbrev']) |
|
| 1044 | - ? sanitize_text_field($this->_req_data['STA_abbrev']) |
|
| 1045 | - : false; |
|
| 1046 | - if (! $STA_ID) { |
|
| 1047 | - EE_Error::add_error( |
|
| 1048 | - esc_html__('No State ID or an invalid State ID was received.', 'event_espresso'), |
|
| 1049 | - __FILE__, |
|
| 1050 | - __FUNCTION__, |
|
| 1051 | - __LINE__ |
|
| 1052 | - ); |
|
| 1053 | - return false; |
|
| 1054 | - } |
|
| 1055 | - |
|
| 1056 | - $success = EEM_State::instance()->delete_by_ID($STA_ID); |
|
| 1057 | - if ($success !== false) { |
|
| 1058 | - do_action( |
|
| 1059 | - 'AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
| 1060 | - $CNT_ISO, |
|
| 1061 | - $STA_ID, |
|
| 1062 | - array('STA_abbrev' => $STA_abbrev) |
|
| 1063 | - ); |
|
| 1064 | - EE_Error::add_success(esc_html__('The State was deleted successfully.', 'event_espresso')); |
|
| 1065 | - } |
|
| 1066 | - if (defined('DOING_AJAX')) { |
|
| 1067 | - $notices = EE_Error::get_notices(false, false); |
|
| 1068 | - $notices['return_data'] = true; |
|
| 1069 | - echo wp_json_encode($notices); |
|
| 1070 | - die(); |
|
| 1071 | - } else { |
|
| 1072 | - $this->_redirect_after_action( |
|
| 1073 | - $success, |
|
| 1074 | - 'State', |
|
| 1075 | - 'deleted', |
|
| 1076 | - array('action' => 'country_settings') |
|
| 1077 | - ); |
|
| 1078 | - } |
|
| 1079 | - } |
|
| 1080 | - |
|
| 1081 | - |
|
| 1082 | - /** |
|
| 1083 | - * _update_country_settings |
|
| 1084 | - * |
|
| 1085 | - * @access protected |
|
| 1086 | - * @return void |
|
| 1087 | - * @throws EE_Error |
|
| 1088 | - * @throws InvalidArgumentException |
|
| 1089 | - * @throws InvalidDataTypeException |
|
| 1090 | - * @throws InvalidInterfaceException |
|
| 1091 | - */ |
|
| 1092 | - protected function _update_country_settings() |
|
| 1093 | - { |
|
| 1094 | - // grab the country ISO code |
|
| 1095 | - $CNT_ISO = isset($this->_req_data['country']) |
|
| 1096 | - ? strtoupper(sanitize_text_field($this->_req_data['country'])) |
|
| 1097 | - : false; |
|
| 1098 | - if (! $CNT_ISO) { |
|
| 1099 | - EE_Error::add_error( |
|
| 1100 | - esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
|
| 1101 | - __FILE__, |
|
| 1102 | - __FUNCTION__, |
|
| 1103 | - __LINE__ |
|
| 1104 | - ); |
|
| 1105 | - |
|
| 1106 | - return; |
|
| 1107 | - } |
|
| 1108 | - $cols_n_values = array(); |
|
| 1109 | - $cols_n_values['CNT_ISO3'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3']) |
|
| 1110 | - ? strtoupper(sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3'])) |
|
| 1111 | - : false; |
|
| 1112 | - $cols_n_values['RGN_ID'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID']) |
|
| 1113 | - ? absint($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID']) |
|
| 1114 | - : null; |
|
| 1115 | - $cols_n_values['CNT_name'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name']) |
|
| 1116 | - ? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name']) |
|
| 1117 | - : null; |
|
| 1118 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code'])) { |
|
| 1119 | - $cols_n_values['CNT_cur_code'] = strtoupper( |
|
| 1120 | - sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code']) |
|
| 1121 | - ); |
|
| 1122 | - } |
|
| 1123 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single'])) { |
|
| 1124 | - $cols_n_values['CNT_cur_single'] = sanitize_text_field( |
|
| 1125 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single'] |
|
| 1126 | - ); |
|
| 1127 | - } |
|
| 1128 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural'])) { |
|
| 1129 | - $cols_n_values['CNT_cur_plural'] = sanitize_text_field( |
|
| 1130 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural'] |
|
| 1131 | - ); |
|
| 1132 | - } |
|
| 1133 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign'])) { |
|
| 1134 | - $cols_n_values['CNT_cur_sign'] = sanitize_text_field( |
|
| 1135 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign'] |
|
| 1136 | - ); |
|
| 1137 | - } |
|
| 1138 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4'])) { |
|
| 1139 | - $cols_n_values['CNT_cur_sign_b4'] = absint( |
|
| 1140 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4'] |
|
| 1141 | - ); |
|
| 1142 | - } |
|
| 1143 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc'])) { |
|
| 1144 | - $cols_n_values['CNT_cur_dec_plc'] = absint( |
|
| 1145 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc'] |
|
| 1146 | - ); |
|
| 1147 | - } |
|
| 1148 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk'])) { |
|
| 1149 | - $cols_n_values['CNT_cur_dec_mrk'] = sanitize_text_field( |
|
| 1150 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk'] |
|
| 1151 | - ); |
|
| 1152 | - } |
|
| 1153 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds'])) { |
|
| 1154 | - $cols_n_values['CNT_cur_thsnds'] = sanitize_text_field( |
|
| 1155 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds'] |
|
| 1156 | - ); |
|
| 1157 | - } |
|
| 1158 | - $cols_n_values['CNT_tel_code'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code']) |
|
| 1159 | - ? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code']) |
|
| 1160 | - : null; |
|
| 1161 | - $cols_n_values['CNT_is_EU'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU']) |
|
| 1162 | - ? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU']) |
|
| 1163 | - : false; |
|
| 1164 | - $cols_n_values['CNT_active'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active']) |
|
| 1165 | - ? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active']) |
|
| 1166 | - : false; |
|
| 1167 | - // allow filtering of country data |
|
| 1168 | - $cols_n_values = apply_filters( |
|
| 1169 | - 'FHEE__General_Settings_Admin_Page___update_country_settings__cols_n_values', |
|
| 1170 | - $cols_n_values |
|
| 1171 | - ); |
|
| 1172 | - |
|
| 1173 | - // where values |
|
| 1174 | - $where_cols_n_values = array(array('CNT_ISO' => $CNT_ISO)); |
|
| 1175 | - // run the update |
|
| 1176 | - $success = EEM_Country::instance()->update($cols_n_values, $where_cols_n_values); |
|
| 1177 | - |
|
| 1178 | - if (isset($this->_req_data['states']) && is_array($this->_req_data['states']) && $success !== false) { |
|
| 1179 | - // allow filtering of states data |
|
| 1180 | - $states = apply_filters( |
|
| 1181 | - 'FHEE__General_Settings_Admin_Page___update_country_settings__states', |
|
| 1182 | - $this->_req_data['states'] |
|
| 1183 | - ); |
|
| 1184 | - |
|
| 1185 | - // loop thru state data ( looks like : states[75][STA_name] ) |
|
| 1186 | - foreach ($states as $STA_ID => $state) { |
|
| 1187 | - $cols_n_values = array( |
|
| 1188 | - 'CNT_ISO' => $CNT_ISO, |
|
| 1189 | - 'STA_abbrev' => sanitize_text_field($state['STA_abbrev']), |
|
| 1190 | - 'STA_name' => sanitize_text_field($state['STA_name']), |
|
| 1191 | - 'STA_active' => (bool) absint($state['STA_active']), |
|
| 1192 | - ); |
|
| 1193 | - // where values |
|
| 1194 | - $where_cols_n_values = array(array('STA_ID' => $STA_ID)); |
|
| 1195 | - // run the update |
|
| 1196 | - $success = EEM_State::instance()->update($cols_n_values, $where_cols_n_values); |
|
| 1197 | - if ($success !== false) { |
|
| 1198 | - do_action( |
|
| 1199 | - 'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
| 1200 | - $CNT_ISO, |
|
| 1201 | - $STA_ID, |
|
| 1202 | - $cols_n_values |
|
| 1203 | - ); |
|
| 1204 | - } |
|
| 1205 | - } |
|
| 1206 | - } |
|
| 1207 | - // check if country being edited matches org option country, and if so, then update EE_Config with new settings |
|
| 1208 | - if (isset(EE_Registry::instance()->CFG->organization->CNT_ISO) |
|
| 1209 | - && $CNT_ISO == EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 1210 | - ) { |
|
| 1211 | - EE_Registry::instance()->CFG->currency = new EE_Currency_Config($CNT_ISO); |
|
| 1212 | - EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 1213 | - } |
|
| 1214 | - |
|
| 1215 | - if ($success !== false) { |
|
| 1216 | - EE_Error::add_success( |
|
| 1217 | - esc_html__('Country Settings updated successfully.', 'event_espresso') |
|
| 1218 | - ); |
|
| 1219 | - } |
|
| 1220 | - $this->_redirect_after_action( |
|
| 1221 | - $success, |
|
| 1222 | - '', |
|
| 1223 | - '', |
|
| 1224 | - array('action' => 'country_settings', 'country' => $CNT_ISO), |
|
| 1225 | - true |
|
| 1226 | - ); |
|
| 1227 | - } |
|
| 1228 | - |
|
| 1229 | - |
|
| 1230 | - /** |
|
| 1231 | - * form_form_field_label_wrap |
|
| 1232 | - * |
|
| 1233 | - * @access public |
|
| 1234 | - * @param string $label |
|
| 1235 | - * @return string |
|
| 1236 | - */ |
|
| 1237 | - public function country_form_field_label_wrap($label, $required_text) |
|
| 1238 | - { |
|
| 1239 | - return ' |
|
| 23 | + /** |
|
| 24 | + * _question_group |
|
| 25 | + * holds the specific question group object for the question group details screen |
|
| 26 | + * |
|
| 27 | + * @var object |
|
| 28 | + */ |
|
| 29 | + protected $_question_group; |
|
| 30 | + |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Initialize basic properties. |
|
| 34 | + */ |
|
| 35 | + protected function _init_page_props() |
|
| 36 | + { |
|
| 37 | + $this->page_slug = GEN_SET_PG_SLUG; |
|
| 38 | + $this->page_label = GEN_SET_LABEL; |
|
| 39 | + $this->_admin_base_url = GEN_SET_ADMIN_URL; |
|
| 40 | + $this->_admin_base_path = GEN_SET_ADMIN; |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Set ajax hooks |
|
| 46 | + */ |
|
| 47 | + protected function _ajax_hooks() |
|
| 48 | + { |
|
| 49 | + add_action('wp_ajax_espresso_display_country_settings', array($this, 'display_country_settings')); |
|
| 50 | + add_action('wp_ajax_espresso_display_country_states', array($this, 'display_country_states')); |
|
| 51 | + add_action('wp_ajax_espresso_delete_state', array($this, 'delete_state'), 10, 3); |
|
| 52 | + add_action('wp_ajax_espresso_add_new_state', array($this, 'add_new_state')); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * More page properties initialization. |
|
| 58 | + */ |
|
| 59 | + protected function _define_page_props() |
|
| 60 | + { |
|
| 61 | + $this->_admin_page_title = GEN_SET_LABEL; |
|
| 62 | + $this->_labels = array( |
|
| 63 | + 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
| 64 | + ); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Set page routes property. |
|
| 70 | + */ |
|
| 71 | + protected function _set_page_routes() |
|
| 72 | + { |
|
| 73 | + $this->_page_routes = array( |
|
| 74 | + |
|
| 75 | + 'critical_pages' => array( |
|
| 76 | + 'func' => '_espresso_page_settings', |
|
| 77 | + 'capability' => 'manage_options', |
|
| 78 | + ), |
|
| 79 | + 'update_espresso_page_settings' => array( |
|
| 80 | + 'func' => '_update_espresso_page_settings', |
|
| 81 | + 'capability' => 'manage_options', |
|
| 82 | + 'noheader' => true, |
|
| 83 | + ), |
|
| 84 | + 'default' => array( |
|
| 85 | + 'func' => '_your_organization_settings', |
|
| 86 | + 'capability' => 'manage_options', |
|
| 87 | + ), |
|
| 88 | + |
|
| 89 | + 'update_your_organization_settings' => array( |
|
| 90 | + 'func' => '_update_your_organization_settings', |
|
| 91 | + 'capability' => 'manage_options', |
|
| 92 | + 'noheader' => true, |
|
| 93 | + ), |
|
| 94 | + |
|
| 95 | + 'admin_option_settings' => array( |
|
| 96 | + 'func' => '_admin_option_settings', |
|
| 97 | + 'capability' => 'manage_options', |
|
| 98 | + ), |
|
| 99 | + |
|
| 100 | + 'update_admin_option_settings' => array( |
|
| 101 | + 'func' => '_update_admin_option_settings', |
|
| 102 | + 'capability' => 'manage_options', |
|
| 103 | + 'noheader' => true, |
|
| 104 | + ), |
|
| 105 | + |
|
| 106 | + 'country_settings' => array( |
|
| 107 | + 'func' => '_country_settings', |
|
| 108 | + 'capability' => 'manage_options', |
|
| 109 | + ), |
|
| 110 | + |
|
| 111 | + 'update_country_settings' => array( |
|
| 112 | + 'func' => '_update_country_settings', |
|
| 113 | + 'capability' => 'manage_options', |
|
| 114 | + 'noheader' => true, |
|
| 115 | + ), |
|
| 116 | + |
|
| 117 | + 'display_country_settings' => array( |
|
| 118 | + 'func' => 'display_country_settings', |
|
| 119 | + 'capability' => 'manage_options', |
|
| 120 | + 'noheader' => true, |
|
| 121 | + ), |
|
| 122 | + |
|
| 123 | + 'add_new_state' => array( |
|
| 124 | + 'func' => 'add_new_state', |
|
| 125 | + 'capability' => 'manage_options', |
|
| 126 | + 'noheader' => true, |
|
| 127 | + ), |
|
| 128 | + |
|
| 129 | + 'delete_state' => array( |
|
| 130 | + 'func' => 'delete_state', |
|
| 131 | + 'capability' => 'manage_options', |
|
| 132 | + 'noheader' => true, |
|
| 133 | + ), |
|
| 134 | + 'privacy_settings' => array( |
|
| 135 | + 'func' => 'privacySettings', |
|
| 136 | + 'capability' => 'manage_options', |
|
| 137 | + ), |
|
| 138 | + 'update_privacy_settings' => array( |
|
| 139 | + 'func' => 'updatePrivacySettings', |
|
| 140 | + 'capability' => 'manage_options', |
|
| 141 | + 'noheader' => true, |
|
| 142 | + 'headers_sent_route' => 'privacy_settings', |
|
| 143 | + ), |
|
| 144 | + ); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * Set page configuration property |
|
| 150 | + */ |
|
| 151 | + protected function _set_page_config() |
|
| 152 | + { |
|
| 153 | + $this->_page_config = array( |
|
| 154 | + 'critical_pages' => array( |
|
| 155 | + 'nav' => array( |
|
| 156 | + 'label' => esc_html__('Critical Pages', 'event_espresso'), |
|
| 157 | + 'order' => 50, |
|
| 158 | + ), |
|
| 159 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 160 | + 'help_tabs' => array( |
|
| 161 | + 'general_settings_critical_pages_help_tab' => array( |
|
| 162 | + 'title' => esc_html__('Critical Pages', 'event_espresso'), |
|
| 163 | + 'filename' => 'general_settings_critical_pages', |
|
| 164 | + ), |
|
| 165 | + ), |
|
| 166 | + 'help_tour' => array('Critical_Pages_Help_Tour'), |
|
| 167 | + 'require_nonce' => false, |
|
| 168 | + ), |
|
| 169 | + 'default' => array( |
|
| 170 | + 'nav' => array( |
|
| 171 | + 'label' => esc_html__('Your Organization', 'event_espresso'), |
|
| 172 | + 'order' => 20, |
|
| 173 | + ), |
|
| 174 | + 'help_tabs' => array( |
|
| 175 | + 'general_settings_your_organization_help_tab' => array( |
|
| 176 | + 'title' => esc_html__('Your Organization', 'event_espresso'), |
|
| 177 | + 'filename' => 'general_settings_your_organization', |
|
| 178 | + ), |
|
| 179 | + ), |
|
| 180 | + 'help_tour' => array('Your_Organization_Help_Tour'), |
|
| 181 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 182 | + 'require_nonce' => false, |
|
| 183 | + ), |
|
| 184 | + 'admin_option_settings' => array( |
|
| 185 | + 'nav' => array( |
|
| 186 | + 'label' => esc_html__('Admin Options', 'event_espresso'), |
|
| 187 | + 'order' => 60, |
|
| 188 | + ), |
|
| 189 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 190 | + 'help_tabs' => array( |
|
| 191 | + 'general_settings_admin_options_help_tab' => array( |
|
| 192 | + 'title' => esc_html__('Admin Options', 'event_espresso'), |
|
| 193 | + 'filename' => 'general_settings_admin_options', |
|
| 194 | + ), |
|
| 195 | + ), |
|
| 196 | + 'help_tour' => array('Admin_Options_Help_Tour'), |
|
| 197 | + 'require_nonce' => false, |
|
| 198 | + ), |
|
| 199 | + 'country_settings' => array( |
|
| 200 | + 'nav' => array( |
|
| 201 | + 'label' => esc_html__('Countries', 'event_espresso'), |
|
| 202 | + 'order' => 70, |
|
| 203 | + ), |
|
| 204 | + 'help_tabs' => array( |
|
| 205 | + 'general_settings_countries_help_tab' => array( |
|
| 206 | + 'title' => esc_html__('Countries', 'event_espresso'), |
|
| 207 | + 'filename' => 'general_settings_countries', |
|
| 208 | + ), |
|
| 209 | + ), |
|
| 210 | + 'help_tour' => array('Countries_Help_Tour'), |
|
| 211 | + 'require_nonce' => false, |
|
| 212 | + ), |
|
| 213 | + 'privacy_settings' => array( |
|
| 214 | + 'nav' => array( |
|
| 215 | + 'label' => esc_html__('Privacy', 'event_espresso'), |
|
| 216 | + 'order' => 80, |
|
| 217 | + ), |
|
| 218 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 219 | + 'require_nonce' => false, |
|
| 220 | + ), |
|
| 221 | + ); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + |
|
| 225 | + protected function _add_screen_options() |
|
| 226 | + { |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + |
|
| 230 | + protected function _add_feature_pointers() |
|
| 231 | + { |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * Enqueue global scripts and styles for all routes in the General Settings Admin Pages. |
|
| 237 | + */ |
|
| 238 | + public function load_scripts_styles() |
|
| 239 | + { |
|
| 240 | + // styles |
|
| 241 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 242 | + // scripts |
|
| 243 | + wp_enqueue_script('ee_admin_js'); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * Execute logic running on `admin_init` |
|
| 249 | + */ |
|
| 250 | + public function admin_init() |
|
| 251 | + { |
|
| 252 | + EE_Registry::$i18n_js_strings['invalid_server_response'] = wp_strip_all_tags(__( |
|
| 253 | + 'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.', |
|
| 254 | + 'event_espresso' |
|
| 255 | + )); |
|
| 256 | + EE_Registry::$i18n_js_strings['error_occurred'] = wp_strip_all_tags(__( |
|
| 257 | + 'An error occurred! Please refresh the page and try again.', |
|
| 258 | + 'event_espresso' |
|
| 259 | + )); |
|
| 260 | + EE_Registry::$i18n_js_strings['confirm_delete_state'] = wp_strip_all_tags(__( |
|
| 261 | + 'Are you sure you want to delete this State / Province?', |
|
| 262 | + 'event_espresso' |
|
| 263 | + )); |
|
| 264 | + $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
| 265 | + EE_Registry::$i18n_js_strings['ajax_url'] = admin_url( |
|
| 266 | + 'admin-ajax.php?page=espresso_general_settings', |
|
| 267 | + $protocol |
|
| 268 | + ); |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + |
|
| 272 | + public function admin_notices() |
|
| 273 | + { |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + |
|
| 277 | + public function admin_footer_scripts() |
|
| 278 | + { |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + |
|
| 282 | + /** |
|
| 283 | + * Enqueue scripts and styles for the default route. |
|
| 284 | + */ |
|
| 285 | + public function load_scripts_styles_default() |
|
| 286 | + { |
|
| 287 | + // styles |
|
| 288 | + wp_enqueue_style('thickbox'); |
|
| 289 | + // scripts |
|
| 290 | + wp_enqueue_script('media-upload'); |
|
| 291 | + wp_enqueue_script('thickbox'); |
|
| 292 | + wp_register_script( |
|
| 293 | + 'organization_settings', |
|
| 294 | + GEN_SET_ASSETS_URL . 'your_organization_settings.js', |
|
| 295 | + array('jquery', 'media-upload', 'thickbox'), |
|
| 296 | + EVENT_ESPRESSO_VERSION, |
|
| 297 | + true |
|
| 298 | + ); |
|
| 299 | + wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 300 | + wp_enqueue_script('organization_settings'); |
|
| 301 | + wp_enqueue_style('organization-css'); |
|
| 302 | + $confirm_image_delete = array( |
|
| 303 | + 'text' => wp_strip_all_tags( |
|
| 304 | + __( |
|
| 305 | + 'Do you really want to delete this image? Please remember to save your settings to complete the removal.', |
|
| 306 | + 'event_espresso' |
|
| 307 | + ) |
|
| 308 | + ), |
|
| 309 | + ); |
|
| 310 | + wp_localize_script('organization_settings', 'confirm_image_delete', $confirm_image_delete); |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + |
|
| 314 | + /** |
|
| 315 | + * Enqueue scripts and styles for the country settings route. |
|
| 316 | + */ |
|
| 317 | + public function load_scripts_styles_country_settings() |
|
| 318 | + { |
|
| 319 | + // scripts |
|
| 320 | + wp_register_script( |
|
| 321 | + 'gen_settings_countries', |
|
| 322 | + GEN_SET_ASSETS_URL . 'gen_settings_countries.js', |
|
| 323 | + array('ee_admin_js'), |
|
| 324 | + EVENT_ESPRESSO_VERSION, |
|
| 325 | + true |
|
| 326 | + ); |
|
| 327 | + wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 328 | + wp_enqueue_script('gen_settings_countries'); |
|
| 329 | + wp_enqueue_style('organization-css'); |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + |
|
| 333 | + /************* Espresso Pages *************/ |
|
| 334 | + /** |
|
| 335 | + * _espresso_page_settings |
|
| 336 | + * |
|
| 337 | + * @throws \EE_Error |
|
| 338 | + * @throws DomainException |
|
| 339 | + * @throws DomainException |
|
| 340 | + * @throws InvalidDataTypeException |
|
| 341 | + * @throws InvalidArgumentException |
|
| 342 | + */ |
|
| 343 | + protected function _espresso_page_settings() |
|
| 344 | + { |
|
| 345 | + // Check to make sure all of the main pages are setup properly, |
|
| 346 | + // if not create the default pages and display an admin notice |
|
| 347 | + EEH_Activation::verify_default_pages_exist(); |
|
| 348 | + $this->_transient_garbage_collection(); |
|
| 349 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
| 350 | + $this->_template_args['reg_page_id'] = isset(EE_Registry::instance()->CFG->core->reg_page_id) |
|
| 351 | + ? EE_Registry::instance()->CFG->core->reg_page_id |
|
| 352 | + : null; |
|
| 353 | + $this->_template_args['reg_page_obj'] = isset(EE_Registry::instance()->CFG->core->reg_page_id) |
|
| 354 | + ? get_page(EE_Registry::instance()->CFG->core->reg_page_id) |
|
| 355 | + : false; |
|
| 356 | + $this->_template_args['txn_page_id'] = isset(EE_Registry::instance()->CFG->core->txn_page_id) |
|
| 357 | + ? EE_Registry::instance()->CFG->core->txn_page_id |
|
| 358 | + : null; |
|
| 359 | + $this->_template_args['txn_page_obj'] = isset(EE_Registry::instance()->CFG->core->txn_page_id) |
|
| 360 | + ? get_page(EE_Registry::instance()->CFG->core->txn_page_id) |
|
| 361 | + : false; |
|
| 362 | + $this->_template_args['thank_you_page_id'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id) |
|
| 363 | + ? EE_Registry::instance()->CFG->core->thank_you_page_id |
|
| 364 | + : null; |
|
| 365 | + $this->_template_args['thank_you_page_obj'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id) |
|
| 366 | + ? get_page(EE_Registry::instance()->CFG->core->thank_you_page_id) |
|
| 367 | + : false; |
|
| 368 | + $this->_template_args['cancel_page_id'] = isset(EE_Registry::instance()->CFG->core->cancel_page_id) |
|
| 369 | + ? EE_Registry::instance()->CFG->core->cancel_page_id |
|
| 370 | + : null; |
|
| 371 | + $this->_template_args['cancel_page_obj'] = isset(EE_Registry::instance()->CFG->core->cancel_page_id) |
|
| 372 | + ? get_page(EE_Registry::instance()->CFG->core->cancel_page_id) |
|
| 373 | + : false; |
|
| 374 | + $this->_set_add_edit_form_tags('update_espresso_page_settings'); |
|
| 375 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 376 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 377 | + GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php', |
|
| 378 | + $this->_template_args, |
|
| 379 | + true |
|
| 380 | + ); |
|
| 381 | + $this->display_admin_page_with_sidebar(); |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * Handler for updating espresso page settings. |
|
| 387 | + * |
|
| 388 | + * @throws EE_Error |
|
| 389 | + */ |
|
| 390 | + protected function _update_espresso_page_settings() |
|
| 391 | + { |
|
| 392 | + // capture incoming request data && set page IDs |
|
| 393 | + EE_Registry::instance()->CFG->core->reg_page_id = isset($this->_req_data['reg_page_id']) |
|
| 394 | + ? absint($this->_req_data['reg_page_id']) |
|
| 395 | + : EE_Registry::instance()->CFG->core->reg_page_id; |
|
| 396 | + EE_Registry::instance()->CFG->core->txn_page_id = isset($this->_req_data['txn_page_id']) |
|
| 397 | + ? absint($this->_req_data['txn_page_id']) |
|
| 398 | + : EE_Registry::instance()->CFG->core->txn_page_id; |
|
| 399 | + EE_Registry::instance()->CFG->core->thank_you_page_id = isset($this->_req_data['thank_you_page_id']) |
|
| 400 | + ? absint($this->_req_data['thank_you_page_id']) |
|
| 401 | + : EE_Registry::instance()->CFG->core->thank_you_page_id; |
|
| 402 | + EE_Registry::instance()->CFG->core->cancel_page_id = isset($this->_req_data['cancel_page_id']) |
|
| 403 | + ? absint($this->_req_data['cancel_page_id']) |
|
| 404 | + : EE_Registry::instance()->CFG->core->cancel_page_id; |
|
| 405 | + |
|
| 406 | + EE_Registry::instance()->CFG->core = apply_filters( |
|
| 407 | + 'FHEE__General_Settings_Admin_Page___update_espresso_page_settings__CFG_core', |
|
| 408 | + EE_Registry::instance()->CFG->core, |
|
| 409 | + $this->_req_data |
|
| 410 | + ); |
|
| 411 | + $what = esc_html__('Critical Pages & Shortcodes', 'event_espresso'); |
|
| 412 | + $this->_redirect_after_action( |
|
| 413 | + $this->_update_espresso_configuration( |
|
| 414 | + $what, |
|
| 415 | + EE_Registry::instance()->CFG->core, |
|
| 416 | + __FILE__, |
|
| 417 | + __FUNCTION__, |
|
| 418 | + __LINE__ |
|
| 419 | + ), |
|
| 420 | + $what, |
|
| 421 | + '', |
|
| 422 | + array( |
|
| 423 | + 'action' => 'critical_pages', |
|
| 424 | + ), |
|
| 425 | + true |
|
| 426 | + ); |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + |
|
| 430 | + /************* Your Organization *************/ |
|
| 431 | + |
|
| 432 | + |
|
| 433 | + /** |
|
| 434 | + * @throws DomainException |
|
| 435 | + * @throws EE_Error |
|
| 436 | + * @throws InvalidArgumentException |
|
| 437 | + * @throws InvalidDataTypeException |
|
| 438 | + * @throws InvalidInterfaceException |
|
| 439 | + */ |
|
| 440 | + protected function _your_organization_settings() |
|
| 441 | + { |
|
| 442 | + $this->_template_args['admin_page_content'] = ''; |
|
| 443 | + try { |
|
| 444 | + /** @var EventEspresso\admin_pages\general_settings\OrganizationSettings $organization_settings_form */ |
|
| 445 | + $organization_settings_form = $this->loader->getShared( |
|
| 446 | + 'EventEspresso\admin_pages\general_settings\OrganizationSettings' |
|
| 447 | + ); |
|
| 448 | + $this->_template_args['admin_page_content'] = $organization_settings_form->display(); |
|
| 449 | + } catch (Exception $e) { |
|
| 450 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 451 | + } |
|
| 452 | + $this->_set_add_edit_form_tags('update_your_organization_settings'); |
|
| 453 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 454 | + $this->display_admin_page_with_sidebar(); |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * Handler for updating organization settings. |
|
| 460 | + * |
|
| 461 | + * @throws EE_Error |
|
| 462 | + */ |
|
| 463 | + protected function _update_your_organization_settings() |
|
| 464 | + { |
|
| 465 | + try { |
|
| 466 | + /** @var EventEspresso\admin_pages\general_settings\OrganizationSettings $organization_settings_form */ |
|
| 467 | + $organization_settings_form = $this->loader->getShared( |
|
| 468 | + 'EventEspresso\admin_pages\general_settings\OrganizationSettings' |
|
| 469 | + ); |
|
| 470 | + $success = $organization_settings_form->process($this->_req_data); |
|
| 471 | + EE_Registry::instance()->CFG = apply_filters( |
|
| 472 | + 'FHEE__General_Settings_Admin_Page___update_your_organization_settings__CFG', |
|
| 473 | + EE_Registry::instance()->CFG |
|
| 474 | + ); |
|
| 475 | + } catch (Exception $e) { |
|
| 476 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 477 | + $success = false; |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + if ($success) { |
|
| 481 | + $success = $this->_update_espresso_configuration( |
|
| 482 | + esc_html__('Your Organization Settings', 'event_espresso'), |
|
| 483 | + EE_Registry::instance()->CFG, |
|
| 484 | + __FILE__, |
|
| 485 | + __FUNCTION__, |
|
| 486 | + __LINE__ |
|
| 487 | + ); |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + $this->_redirect_after_action($success, '', '', array('action' => 'default'), true); |
|
| 491 | + } |
|
| 492 | + |
|
| 493 | + |
|
| 494 | + |
|
| 495 | + /************* Admin Options *************/ |
|
| 496 | + |
|
| 497 | + |
|
| 498 | + /** |
|
| 499 | + * _admin_option_settings |
|
| 500 | + * |
|
| 501 | + * @throws \EE_Error |
|
| 502 | + * @throws \LogicException |
|
| 503 | + */ |
|
| 504 | + protected function _admin_option_settings() |
|
| 505 | + { |
|
| 506 | + $this->_template_args['admin_page_content'] = ''; |
|
| 507 | + try { |
|
| 508 | + $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance()); |
|
| 509 | + // still need this for the old school form in Extend_General_Settings_Admin_Page |
|
| 510 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
| 511 | + // also need to account for the do_action that was in the old template |
|
| 512 | + $admin_options_settings_form->setTemplateArgs($this->_template_args); |
|
| 513 | + $this->_template_args['admin_page_content'] = $admin_options_settings_form->display(); |
|
| 514 | + } catch (Exception $e) { |
|
| 515 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 516 | + } |
|
| 517 | + $this->_set_add_edit_form_tags('update_admin_option_settings'); |
|
| 518 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 519 | + $this->display_admin_page_with_sidebar(); |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + |
|
| 523 | + /** |
|
| 524 | + * _update_admin_option_settings |
|
| 525 | + * |
|
| 526 | + * @throws \EE_Error |
|
| 527 | + * @throws InvalidDataTypeException |
|
| 528 | + * @throws \EventEspresso\core\exceptions\InvalidFormSubmissionException |
|
| 529 | + * @throws \InvalidArgumentException |
|
| 530 | + * @throws \LogicException |
|
| 531 | + */ |
|
| 532 | + protected function _update_admin_option_settings() |
|
| 533 | + { |
|
| 534 | + try { |
|
| 535 | + $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance()); |
|
| 536 | + $admin_options_settings_form->process($this->_req_data[ $admin_options_settings_form->slug() ]); |
|
| 537 | + EE_Registry::instance()->CFG->admin = apply_filters( |
|
| 538 | + 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__CFG_admin', |
|
| 539 | + EE_Registry::instance()->CFG->admin |
|
| 540 | + ); |
|
| 541 | + } catch (Exception $e) { |
|
| 542 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 543 | + } |
|
| 544 | + $this->_redirect_after_action( |
|
| 545 | + apply_filters( |
|
| 546 | + 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__success', |
|
| 547 | + $this->_update_espresso_configuration( |
|
| 548 | + 'Admin Options', |
|
| 549 | + EE_Registry::instance()->CFG->admin, |
|
| 550 | + __FILE__, |
|
| 551 | + __FUNCTION__, |
|
| 552 | + __LINE__ |
|
| 553 | + ) |
|
| 554 | + ), |
|
| 555 | + 'Admin Options', |
|
| 556 | + 'updated', |
|
| 557 | + array('action' => 'admin_option_settings') |
|
| 558 | + ); |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + |
|
| 562 | + /************* Countries *************/ |
|
| 563 | + |
|
| 564 | + |
|
| 565 | + /** |
|
| 566 | + * @return string |
|
| 567 | + */ |
|
| 568 | + protected function getCountryIsoForSite() |
|
| 569 | + { |
|
| 570 | + return ! empty(EE_Registry::instance()->CFG->organization->CNT_ISO) |
|
| 571 | + ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 572 | + : 'US'; |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + |
|
| 576 | + /** |
|
| 577 | + * @param string $CNT_ISO |
|
| 578 | + * @param EE_Country|null $country |
|
| 579 | + * @return EE_Base_Class|EE_Country |
|
| 580 | + * @throws EE_Error |
|
| 581 | + * @throws InvalidArgumentException |
|
| 582 | + * @throws InvalidDataTypeException |
|
| 583 | + * @throws InvalidInterfaceException |
|
| 584 | + * @throws ReflectionException |
|
| 585 | + */ |
|
| 586 | + protected function verifyOrGetCountryFromIso($CNT_ISO, EE_Country $country = null) |
|
| 587 | + { |
|
| 588 | + /** @var EE_Country $country */ |
|
| 589 | + return $country instanceof EE_Country && $country->ID() === $CNT_ISO |
|
| 590 | + ? $country |
|
| 591 | + : EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + |
|
| 595 | + /** |
|
| 596 | + * Output Country Settings view. |
|
| 597 | + * |
|
| 598 | + * @throws DomainException |
|
| 599 | + * @throws EE_Error |
|
| 600 | + * @throws InvalidArgumentException |
|
| 601 | + * @throws InvalidDataTypeException |
|
| 602 | + * @throws InvalidInterfaceException |
|
| 603 | + * @throws ReflectionException |
|
| 604 | + */ |
|
| 605 | + protected function _country_settings() |
|
| 606 | + { |
|
| 607 | + $CNT_ISO_for_site = $this->getCountryIsoForSite(); |
|
| 608 | + $CNT_ISO = isset($this->_req_data['country']) |
|
| 609 | + ? strtoupper(sanitize_text_field($this->_req_data['country'])) |
|
| 610 | + : $CNT_ISO_for_site; |
|
| 611 | + |
|
| 612 | + // load field generator helper |
|
| 613 | + |
|
| 614 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
| 615 | + |
|
| 616 | + $this->_template_args['countries'] = new EE_Question_Form_Input( |
|
| 617 | + EE_Question::new_instance( |
|
| 618 | + array( |
|
| 619 | + 'QST_ID' => 0, |
|
| 620 | + 'QST_display_text' => esc_html__('Select Country', 'event_espresso'), |
|
| 621 | + 'QST_system' => 'admin-country', |
|
| 622 | + ) |
|
| 623 | + ), |
|
| 624 | + EE_Answer::new_instance( |
|
| 625 | + array( |
|
| 626 | + 'ANS_ID' => 0, |
|
| 627 | + 'ANS_value' => $CNT_ISO, |
|
| 628 | + ) |
|
| 629 | + ), |
|
| 630 | + array( |
|
| 631 | + 'input_id' => 'country', |
|
| 632 | + 'input_name' => 'country', |
|
| 633 | + 'input_prefix' => '', |
|
| 634 | + 'append_qstn_id' => false, |
|
| 635 | + ) |
|
| 636 | + ); |
|
| 637 | + $country = $this->verifyOrGetCountryFromIso($CNT_ISO_for_site); |
|
| 638 | + add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2); |
|
| 639 | + add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2); |
|
| 640 | + $this->_template_args['country_details_settings'] = $this->display_country_settings( |
|
| 641 | + $country->ID(), |
|
| 642 | + $country |
|
| 643 | + ); |
|
| 644 | + $this->_template_args['country_states_settings'] = $this->display_country_states( |
|
| 645 | + $country->ID(), |
|
| 646 | + $country |
|
| 647 | + ); |
|
| 648 | + $this->_template_args['CNT_name_for_site'] = $country->name(); |
|
| 649 | + |
|
| 650 | + $this->_set_add_edit_form_tags('update_country_settings'); |
|
| 651 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 652 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 653 | + GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php', |
|
| 654 | + $this->_template_args, |
|
| 655 | + true |
|
| 656 | + ); |
|
| 657 | + $this->display_admin_page_with_no_sidebar(); |
|
| 658 | + } |
|
| 659 | + |
|
| 660 | + |
|
| 661 | + /** |
|
| 662 | + * display_country_settings |
|
| 663 | + * |
|
| 664 | + * @param string $CNT_ISO |
|
| 665 | + * @param EE_Country|null $country |
|
| 666 | + * @return mixed string | array$country |
|
| 667 | + * @throws DomainException |
|
| 668 | + * @throws EE_Error |
|
| 669 | + * @throws InvalidArgumentException |
|
| 670 | + * @throws InvalidDataTypeException |
|
| 671 | + * @throws InvalidInterfaceException |
|
| 672 | + * @throws ReflectionException |
|
| 673 | + */ |
|
| 674 | + public function display_country_settings($CNT_ISO = '', EE_Country $country = null) |
|
| 675 | + { |
|
| 676 | + $CNT_ISO_for_site = $this->getCountryIsoForSite(); |
|
| 677 | + |
|
| 678 | + $CNT_ISO = isset($this->_req_data['country']) |
|
| 679 | + ? strtoupper(sanitize_text_field($this->_req_data['country'])) |
|
| 680 | + : $CNT_ISO; |
|
| 681 | + if (! $CNT_ISO) { |
|
| 682 | + return ''; |
|
| 683 | + } |
|
| 684 | + |
|
| 685 | + // for ajax |
|
| 686 | + remove_all_filters('FHEE__EEH_Form_Fields__label_html'); |
|
| 687 | + remove_all_filters('FHEE__EEH_Form_Fields__input_html'); |
|
| 688 | + add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2); |
|
| 689 | + add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2); |
|
| 690 | + $country = $this->verifyOrGetCountryFromIso($CNT_ISO, $country); |
|
| 691 | + $CNT_cur_disabled = $CNT_ISO !== $CNT_ISO_for_site; |
|
| 692 | + $this->_template_args['CNT_cur_disabled'] = $CNT_cur_disabled; |
|
| 693 | + |
|
| 694 | + $country_input_types = array( |
|
| 695 | + 'CNT_active' => array( |
|
| 696 | + 'type' => 'RADIO_BTN', |
|
| 697 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 698 | + 'class' => '', |
|
| 699 | + 'options' => $this->_yes_no_values, |
|
| 700 | + 'use_desc_4_label' => true, |
|
| 701 | + ), |
|
| 702 | + 'CNT_ISO' => array( |
|
| 703 | + 'type' => 'TEXT', |
|
| 704 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 705 | + 'class' => 'small-text', |
|
| 706 | + ), |
|
| 707 | + 'CNT_ISO3' => array( |
|
| 708 | + 'type' => 'TEXT', |
|
| 709 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 710 | + 'class' => 'small-text', |
|
| 711 | + ), |
|
| 712 | + 'RGN_ID' => array( |
|
| 713 | + 'type' => 'TEXT', |
|
| 714 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 715 | + 'class' => 'small-text', |
|
| 716 | + ), |
|
| 717 | + 'CNT_name' => array( |
|
| 718 | + 'type' => 'TEXT', |
|
| 719 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 720 | + 'class' => 'regular-text', |
|
| 721 | + ), |
|
| 722 | + 'CNT_cur_code' => array( |
|
| 723 | + 'type' => 'TEXT', |
|
| 724 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 725 | + 'class' => 'small-text', |
|
| 726 | + 'disabled' => $CNT_cur_disabled, |
|
| 727 | + ), |
|
| 728 | + 'CNT_cur_single' => array( |
|
| 729 | + 'type' => 'TEXT', |
|
| 730 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 731 | + 'class' => 'medium-text', |
|
| 732 | + 'disabled' => $CNT_cur_disabled, |
|
| 733 | + ), |
|
| 734 | + 'CNT_cur_plural' => array( |
|
| 735 | + 'type' => 'TEXT', |
|
| 736 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 737 | + 'class' => 'medium-text', |
|
| 738 | + 'disabled' => $CNT_cur_disabled, |
|
| 739 | + ), |
|
| 740 | + 'CNT_cur_sign' => array( |
|
| 741 | + 'type' => 'TEXT', |
|
| 742 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 743 | + 'class' => 'small-text', |
|
| 744 | + 'htmlentities' => false, |
|
| 745 | + 'disabled' => $CNT_cur_disabled, |
|
| 746 | + ), |
|
| 747 | + 'CNT_cur_sign_b4' => array( |
|
| 748 | + 'type' => 'RADIO_BTN', |
|
| 749 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 750 | + 'class' => '', |
|
| 751 | + 'options' => $this->_yes_no_values, |
|
| 752 | + 'use_desc_4_label' => true, |
|
| 753 | + 'disabled' => $CNT_cur_disabled, |
|
| 754 | + ), |
|
| 755 | + 'CNT_cur_dec_plc' => array( |
|
| 756 | + 'type' => 'RADIO_BTN', |
|
| 757 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 758 | + 'class' => '', |
|
| 759 | + 'options' => array( |
|
| 760 | + array('id' => 0, 'text' => ''), |
|
| 761 | + array('id' => 1, 'text' => ''), |
|
| 762 | + array('id' => 2, 'text' => ''), |
|
| 763 | + array('id' => 3, 'text' => ''), |
|
| 764 | + ), |
|
| 765 | + 'disabled' => $CNT_cur_disabled, |
|
| 766 | + ), |
|
| 767 | + 'CNT_cur_dec_mrk' => array( |
|
| 768 | + 'type' => 'RADIO_BTN', |
|
| 769 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 770 | + 'class' => '', |
|
| 771 | + 'options' => array( |
|
| 772 | + array( |
|
| 773 | + 'id' => ',', |
|
| 774 | + 'text' => esc_html__(', (comma)', 'event_espresso'), |
|
| 775 | + ), |
|
| 776 | + array('id' => '.', 'text' => esc_html__('. (decimal)', 'event_espresso')), |
|
| 777 | + ), |
|
| 778 | + 'use_desc_4_label' => true, |
|
| 779 | + 'disabled' => $CNT_cur_disabled, |
|
| 780 | + ), |
|
| 781 | + 'CNT_cur_thsnds' => array( |
|
| 782 | + 'type' => 'RADIO_BTN', |
|
| 783 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 784 | + 'class' => '', |
|
| 785 | + 'options' => array( |
|
| 786 | + array( |
|
| 787 | + 'id' => ',', |
|
| 788 | + 'text' => esc_html__(', (comma)', 'event_espresso'), |
|
| 789 | + ), |
|
| 790 | + array( |
|
| 791 | + 'id' => '.', |
|
| 792 | + 'text' => esc_html__('. (decimal)', 'event_espresso') |
|
| 793 | + ), |
|
| 794 | + array( |
|
| 795 | + 'id' => ' ', |
|
| 796 | + 'text' => esc_html__('(space)', 'event_espresso') |
|
| 797 | + ) |
|
| 798 | + ), |
|
| 799 | + 'use_desc_4_label' => true, |
|
| 800 | + 'disabled' => $CNT_cur_disabled, |
|
| 801 | + ), |
|
| 802 | + 'CNT_tel_code' => array( |
|
| 803 | + 'type' => 'TEXT', |
|
| 804 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 805 | + 'class' => 'small-text', |
|
| 806 | + ), |
|
| 807 | + 'CNT_is_EU' => array( |
|
| 808 | + 'type' => 'RADIO_BTN', |
|
| 809 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 810 | + 'class' => '', |
|
| 811 | + 'options' => $this->_yes_no_values, |
|
| 812 | + 'use_desc_4_label' => true, |
|
| 813 | + ), |
|
| 814 | + ); |
|
| 815 | + $this->_template_args['inputs'] = EE_Question_Form_Input::generate_question_form_inputs_for_object( |
|
| 816 | + $country, |
|
| 817 | + $country_input_types |
|
| 818 | + ); |
|
| 819 | + $country_details_settings = EEH_Template::display_template( |
|
| 820 | + GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php', |
|
| 821 | + $this->_template_args, |
|
| 822 | + true |
|
| 823 | + ); |
|
| 824 | + |
|
| 825 | + if (defined('DOING_AJAX')) { |
|
| 826 | + $notices = EE_Error::get_notices(false, false, false); |
|
| 827 | + echo wp_json_encode( |
|
| 828 | + array( |
|
| 829 | + 'return_data' => $country_details_settings, |
|
| 830 | + 'success' => $notices['success'], |
|
| 831 | + 'errors' => $notices['errors'], |
|
| 832 | + ) |
|
| 833 | + ); |
|
| 834 | + die(); |
|
| 835 | + } else { |
|
| 836 | + return $country_details_settings; |
|
| 837 | + } |
|
| 838 | + } |
|
| 839 | + |
|
| 840 | + |
|
| 841 | + /** |
|
| 842 | + * @param string $CNT_ISO |
|
| 843 | + * @param EE_Country|null $country |
|
| 844 | + * @return string |
|
| 845 | + * @throws DomainException |
|
| 846 | + * @throws EE_Error |
|
| 847 | + * @throws InvalidArgumentException |
|
| 848 | + * @throws InvalidDataTypeException |
|
| 849 | + * @throws InvalidInterfaceException |
|
| 850 | + * @throws ReflectionException |
|
| 851 | + */ |
|
| 852 | + public function display_country_states($CNT_ISO = '', EE_Country $country = null) |
|
| 853 | + { |
|
| 854 | + |
|
| 855 | + $CNT_ISO = isset($this->_req_data['country']) |
|
| 856 | + ? sanitize_text_field($this->_req_data['country']) |
|
| 857 | + : $CNT_ISO; |
|
| 858 | + if (! $CNT_ISO) { |
|
| 859 | + return ''; |
|
| 860 | + } |
|
| 861 | + // for ajax |
|
| 862 | + remove_all_filters('FHEE__EEH_Form_Fields__label_html'); |
|
| 863 | + remove_all_filters('FHEE__EEH_Form_Fields__input_html'); |
|
| 864 | + add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'state_form_field_label_wrap'), 10, 2); |
|
| 865 | + add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'state_form_field_input__wrap'), 10, 2); |
|
| 866 | + $states = EEM_State::instance()->get_all_states_for_these_countries(array($CNT_ISO => $CNT_ISO)); |
|
| 867 | + if (empty($states)) { |
|
| 868 | + /** @var EventEspresso\core\services\address\CountrySubRegionDao $countrySubRegionDao */ |
|
| 869 | + $countrySubRegionDao = $this->loader->getShared( |
|
| 870 | + 'EventEspresso\core\services\address\CountrySubRegionDao' |
|
| 871 | + ); |
|
| 872 | + if ($countrySubRegionDao instanceof EventEspresso\core\services\address\CountrySubRegionDao) { |
|
| 873 | + $country = $this->verifyOrGetCountryFromIso($CNT_ISO, $country); |
|
| 874 | + if ($countrySubRegionDao->saveCountrySubRegions($country)) { |
|
| 875 | + $states = EEM_State::instance()->get_all_states_for_these_countries( |
|
| 876 | + array($CNT_ISO => $CNT_ISO) |
|
| 877 | + ); |
|
| 878 | + } |
|
| 879 | + } |
|
| 880 | + } |
|
| 881 | + if (is_array($states)) { |
|
| 882 | + foreach ($states as $STA_ID => $state) { |
|
| 883 | + if ($state instanceof EE_State) { |
|
| 884 | + // STA_abbrev STA_name STA_active |
|
| 885 | + $state_input_types = array( |
|
| 886 | + 'STA_abbrev' => array( |
|
| 887 | + 'type' => 'TEXT', |
|
| 888 | + 'input_name' => 'states[' . $STA_ID . ']', |
|
| 889 | + 'class' => 'mid-text', |
|
| 890 | + ), |
|
| 891 | + 'STA_name' => array( |
|
| 892 | + 'type' => 'TEXT', |
|
| 893 | + 'input_name' => 'states[' . $STA_ID . ']', |
|
| 894 | + 'class' => 'regular-text', |
|
| 895 | + ), |
|
| 896 | + 'STA_active' => array( |
|
| 897 | + 'type' => 'RADIO_BTN', |
|
| 898 | + 'input_name' => 'states[' . $STA_ID . ']', |
|
| 899 | + 'options' => $this->_yes_no_values, |
|
| 900 | + 'use_desc_4_label' => true, |
|
| 901 | + ), |
|
| 902 | + ); |
|
| 903 | + $this->_template_args['states'][ $STA_ID ]['inputs'] = |
|
| 904 | + EE_Question_Form_Input::generate_question_form_inputs_for_object( |
|
| 905 | + $state, |
|
| 906 | + $state_input_types |
|
| 907 | + ); |
|
| 908 | + $query_args = array( |
|
| 909 | + 'action' => 'delete_state', |
|
| 910 | + 'STA_ID' => $STA_ID, |
|
| 911 | + 'CNT_ISO' => $CNT_ISO, |
|
| 912 | + 'STA_abbrev' => $state->abbrev(), |
|
| 913 | + ); |
|
| 914 | + $this->_template_args['states'][ $STA_ID ]['delete_state_url'] = |
|
| 915 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 916 | + $query_args, |
|
| 917 | + GEN_SET_ADMIN_URL |
|
| 918 | + ); |
|
| 919 | + } |
|
| 920 | + } |
|
| 921 | + } else { |
|
| 922 | + $this->_template_args['states'] = false; |
|
| 923 | + } |
|
| 924 | + |
|
| 925 | + $this->_template_args['add_new_state_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 926 | + array('action' => 'add_new_state'), |
|
| 927 | + GEN_SET_ADMIN_URL |
|
| 928 | + ); |
|
| 929 | + |
|
| 930 | + $state_details_settings = EEH_Template::display_template( |
|
| 931 | + GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php', |
|
| 932 | + $this->_template_args, |
|
| 933 | + true |
|
| 934 | + ); |
|
| 935 | + |
|
| 936 | + if (defined('DOING_AJAX')) { |
|
| 937 | + $notices = EE_Error::get_notices(false, false, false); |
|
| 938 | + echo wp_json_encode( |
|
| 939 | + array( |
|
| 940 | + 'return_data' => $state_details_settings, |
|
| 941 | + 'success' => $notices['success'], |
|
| 942 | + 'errors' => $notices['errors'], |
|
| 943 | + ) |
|
| 944 | + ); |
|
| 945 | + die(); |
|
| 946 | + } else { |
|
| 947 | + return $state_details_settings; |
|
| 948 | + } |
|
| 949 | + } |
|
| 950 | + |
|
| 951 | + |
|
| 952 | + /** |
|
| 953 | + * add_new_state |
|
| 954 | + * |
|
| 955 | + * @access public |
|
| 956 | + * @return void |
|
| 957 | + * @throws EE_Error |
|
| 958 | + * @throws InvalidArgumentException |
|
| 959 | + * @throws InvalidDataTypeException |
|
| 960 | + * @throws InvalidInterfaceException |
|
| 961 | + */ |
|
| 962 | + public function add_new_state() |
|
| 963 | + { |
|
| 964 | + |
|
| 965 | + $success = true; |
|
| 966 | + |
|
| 967 | + $CNT_ISO = isset($this->_req_data['CNT_ISO']) |
|
| 968 | + ? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO'])) |
|
| 969 | + : false; |
|
| 970 | + if (! $CNT_ISO) { |
|
| 971 | + EE_Error::add_error( |
|
| 972 | + esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
|
| 973 | + __FILE__, |
|
| 974 | + __FUNCTION__, |
|
| 975 | + __LINE__ |
|
| 976 | + ); |
|
| 977 | + $success = false; |
|
| 978 | + } |
|
| 979 | + $STA_abbrev = isset($this->_req_data['STA_abbrev']) |
|
| 980 | + ? sanitize_text_field($this->_req_data['STA_abbrev']) |
|
| 981 | + : false; |
|
| 982 | + if (! $STA_abbrev) { |
|
| 983 | + EE_Error::add_error( |
|
| 984 | + esc_html__('No State ISO code or an invalid State ISO code was received.', 'event_espresso'), |
|
| 985 | + __FILE__, |
|
| 986 | + __FUNCTION__, |
|
| 987 | + __LINE__ |
|
| 988 | + ); |
|
| 989 | + $success = false; |
|
| 990 | + } |
|
| 991 | + $STA_name = isset($this->_req_data['STA_name']) |
|
| 992 | + ? sanitize_text_field($this->_req_data['STA_name']) |
|
| 993 | + : false; |
|
| 994 | + if (! $STA_name) { |
|
| 995 | + EE_Error::add_error( |
|
| 996 | + esc_html__('No State name or an invalid State name was received.', 'event_espresso'), |
|
| 997 | + __FILE__, |
|
| 998 | + __FUNCTION__, |
|
| 999 | + __LINE__ |
|
| 1000 | + ); |
|
| 1001 | + $success = false; |
|
| 1002 | + } |
|
| 1003 | + |
|
| 1004 | + if ($success) { |
|
| 1005 | + $cols_n_values = array( |
|
| 1006 | + 'CNT_ISO' => $CNT_ISO, |
|
| 1007 | + 'STA_abbrev' => $STA_abbrev, |
|
| 1008 | + 'STA_name' => $STA_name, |
|
| 1009 | + 'STA_active' => true, |
|
| 1010 | + ); |
|
| 1011 | + $success = EEM_State::instance()->insert($cols_n_values); |
|
| 1012 | + EE_Error::add_success(esc_html__('The State was added successfully.', 'event_espresso')); |
|
| 1013 | + } |
|
| 1014 | + |
|
| 1015 | + if (defined('DOING_AJAX')) { |
|
| 1016 | + $notices = EE_Error::get_notices(false, false, false); |
|
| 1017 | + echo wp_json_encode(array_merge($notices, array('return_data' => $CNT_ISO))); |
|
| 1018 | + die(); |
|
| 1019 | + } else { |
|
| 1020 | + $this->_redirect_after_action($success, 'State', 'added', array('action' => 'country_settings')); |
|
| 1021 | + } |
|
| 1022 | + } |
|
| 1023 | + |
|
| 1024 | + |
|
| 1025 | + /** |
|
| 1026 | + * delete_state |
|
| 1027 | + * |
|
| 1028 | + * @access public |
|
| 1029 | + * @return boolean |
|
| 1030 | + * @throws EE_Error |
|
| 1031 | + * @throws InvalidArgumentException |
|
| 1032 | + * @throws InvalidDataTypeException |
|
| 1033 | + * @throws InvalidInterfaceException |
|
| 1034 | + */ |
|
| 1035 | + public function delete_state() |
|
| 1036 | + { |
|
| 1037 | + $CNT_ISO = isset($this->_req_data['CNT_ISO']) |
|
| 1038 | + ? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO'])) |
|
| 1039 | + : false; |
|
| 1040 | + $STA_ID = isset($this->_req_data['STA_ID']) |
|
| 1041 | + ? sanitize_text_field($this->_req_data['STA_ID']) |
|
| 1042 | + : false; |
|
| 1043 | + $STA_abbrev = isset($this->_req_data['STA_abbrev']) |
|
| 1044 | + ? sanitize_text_field($this->_req_data['STA_abbrev']) |
|
| 1045 | + : false; |
|
| 1046 | + if (! $STA_ID) { |
|
| 1047 | + EE_Error::add_error( |
|
| 1048 | + esc_html__('No State ID or an invalid State ID was received.', 'event_espresso'), |
|
| 1049 | + __FILE__, |
|
| 1050 | + __FUNCTION__, |
|
| 1051 | + __LINE__ |
|
| 1052 | + ); |
|
| 1053 | + return false; |
|
| 1054 | + } |
|
| 1055 | + |
|
| 1056 | + $success = EEM_State::instance()->delete_by_ID($STA_ID); |
|
| 1057 | + if ($success !== false) { |
|
| 1058 | + do_action( |
|
| 1059 | + 'AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
| 1060 | + $CNT_ISO, |
|
| 1061 | + $STA_ID, |
|
| 1062 | + array('STA_abbrev' => $STA_abbrev) |
|
| 1063 | + ); |
|
| 1064 | + EE_Error::add_success(esc_html__('The State was deleted successfully.', 'event_espresso')); |
|
| 1065 | + } |
|
| 1066 | + if (defined('DOING_AJAX')) { |
|
| 1067 | + $notices = EE_Error::get_notices(false, false); |
|
| 1068 | + $notices['return_data'] = true; |
|
| 1069 | + echo wp_json_encode($notices); |
|
| 1070 | + die(); |
|
| 1071 | + } else { |
|
| 1072 | + $this->_redirect_after_action( |
|
| 1073 | + $success, |
|
| 1074 | + 'State', |
|
| 1075 | + 'deleted', |
|
| 1076 | + array('action' => 'country_settings') |
|
| 1077 | + ); |
|
| 1078 | + } |
|
| 1079 | + } |
|
| 1080 | + |
|
| 1081 | + |
|
| 1082 | + /** |
|
| 1083 | + * _update_country_settings |
|
| 1084 | + * |
|
| 1085 | + * @access protected |
|
| 1086 | + * @return void |
|
| 1087 | + * @throws EE_Error |
|
| 1088 | + * @throws InvalidArgumentException |
|
| 1089 | + * @throws InvalidDataTypeException |
|
| 1090 | + * @throws InvalidInterfaceException |
|
| 1091 | + */ |
|
| 1092 | + protected function _update_country_settings() |
|
| 1093 | + { |
|
| 1094 | + // grab the country ISO code |
|
| 1095 | + $CNT_ISO = isset($this->_req_data['country']) |
|
| 1096 | + ? strtoupper(sanitize_text_field($this->_req_data['country'])) |
|
| 1097 | + : false; |
|
| 1098 | + if (! $CNT_ISO) { |
|
| 1099 | + EE_Error::add_error( |
|
| 1100 | + esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
|
| 1101 | + __FILE__, |
|
| 1102 | + __FUNCTION__, |
|
| 1103 | + __LINE__ |
|
| 1104 | + ); |
|
| 1105 | + |
|
| 1106 | + return; |
|
| 1107 | + } |
|
| 1108 | + $cols_n_values = array(); |
|
| 1109 | + $cols_n_values['CNT_ISO3'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3']) |
|
| 1110 | + ? strtoupper(sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3'])) |
|
| 1111 | + : false; |
|
| 1112 | + $cols_n_values['RGN_ID'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID']) |
|
| 1113 | + ? absint($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID']) |
|
| 1114 | + : null; |
|
| 1115 | + $cols_n_values['CNT_name'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name']) |
|
| 1116 | + ? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name']) |
|
| 1117 | + : null; |
|
| 1118 | + if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code'])) { |
|
| 1119 | + $cols_n_values['CNT_cur_code'] = strtoupper( |
|
| 1120 | + sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code']) |
|
| 1121 | + ); |
|
| 1122 | + } |
|
| 1123 | + if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single'])) { |
|
| 1124 | + $cols_n_values['CNT_cur_single'] = sanitize_text_field( |
|
| 1125 | + $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single'] |
|
| 1126 | + ); |
|
| 1127 | + } |
|
| 1128 | + if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural'])) { |
|
| 1129 | + $cols_n_values['CNT_cur_plural'] = sanitize_text_field( |
|
| 1130 | + $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural'] |
|
| 1131 | + ); |
|
| 1132 | + } |
|
| 1133 | + if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign'])) { |
|
| 1134 | + $cols_n_values['CNT_cur_sign'] = sanitize_text_field( |
|
| 1135 | + $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign'] |
|
| 1136 | + ); |
|
| 1137 | + } |
|
| 1138 | + if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4'])) { |
|
| 1139 | + $cols_n_values['CNT_cur_sign_b4'] = absint( |
|
| 1140 | + $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4'] |
|
| 1141 | + ); |
|
| 1142 | + } |
|
| 1143 | + if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc'])) { |
|
| 1144 | + $cols_n_values['CNT_cur_dec_plc'] = absint( |
|
| 1145 | + $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc'] |
|
| 1146 | + ); |
|
| 1147 | + } |
|
| 1148 | + if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk'])) { |
|
| 1149 | + $cols_n_values['CNT_cur_dec_mrk'] = sanitize_text_field( |
|
| 1150 | + $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk'] |
|
| 1151 | + ); |
|
| 1152 | + } |
|
| 1153 | + if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds'])) { |
|
| 1154 | + $cols_n_values['CNT_cur_thsnds'] = sanitize_text_field( |
|
| 1155 | + $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds'] |
|
| 1156 | + ); |
|
| 1157 | + } |
|
| 1158 | + $cols_n_values['CNT_tel_code'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code']) |
|
| 1159 | + ? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code']) |
|
| 1160 | + : null; |
|
| 1161 | + $cols_n_values['CNT_is_EU'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU']) |
|
| 1162 | + ? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU']) |
|
| 1163 | + : false; |
|
| 1164 | + $cols_n_values['CNT_active'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active']) |
|
| 1165 | + ? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active']) |
|
| 1166 | + : false; |
|
| 1167 | + // allow filtering of country data |
|
| 1168 | + $cols_n_values = apply_filters( |
|
| 1169 | + 'FHEE__General_Settings_Admin_Page___update_country_settings__cols_n_values', |
|
| 1170 | + $cols_n_values |
|
| 1171 | + ); |
|
| 1172 | + |
|
| 1173 | + // where values |
|
| 1174 | + $where_cols_n_values = array(array('CNT_ISO' => $CNT_ISO)); |
|
| 1175 | + // run the update |
|
| 1176 | + $success = EEM_Country::instance()->update($cols_n_values, $where_cols_n_values); |
|
| 1177 | + |
|
| 1178 | + if (isset($this->_req_data['states']) && is_array($this->_req_data['states']) && $success !== false) { |
|
| 1179 | + // allow filtering of states data |
|
| 1180 | + $states = apply_filters( |
|
| 1181 | + 'FHEE__General_Settings_Admin_Page___update_country_settings__states', |
|
| 1182 | + $this->_req_data['states'] |
|
| 1183 | + ); |
|
| 1184 | + |
|
| 1185 | + // loop thru state data ( looks like : states[75][STA_name] ) |
|
| 1186 | + foreach ($states as $STA_ID => $state) { |
|
| 1187 | + $cols_n_values = array( |
|
| 1188 | + 'CNT_ISO' => $CNT_ISO, |
|
| 1189 | + 'STA_abbrev' => sanitize_text_field($state['STA_abbrev']), |
|
| 1190 | + 'STA_name' => sanitize_text_field($state['STA_name']), |
|
| 1191 | + 'STA_active' => (bool) absint($state['STA_active']), |
|
| 1192 | + ); |
|
| 1193 | + // where values |
|
| 1194 | + $where_cols_n_values = array(array('STA_ID' => $STA_ID)); |
|
| 1195 | + // run the update |
|
| 1196 | + $success = EEM_State::instance()->update($cols_n_values, $where_cols_n_values); |
|
| 1197 | + if ($success !== false) { |
|
| 1198 | + do_action( |
|
| 1199 | + 'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
| 1200 | + $CNT_ISO, |
|
| 1201 | + $STA_ID, |
|
| 1202 | + $cols_n_values |
|
| 1203 | + ); |
|
| 1204 | + } |
|
| 1205 | + } |
|
| 1206 | + } |
|
| 1207 | + // check if country being edited matches org option country, and if so, then update EE_Config with new settings |
|
| 1208 | + if (isset(EE_Registry::instance()->CFG->organization->CNT_ISO) |
|
| 1209 | + && $CNT_ISO == EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 1210 | + ) { |
|
| 1211 | + EE_Registry::instance()->CFG->currency = new EE_Currency_Config($CNT_ISO); |
|
| 1212 | + EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 1213 | + } |
|
| 1214 | + |
|
| 1215 | + if ($success !== false) { |
|
| 1216 | + EE_Error::add_success( |
|
| 1217 | + esc_html__('Country Settings updated successfully.', 'event_espresso') |
|
| 1218 | + ); |
|
| 1219 | + } |
|
| 1220 | + $this->_redirect_after_action( |
|
| 1221 | + $success, |
|
| 1222 | + '', |
|
| 1223 | + '', |
|
| 1224 | + array('action' => 'country_settings', 'country' => $CNT_ISO), |
|
| 1225 | + true |
|
| 1226 | + ); |
|
| 1227 | + } |
|
| 1228 | + |
|
| 1229 | + |
|
| 1230 | + /** |
|
| 1231 | + * form_form_field_label_wrap |
|
| 1232 | + * |
|
| 1233 | + * @access public |
|
| 1234 | + * @param string $label |
|
| 1235 | + * @return string |
|
| 1236 | + */ |
|
| 1237 | + public function country_form_field_label_wrap($label, $required_text) |
|
| 1238 | + { |
|
| 1239 | + return ' |
|
| 1240 | 1240 | <tr> |
| 1241 | 1241 | <th> |
| 1242 | 1242 | ' . $label . ' |
| 1243 | 1243 | </th>'; |
| 1244 | - } |
|
| 1245 | - |
|
| 1246 | - |
|
| 1247 | - /** |
|
| 1248 | - * form_form_field_input__wrap |
|
| 1249 | - * |
|
| 1250 | - * @access public |
|
| 1251 | - * @param string $label |
|
| 1252 | - * @return string |
|
| 1253 | - */ |
|
| 1254 | - public function country_form_field_input__wrap($input, $label) |
|
| 1255 | - { |
|
| 1256 | - return ' |
|
| 1244 | + } |
|
| 1245 | + |
|
| 1246 | + |
|
| 1247 | + /** |
|
| 1248 | + * form_form_field_input__wrap |
|
| 1249 | + * |
|
| 1250 | + * @access public |
|
| 1251 | + * @param string $label |
|
| 1252 | + * @return string |
|
| 1253 | + */ |
|
| 1254 | + public function country_form_field_input__wrap($input, $label) |
|
| 1255 | + { |
|
| 1256 | + return ' |
|
| 1257 | 1257 | <td class="general-settings-country-input-td"> |
| 1258 | 1258 | ' . $input . ' |
| 1259 | 1259 | </td> |
| 1260 | 1260 | </tr>'; |
| 1261 | - } |
|
| 1262 | - |
|
| 1263 | - |
|
| 1264 | - /** |
|
| 1265 | - * form_form_field_label_wrap |
|
| 1266 | - * |
|
| 1267 | - * @access public |
|
| 1268 | - * @param string $label |
|
| 1269 | - * @param string $required_text |
|
| 1270 | - * @return string |
|
| 1271 | - */ |
|
| 1272 | - public function state_form_field_label_wrap($label, $required_text) |
|
| 1273 | - { |
|
| 1274 | - return $required_text; |
|
| 1275 | - } |
|
| 1276 | - |
|
| 1277 | - |
|
| 1278 | - /** |
|
| 1279 | - * form_form_field_input__wrap |
|
| 1280 | - * |
|
| 1281 | - * @access public |
|
| 1282 | - * @param string $label |
|
| 1283 | - * @return string |
|
| 1284 | - */ |
|
| 1285 | - public function state_form_field_input__wrap($input, $label) |
|
| 1286 | - { |
|
| 1287 | - return ' |
|
| 1261 | + } |
|
| 1262 | + |
|
| 1263 | + |
|
| 1264 | + /** |
|
| 1265 | + * form_form_field_label_wrap |
|
| 1266 | + * |
|
| 1267 | + * @access public |
|
| 1268 | + * @param string $label |
|
| 1269 | + * @param string $required_text |
|
| 1270 | + * @return string |
|
| 1271 | + */ |
|
| 1272 | + public function state_form_field_label_wrap($label, $required_text) |
|
| 1273 | + { |
|
| 1274 | + return $required_text; |
|
| 1275 | + } |
|
| 1276 | + |
|
| 1277 | + |
|
| 1278 | + /** |
|
| 1279 | + * form_form_field_input__wrap |
|
| 1280 | + * |
|
| 1281 | + * @access public |
|
| 1282 | + * @param string $label |
|
| 1283 | + * @return string |
|
| 1284 | + */ |
|
| 1285 | + public function state_form_field_input__wrap($input, $label) |
|
| 1286 | + { |
|
| 1287 | + return ' |
|
| 1288 | 1288 | <td class="general-settings-country-state-input-td"> |
| 1289 | 1289 | ' . $input . ' |
| 1290 | 1290 | </td>'; |
| 1291 | - } |
|
| 1292 | - |
|
| 1293 | - |
|
| 1294 | - /***********/ |
|
| 1295 | - |
|
| 1296 | - |
|
| 1297 | - /** |
|
| 1298 | - * displays edit and view links for critical EE pages |
|
| 1299 | - * |
|
| 1300 | - * @access public |
|
| 1301 | - * @param int $ee_page_id |
|
| 1302 | - * @return string |
|
| 1303 | - */ |
|
| 1304 | - public static function edit_view_links($ee_page_id) |
|
| 1305 | - { |
|
| 1306 | - $links = '<a href="' |
|
| 1307 | - . add_query_arg( |
|
| 1308 | - array('post' => $ee_page_id, 'action' => 'edit'), |
|
| 1309 | - admin_url('post.php') |
|
| 1310 | - ) |
|
| 1311 | - . '" >' |
|
| 1312 | - . esc_html__('Edit', 'event_espresso') |
|
| 1313 | - . '</a>'; |
|
| 1314 | - $links .= ' | '; |
|
| 1315 | - $links .= '<a href="' . get_permalink($ee_page_id) . '" >' . esc_html__('View', 'event_espresso') . '</a>'; |
|
| 1316 | - |
|
| 1317 | - return $links; |
|
| 1318 | - } |
|
| 1319 | - |
|
| 1320 | - |
|
| 1321 | - /** |
|
| 1322 | - * displays page and shortcode status for critical EE pages |
|
| 1323 | - * |
|
| 1324 | - * @param WP page object $ee_page |
|
| 1325 | - * @return string |
|
| 1326 | - */ |
|
| 1327 | - public static function page_and_shortcode_status($ee_page, $shortcode) |
|
| 1328 | - { |
|
| 1329 | - |
|
| 1330 | - // page status |
|
| 1331 | - if (isset($ee_page->post_status) && $ee_page->post_status == 'publish') { |
|
| 1332 | - $pg_colour = 'green'; |
|
| 1333 | - $pg_status = sprintf(esc_html__('Page%sStatus%sOK', 'event_espresso'), ' ', ' '); |
|
| 1334 | - } else { |
|
| 1335 | - $pg_colour = 'red'; |
|
| 1336 | - $pg_status = sprintf(esc_html__('Page%sVisibility%sProblem', 'event_espresso'), ' ', ' '); |
|
| 1337 | - } |
|
| 1338 | - |
|
| 1339 | - // shortcode status |
|
| 1340 | - if (isset($ee_page->post_content) && strpos($ee_page->post_content, $shortcode) !== false) { |
|
| 1341 | - $sc_colour = 'green'; |
|
| 1342 | - $sc_status = sprintf(esc_html__('Shortcode%sOK', 'event_espresso'), ' '); |
|
| 1343 | - } else { |
|
| 1344 | - $sc_colour = 'red'; |
|
| 1345 | - $sc_status = sprintf(esc_html__('Shortcode%sProblem', 'event_espresso'), ' '); |
|
| 1346 | - } |
|
| 1347 | - |
|
| 1348 | - return '<span style="color:' . $pg_colour . '; margin-right:2em;"><strong>' |
|
| 1349 | - . $pg_status |
|
| 1350 | - . '</strong></span><span style="color:' . $sc_colour . '"><strong>' . $sc_status . '</strong></span>'; |
|
| 1351 | - } |
|
| 1352 | - |
|
| 1353 | - |
|
| 1354 | - /** |
|
| 1355 | - * generates a dropdown of all parent pages - copied from WP core |
|
| 1356 | - * |
|
| 1357 | - * @param int $default |
|
| 1358 | - * @param int $parent |
|
| 1359 | - * @param int $level |
|
| 1360 | - */ |
|
| 1361 | - public static function page_settings_dropdown($default = 0, $parent = 0, $level = 0) |
|
| 1362 | - { |
|
| 1363 | - global $wpdb; |
|
| 1364 | - $items = $wpdb->get_results( |
|
| 1365 | - $wpdb->prepare( |
|
| 1366 | - "SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status != 'trash' ORDER BY menu_order", |
|
| 1367 | - $parent |
|
| 1368 | - ) |
|
| 1369 | - ); |
|
| 1370 | - |
|
| 1371 | - if ($items) { |
|
| 1372 | - foreach ($items as $item) { |
|
| 1373 | - $pad = str_repeat(' ', $level * 3); |
|
| 1374 | - if ($item->ID == $default) { |
|
| 1375 | - $current = ' selected="selected"'; |
|
| 1376 | - } else { |
|
| 1377 | - $current = ''; |
|
| 1378 | - } |
|
| 1379 | - |
|
| 1380 | - echo "\n\t<option class='level-$level' value='$item->ID'$current>$pad " |
|
| 1381 | - . esc_html($item->post_title) |
|
| 1382 | - . "</option>"; |
|
| 1383 | - parent_dropdown($default, $item->ID, $level + 1); |
|
| 1384 | - } |
|
| 1385 | - } |
|
| 1386 | - } |
|
| 1387 | - |
|
| 1388 | - |
|
| 1389 | - /** |
|
| 1390 | - * Loads the scripts for the privacy settings form |
|
| 1391 | - */ |
|
| 1392 | - public function load_scripts_styles_privacy_settings() |
|
| 1393 | - { |
|
| 1394 | - $form_handler = $this->loader->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler'); |
|
| 1395 | - $form_handler->enqueueStylesAndScripts(); |
|
| 1396 | - } |
|
| 1397 | - |
|
| 1398 | - |
|
| 1399 | - /** |
|
| 1400 | - * display the privacy settings form |
|
| 1401 | - */ |
|
| 1402 | - public function privacySettings() |
|
| 1403 | - { |
|
| 1404 | - $this->_set_add_edit_form_tags('update_privacy_settings'); |
|
| 1405 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 1406 | - $form_handler = $this->loader->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler'); |
|
| 1407 | - $this->_template_args['admin_page_content'] = $form_handler->display(); |
|
| 1408 | - $this->display_admin_page_with_sidebar(); |
|
| 1409 | - } |
|
| 1410 | - |
|
| 1411 | - |
|
| 1412 | - /** |
|
| 1413 | - * Update the privacy settings from form data |
|
| 1414 | - * |
|
| 1415 | - * @throws EE_Error |
|
| 1416 | - */ |
|
| 1417 | - public function updatePrivacySettings() |
|
| 1418 | - { |
|
| 1419 | - $form_handler = $this->loader->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler'); |
|
| 1420 | - $success = $form_handler->process($this->get_request_data()); |
|
| 1421 | - $this->_redirect_after_action( |
|
| 1422 | - $success, |
|
| 1423 | - esc_html__('Registration Form Options', 'event_espresso'), |
|
| 1424 | - 'updated', |
|
| 1425 | - array('action' => 'privacy_settings') |
|
| 1426 | - ); |
|
| 1427 | - } |
|
| 1291 | + } |
|
| 1292 | + |
|
| 1293 | + |
|
| 1294 | + /***********/ |
|
| 1295 | + |
|
| 1296 | + |
|
| 1297 | + /** |
|
| 1298 | + * displays edit and view links for critical EE pages |
|
| 1299 | + * |
|
| 1300 | + * @access public |
|
| 1301 | + * @param int $ee_page_id |
|
| 1302 | + * @return string |
|
| 1303 | + */ |
|
| 1304 | + public static function edit_view_links($ee_page_id) |
|
| 1305 | + { |
|
| 1306 | + $links = '<a href="' |
|
| 1307 | + . add_query_arg( |
|
| 1308 | + array('post' => $ee_page_id, 'action' => 'edit'), |
|
| 1309 | + admin_url('post.php') |
|
| 1310 | + ) |
|
| 1311 | + . '" >' |
|
| 1312 | + . esc_html__('Edit', 'event_espresso') |
|
| 1313 | + . '</a>'; |
|
| 1314 | + $links .= ' | '; |
|
| 1315 | + $links .= '<a href="' . get_permalink($ee_page_id) . '" >' . esc_html__('View', 'event_espresso') . '</a>'; |
|
| 1316 | + |
|
| 1317 | + return $links; |
|
| 1318 | + } |
|
| 1319 | + |
|
| 1320 | + |
|
| 1321 | + /** |
|
| 1322 | + * displays page and shortcode status for critical EE pages |
|
| 1323 | + * |
|
| 1324 | + * @param WP page object $ee_page |
|
| 1325 | + * @return string |
|
| 1326 | + */ |
|
| 1327 | + public static function page_and_shortcode_status($ee_page, $shortcode) |
|
| 1328 | + { |
|
| 1329 | + |
|
| 1330 | + // page status |
|
| 1331 | + if (isset($ee_page->post_status) && $ee_page->post_status == 'publish') { |
|
| 1332 | + $pg_colour = 'green'; |
|
| 1333 | + $pg_status = sprintf(esc_html__('Page%sStatus%sOK', 'event_espresso'), ' ', ' '); |
|
| 1334 | + } else { |
|
| 1335 | + $pg_colour = 'red'; |
|
| 1336 | + $pg_status = sprintf(esc_html__('Page%sVisibility%sProblem', 'event_espresso'), ' ', ' '); |
|
| 1337 | + } |
|
| 1338 | + |
|
| 1339 | + // shortcode status |
|
| 1340 | + if (isset($ee_page->post_content) && strpos($ee_page->post_content, $shortcode) !== false) { |
|
| 1341 | + $sc_colour = 'green'; |
|
| 1342 | + $sc_status = sprintf(esc_html__('Shortcode%sOK', 'event_espresso'), ' '); |
|
| 1343 | + } else { |
|
| 1344 | + $sc_colour = 'red'; |
|
| 1345 | + $sc_status = sprintf(esc_html__('Shortcode%sProblem', 'event_espresso'), ' '); |
|
| 1346 | + } |
|
| 1347 | + |
|
| 1348 | + return '<span style="color:' . $pg_colour . '; margin-right:2em;"><strong>' |
|
| 1349 | + . $pg_status |
|
| 1350 | + . '</strong></span><span style="color:' . $sc_colour . '"><strong>' . $sc_status . '</strong></span>'; |
|
| 1351 | + } |
|
| 1352 | + |
|
| 1353 | + |
|
| 1354 | + /** |
|
| 1355 | + * generates a dropdown of all parent pages - copied from WP core |
|
| 1356 | + * |
|
| 1357 | + * @param int $default |
|
| 1358 | + * @param int $parent |
|
| 1359 | + * @param int $level |
|
| 1360 | + */ |
|
| 1361 | + public static function page_settings_dropdown($default = 0, $parent = 0, $level = 0) |
|
| 1362 | + { |
|
| 1363 | + global $wpdb; |
|
| 1364 | + $items = $wpdb->get_results( |
|
| 1365 | + $wpdb->prepare( |
|
| 1366 | + "SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status != 'trash' ORDER BY menu_order", |
|
| 1367 | + $parent |
|
| 1368 | + ) |
|
| 1369 | + ); |
|
| 1370 | + |
|
| 1371 | + if ($items) { |
|
| 1372 | + foreach ($items as $item) { |
|
| 1373 | + $pad = str_repeat(' ', $level * 3); |
|
| 1374 | + if ($item->ID == $default) { |
|
| 1375 | + $current = ' selected="selected"'; |
|
| 1376 | + } else { |
|
| 1377 | + $current = ''; |
|
| 1378 | + } |
|
| 1379 | + |
|
| 1380 | + echo "\n\t<option class='level-$level' value='$item->ID'$current>$pad " |
|
| 1381 | + . esc_html($item->post_title) |
|
| 1382 | + . "</option>"; |
|
| 1383 | + parent_dropdown($default, $item->ID, $level + 1); |
|
| 1384 | + } |
|
| 1385 | + } |
|
| 1386 | + } |
|
| 1387 | + |
|
| 1388 | + |
|
| 1389 | + /** |
|
| 1390 | + * Loads the scripts for the privacy settings form |
|
| 1391 | + */ |
|
| 1392 | + public function load_scripts_styles_privacy_settings() |
|
| 1393 | + { |
|
| 1394 | + $form_handler = $this->loader->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler'); |
|
| 1395 | + $form_handler->enqueueStylesAndScripts(); |
|
| 1396 | + } |
|
| 1397 | + |
|
| 1398 | + |
|
| 1399 | + /** |
|
| 1400 | + * display the privacy settings form |
|
| 1401 | + */ |
|
| 1402 | + public function privacySettings() |
|
| 1403 | + { |
|
| 1404 | + $this->_set_add_edit_form_tags('update_privacy_settings'); |
|
| 1405 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 1406 | + $form_handler = $this->loader->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler'); |
|
| 1407 | + $this->_template_args['admin_page_content'] = $form_handler->display(); |
|
| 1408 | + $this->display_admin_page_with_sidebar(); |
|
| 1409 | + } |
|
| 1410 | + |
|
| 1411 | + |
|
| 1412 | + /** |
|
| 1413 | + * Update the privacy settings from form data |
|
| 1414 | + * |
|
| 1415 | + * @throws EE_Error |
|
| 1416 | + */ |
|
| 1417 | + public function updatePrivacySettings() |
|
| 1418 | + { |
|
| 1419 | + $form_handler = $this->loader->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler'); |
|
| 1420 | + $success = $form_handler->process($this->get_request_data()); |
|
| 1421 | + $this->_redirect_after_action( |
|
| 1422 | + $success, |
|
| 1423 | + esc_html__('Registration Form Options', 'event_espresso'), |
|
| 1424 | + 'updated', |
|
| 1425 | + array('action' => 'privacy_settings') |
|
| 1426 | + ); |
|
| 1427 | + } |
|
| 1428 | 1428 | } |
@@ -291,12 +291,12 @@ discard block |
||
| 291 | 291 | wp_enqueue_script('thickbox'); |
| 292 | 292 | wp_register_script( |
| 293 | 293 | 'organization_settings', |
| 294 | - GEN_SET_ASSETS_URL . 'your_organization_settings.js', |
|
| 294 | + GEN_SET_ASSETS_URL.'your_organization_settings.js', |
|
| 295 | 295 | array('jquery', 'media-upload', 'thickbox'), |
| 296 | 296 | EVENT_ESPRESSO_VERSION, |
| 297 | 297 | true |
| 298 | 298 | ); |
| 299 | - wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 299 | + wp_register_style('organization-css', GEN_SET_ASSETS_URL.'organization.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 300 | 300 | wp_enqueue_script('organization_settings'); |
| 301 | 301 | wp_enqueue_style('organization-css'); |
| 302 | 302 | $confirm_image_delete = array( |
@@ -319,12 +319,12 @@ discard block |
||
| 319 | 319 | // scripts |
| 320 | 320 | wp_register_script( |
| 321 | 321 | 'gen_settings_countries', |
| 322 | - GEN_SET_ASSETS_URL . 'gen_settings_countries.js', |
|
| 322 | + GEN_SET_ASSETS_URL.'gen_settings_countries.js', |
|
| 323 | 323 | array('ee_admin_js'), |
| 324 | 324 | EVENT_ESPRESSO_VERSION, |
| 325 | 325 | true |
| 326 | 326 | ); |
| 327 | - wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 327 | + wp_register_style('organization-css', GEN_SET_ASSETS_URL.'organization.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 328 | 328 | wp_enqueue_script('gen_settings_countries'); |
| 329 | 329 | wp_enqueue_style('organization-css'); |
| 330 | 330 | } |
@@ -374,7 +374,7 @@ discard block |
||
| 374 | 374 | $this->_set_add_edit_form_tags('update_espresso_page_settings'); |
| 375 | 375 | $this->_set_publish_post_box_vars(null, false, false, null, false); |
| 376 | 376 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
| 377 | - GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php', |
|
| 377 | + GEN_SET_TEMPLATE_PATH.'espresso_page_settings.template.php', |
|
| 378 | 378 | $this->_template_args, |
| 379 | 379 | true |
| 380 | 380 | ); |
@@ -533,7 +533,7 @@ discard block |
||
| 533 | 533 | { |
| 534 | 534 | try { |
| 535 | 535 | $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance()); |
| 536 | - $admin_options_settings_form->process($this->_req_data[ $admin_options_settings_form->slug() ]); |
|
| 536 | + $admin_options_settings_form->process($this->_req_data[$admin_options_settings_form->slug()]); |
|
| 537 | 537 | EE_Registry::instance()->CFG->admin = apply_filters( |
| 538 | 538 | 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__CFG_admin', |
| 539 | 539 | EE_Registry::instance()->CFG->admin |
@@ -650,7 +650,7 @@ discard block |
||
| 650 | 650 | $this->_set_add_edit_form_tags('update_country_settings'); |
| 651 | 651 | $this->_set_publish_post_box_vars(null, false, false, null, false); |
| 652 | 652 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
| 653 | - GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php', |
|
| 653 | + GEN_SET_TEMPLATE_PATH.'countries_settings.template.php', |
|
| 654 | 654 | $this->_template_args, |
| 655 | 655 | true |
| 656 | 656 | ); |
@@ -678,7 +678,7 @@ discard block |
||
| 678 | 678 | $CNT_ISO = isset($this->_req_data['country']) |
| 679 | 679 | ? strtoupper(sanitize_text_field($this->_req_data['country'])) |
| 680 | 680 | : $CNT_ISO; |
| 681 | - if (! $CNT_ISO) { |
|
| 681 | + if ( ! $CNT_ISO) { |
|
| 682 | 682 | return ''; |
| 683 | 683 | } |
| 684 | 684 | |
@@ -694,59 +694,59 @@ discard block |
||
| 694 | 694 | $country_input_types = array( |
| 695 | 695 | 'CNT_active' => array( |
| 696 | 696 | 'type' => 'RADIO_BTN', |
| 697 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 697 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
| 698 | 698 | 'class' => '', |
| 699 | 699 | 'options' => $this->_yes_no_values, |
| 700 | 700 | 'use_desc_4_label' => true, |
| 701 | 701 | ), |
| 702 | 702 | 'CNT_ISO' => array( |
| 703 | 703 | 'type' => 'TEXT', |
| 704 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 704 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
| 705 | 705 | 'class' => 'small-text', |
| 706 | 706 | ), |
| 707 | 707 | 'CNT_ISO3' => array( |
| 708 | 708 | 'type' => 'TEXT', |
| 709 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 709 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
| 710 | 710 | 'class' => 'small-text', |
| 711 | 711 | ), |
| 712 | 712 | 'RGN_ID' => array( |
| 713 | 713 | 'type' => 'TEXT', |
| 714 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 714 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
| 715 | 715 | 'class' => 'small-text', |
| 716 | 716 | ), |
| 717 | 717 | 'CNT_name' => array( |
| 718 | 718 | 'type' => 'TEXT', |
| 719 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 719 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
| 720 | 720 | 'class' => 'regular-text', |
| 721 | 721 | ), |
| 722 | 722 | 'CNT_cur_code' => array( |
| 723 | 723 | 'type' => 'TEXT', |
| 724 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 724 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
| 725 | 725 | 'class' => 'small-text', |
| 726 | 726 | 'disabled' => $CNT_cur_disabled, |
| 727 | 727 | ), |
| 728 | 728 | 'CNT_cur_single' => array( |
| 729 | 729 | 'type' => 'TEXT', |
| 730 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 730 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
| 731 | 731 | 'class' => 'medium-text', |
| 732 | 732 | 'disabled' => $CNT_cur_disabled, |
| 733 | 733 | ), |
| 734 | 734 | 'CNT_cur_plural' => array( |
| 735 | 735 | 'type' => 'TEXT', |
| 736 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 736 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
| 737 | 737 | 'class' => 'medium-text', |
| 738 | 738 | 'disabled' => $CNT_cur_disabled, |
| 739 | 739 | ), |
| 740 | 740 | 'CNT_cur_sign' => array( |
| 741 | 741 | 'type' => 'TEXT', |
| 742 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 742 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
| 743 | 743 | 'class' => 'small-text', |
| 744 | 744 | 'htmlentities' => false, |
| 745 | 745 | 'disabled' => $CNT_cur_disabled, |
| 746 | 746 | ), |
| 747 | 747 | 'CNT_cur_sign_b4' => array( |
| 748 | 748 | 'type' => 'RADIO_BTN', |
| 749 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 749 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
| 750 | 750 | 'class' => '', |
| 751 | 751 | 'options' => $this->_yes_no_values, |
| 752 | 752 | 'use_desc_4_label' => true, |
@@ -754,7 +754,7 @@ discard block |
||
| 754 | 754 | ), |
| 755 | 755 | 'CNT_cur_dec_plc' => array( |
| 756 | 756 | 'type' => 'RADIO_BTN', |
| 757 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 757 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
| 758 | 758 | 'class' => '', |
| 759 | 759 | 'options' => array( |
| 760 | 760 | array('id' => 0, 'text' => ''), |
@@ -766,7 +766,7 @@ discard block |
||
| 766 | 766 | ), |
| 767 | 767 | 'CNT_cur_dec_mrk' => array( |
| 768 | 768 | 'type' => 'RADIO_BTN', |
| 769 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 769 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
| 770 | 770 | 'class' => '', |
| 771 | 771 | 'options' => array( |
| 772 | 772 | array( |
@@ -780,7 +780,7 @@ discard block |
||
| 780 | 780 | ), |
| 781 | 781 | 'CNT_cur_thsnds' => array( |
| 782 | 782 | 'type' => 'RADIO_BTN', |
| 783 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 783 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
| 784 | 784 | 'class' => '', |
| 785 | 785 | 'options' => array( |
| 786 | 786 | array( |
@@ -801,12 +801,12 @@ discard block |
||
| 801 | 801 | ), |
| 802 | 802 | 'CNT_tel_code' => array( |
| 803 | 803 | 'type' => 'TEXT', |
| 804 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 804 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
| 805 | 805 | 'class' => 'small-text', |
| 806 | 806 | ), |
| 807 | 807 | 'CNT_is_EU' => array( |
| 808 | 808 | 'type' => 'RADIO_BTN', |
| 809 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 809 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
| 810 | 810 | 'class' => '', |
| 811 | 811 | 'options' => $this->_yes_no_values, |
| 812 | 812 | 'use_desc_4_label' => true, |
@@ -817,7 +817,7 @@ discard block |
||
| 817 | 817 | $country_input_types |
| 818 | 818 | ); |
| 819 | 819 | $country_details_settings = EEH_Template::display_template( |
| 820 | - GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php', |
|
| 820 | + GEN_SET_TEMPLATE_PATH.'country_details_settings.template.php', |
|
| 821 | 821 | $this->_template_args, |
| 822 | 822 | true |
| 823 | 823 | ); |
@@ -855,7 +855,7 @@ discard block |
||
| 855 | 855 | $CNT_ISO = isset($this->_req_data['country']) |
| 856 | 856 | ? sanitize_text_field($this->_req_data['country']) |
| 857 | 857 | : $CNT_ISO; |
| 858 | - if (! $CNT_ISO) { |
|
| 858 | + if ( ! $CNT_ISO) { |
|
| 859 | 859 | return ''; |
| 860 | 860 | } |
| 861 | 861 | // for ajax |
@@ -885,22 +885,22 @@ discard block |
||
| 885 | 885 | $state_input_types = array( |
| 886 | 886 | 'STA_abbrev' => array( |
| 887 | 887 | 'type' => 'TEXT', |
| 888 | - 'input_name' => 'states[' . $STA_ID . ']', |
|
| 888 | + 'input_name' => 'states['.$STA_ID.']', |
|
| 889 | 889 | 'class' => 'mid-text', |
| 890 | 890 | ), |
| 891 | 891 | 'STA_name' => array( |
| 892 | 892 | 'type' => 'TEXT', |
| 893 | - 'input_name' => 'states[' . $STA_ID . ']', |
|
| 893 | + 'input_name' => 'states['.$STA_ID.']', |
|
| 894 | 894 | 'class' => 'regular-text', |
| 895 | 895 | ), |
| 896 | 896 | 'STA_active' => array( |
| 897 | 897 | 'type' => 'RADIO_BTN', |
| 898 | - 'input_name' => 'states[' . $STA_ID . ']', |
|
| 898 | + 'input_name' => 'states['.$STA_ID.']', |
|
| 899 | 899 | 'options' => $this->_yes_no_values, |
| 900 | 900 | 'use_desc_4_label' => true, |
| 901 | 901 | ), |
| 902 | 902 | ); |
| 903 | - $this->_template_args['states'][ $STA_ID ]['inputs'] = |
|
| 903 | + $this->_template_args['states'][$STA_ID]['inputs'] = |
|
| 904 | 904 | EE_Question_Form_Input::generate_question_form_inputs_for_object( |
| 905 | 905 | $state, |
| 906 | 906 | $state_input_types |
@@ -911,7 +911,7 @@ discard block |
||
| 911 | 911 | 'CNT_ISO' => $CNT_ISO, |
| 912 | 912 | 'STA_abbrev' => $state->abbrev(), |
| 913 | 913 | ); |
| 914 | - $this->_template_args['states'][ $STA_ID ]['delete_state_url'] = |
|
| 914 | + $this->_template_args['states'][$STA_ID]['delete_state_url'] = |
|
| 915 | 915 | EE_Admin_Page::add_query_args_and_nonce( |
| 916 | 916 | $query_args, |
| 917 | 917 | GEN_SET_ADMIN_URL |
@@ -928,7 +928,7 @@ discard block |
||
| 928 | 928 | ); |
| 929 | 929 | |
| 930 | 930 | $state_details_settings = EEH_Template::display_template( |
| 931 | - GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php', |
|
| 931 | + GEN_SET_TEMPLATE_PATH.'state_details_settings.template.php', |
|
| 932 | 932 | $this->_template_args, |
| 933 | 933 | true |
| 934 | 934 | ); |
@@ -967,7 +967,7 @@ discard block |
||
| 967 | 967 | $CNT_ISO = isset($this->_req_data['CNT_ISO']) |
| 968 | 968 | ? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO'])) |
| 969 | 969 | : false; |
| 970 | - if (! $CNT_ISO) { |
|
| 970 | + if ( ! $CNT_ISO) { |
|
| 971 | 971 | EE_Error::add_error( |
| 972 | 972 | esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
| 973 | 973 | __FILE__, |
@@ -979,7 +979,7 @@ discard block |
||
| 979 | 979 | $STA_abbrev = isset($this->_req_data['STA_abbrev']) |
| 980 | 980 | ? sanitize_text_field($this->_req_data['STA_abbrev']) |
| 981 | 981 | : false; |
| 982 | - if (! $STA_abbrev) { |
|
| 982 | + if ( ! $STA_abbrev) { |
|
| 983 | 983 | EE_Error::add_error( |
| 984 | 984 | esc_html__('No State ISO code or an invalid State ISO code was received.', 'event_espresso'), |
| 985 | 985 | __FILE__, |
@@ -991,7 +991,7 @@ discard block |
||
| 991 | 991 | $STA_name = isset($this->_req_data['STA_name']) |
| 992 | 992 | ? sanitize_text_field($this->_req_data['STA_name']) |
| 993 | 993 | : false; |
| 994 | - if (! $STA_name) { |
|
| 994 | + if ( ! $STA_name) { |
|
| 995 | 995 | EE_Error::add_error( |
| 996 | 996 | esc_html__('No State name or an invalid State name was received.', 'event_espresso'), |
| 997 | 997 | __FILE__, |
@@ -1043,7 +1043,7 @@ discard block |
||
| 1043 | 1043 | $STA_abbrev = isset($this->_req_data['STA_abbrev']) |
| 1044 | 1044 | ? sanitize_text_field($this->_req_data['STA_abbrev']) |
| 1045 | 1045 | : false; |
| 1046 | - if (! $STA_ID) { |
|
| 1046 | + if ( ! $STA_ID) { |
|
| 1047 | 1047 | EE_Error::add_error( |
| 1048 | 1048 | esc_html__('No State ID or an invalid State ID was received.', 'event_espresso'), |
| 1049 | 1049 | __FILE__, |
@@ -1095,7 +1095,7 @@ discard block |
||
| 1095 | 1095 | $CNT_ISO = isset($this->_req_data['country']) |
| 1096 | 1096 | ? strtoupper(sanitize_text_field($this->_req_data['country'])) |
| 1097 | 1097 | : false; |
| 1098 | - if (! $CNT_ISO) { |
|
| 1098 | + if ( ! $CNT_ISO) { |
|
| 1099 | 1099 | EE_Error::add_error( |
| 1100 | 1100 | esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
| 1101 | 1101 | __FILE__, |
@@ -1106,63 +1106,63 @@ discard block |
||
| 1106 | 1106 | return; |
| 1107 | 1107 | } |
| 1108 | 1108 | $cols_n_values = array(); |
| 1109 | - $cols_n_values['CNT_ISO3'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3']) |
|
| 1110 | - ? strtoupper(sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3'])) |
|
| 1109 | + $cols_n_values['CNT_ISO3'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_ISO3']) |
|
| 1110 | + ? strtoupper(sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_ISO3'])) |
|
| 1111 | 1111 | : false; |
| 1112 | - $cols_n_values['RGN_ID'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID']) |
|
| 1113 | - ? absint($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID']) |
|
| 1112 | + $cols_n_values['RGN_ID'] = isset($this->_req_data['cntry'][$CNT_ISO]['RGN_ID']) |
|
| 1113 | + ? absint($this->_req_data['cntry'][$CNT_ISO]['RGN_ID']) |
|
| 1114 | 1114 | : null; |
| 1115 | - $cols_n_values['CNT_name'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name']) |
|
| 1116 | - ? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name']) |
|
| 1115 | + $cols_n_values['CNT_name'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_name']) |
|
| 1116 | + ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_name']) |
|
| 1117 | 1117 | : null; |
| 1118 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code'])) { |
|
| 1118 | + if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_code'])) { |
|
| 1119 | 1119 | $cols_n_values['CNT_cur_code'] = strtoupper( |
| 1120 | - sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code']) |
|
| 1120 | + sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_code']) |
|
| 1121 | 1121 | ); |
| 1122 | 1122 | } |
| 1123 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single'])) { |
|
| 1123 | + if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_single'])) { |
|
| 1124 | 1124 | $cols_n_values['CNT_cur_single'] = sanitize_text_field( |
| 1125 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single'] |
|
| 1125 | + $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_single'] |
|
| 1126 | 1126 | ); |
| 1127 | 1127 | } |
| 1128 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural'])) { |
|
| 1128 | + if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_plural'])) { |
|
| 1129 | 1129 | $cols_n_values['CNT_cur_plural'] = sanitize_text_field( |
| 1130 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural'] |
|
| 1130 | + $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_plural'] |
|
| 1131 | 1131 | ); |
| 1132 | 1132 | } |
| 1133 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign'])) { |
|
| 1133 | + if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign'])) { |
|
| 1134 | 1134 | $cols_n_values['CNT_cur_sign'] = sanitize_text_field( |
| 1135 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign'] |
|
| 1135 | + $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign'] |
|
| 1136 | 1136 | ); |
| 1137 | 1137 | } |
| 1138 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4'])) { |
|
| 1138 | + if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign_b4'])) { |
|
| 1139 | 1139 | $cols_n_values['CNT_cur_sign_b4'] = absint( |
| 1140 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4'] |
|
| 1140 | + $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign_b4'] |
|
| 1141 | 1141 | ); |
| 1142 | 1142 | } |
| 1143 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc'])) { |
|
| 1143 | + if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_plc'])) { |
|
| 1144 | 1144 | $cols_n_values['CNT_cur_dec_plc'] = absint( |
| 1145 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc'] |
|
| 1145 | + $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_plc'] |
|
| 1146 | 1146 | ); |
| 1147 | 1147 | } |
| 1148 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk'])) { |
|
| 1148 | + if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_mrk'])) { |
|
| 1149 | 1149 | $cols_n_values['CNT_cur_dec_mrk'] = sanitize_text_field( |
| 1150 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk'] |
|
| 1150 | + $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_mrk'] |
|
| 1151 | 1151 | ); |
| 1152 | 1152 | } |
| 1153 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds'])) { |
|
| 1153 | + if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_thsnds'])) { |
|
| 1154 | 1154 | $cols_n_values['CNT_cur_thsnds'] = sanitize_text_field( |
| 1155 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds'] |
|
| 1155 | + $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_thsnds'] |
|
| 1156 | 1156 | ); |
| 1157 | 1157 | } |
| 1158 | - $cols_n_values['CNT_tel_code'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code']) |
|
| 1159 | - ? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code']) |
|
| 1158 | + $cols_n_values['CNT_tel_code'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_tel_code']) |
|
| 1159 | + ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_tel_code']) |
|
| 1160 | 1160 | : null; |
| 1161 | - $cols_n_values['CNT_is_EU'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU']) |
|
| 1162 | - ? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU']) |
|
| 1161 | + $cols_n_values['CNT_is_EU'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_is_EU']) |
|
| 1162 | + ? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_is_EU']) |
|
| 1163 | 1163 | : false; |
| 1164 | - $cols_n_values['CNT_active'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active']) |
|
| 1165 | - ? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active']) |
|
| 1164 | + $cols_n_values['CNT_active'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_active']) |
|
| 1165 | + ? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_active']) |
|
| 1166 | 1166 | : false; |
| 1167 | 1167 | // allow filtering of country data |
| 1168 | 1168 | $cols_n_values = apply_filters( |
@@ -1239,7 +1239,7 @@ discard block |
||
| 1239 | 1239 | return ' |
| 1240 | 1240 | <tr> |
| 1241 | 1241 | <th> |
| 1242 | - ' . $label . ' |
|
| 1242 | + ' . $label.' |
|
| 1243 | 1243 | </th>'; |
| 1244 | 1244 | } |
| 1245 | 1245 | |
@@ -1255,7 +1255,7 @@ discard block |
||
| 1255 | 1255 | { |
| 1256 | 1256 | return ' |
| 1257 | 1257 | <td class="general-settings-country-input-td"> |
| 1258 | - ' . $input . ' |
|
| 1258 | + ' . $input.' |
|
| 1259 | 1259 | </td> |
| 1260 | 1260 | </tr>'; |
| 1261 | 1261 | } |
@@ -1286,7 +1286,7 @@ discard block |
||
| 1286 | 1286 | { |
| 1287 | 1287 | return ' |
| 1288 | 1288 | <td class="general-settings-country-state-input-td"> |
| 1289 | - ' . $input . ' |
|
| 1289 | + ' . $input.' |
|
| 1290 | 1290 | </td>'; |
| 1291 | 1291 | } |
| 1292 | 1292 | |
@@ -1312,7 +1312,7 @@ discard block |
||
| 1312 | 1312 | . esc_html__('Edit', 'event_espresso') |
| 1313 | 1313 | . '</a>'; |
| 1314 | 1314 | $links .= ' | '; |
| 1315 | - $links .= '<a href="' . get_permalink($ee_page_id) . '" >' . esc_html__('View', 'event_espresso') . '</a>'; |
|
| 1315 | + $links .= '<a href="'.get_permalink($ee_page_id).'" >'.esc_html__('View', 'event_espresso').'</a>'; |
|
| 1316 | 1316 | |
| 1317 | 1317 | return $links; |
| 1318 | 1318 | } |
@@ -1345,9 +1345,9 @@ discard block |
||
| 1345 | 1345 | $sc_status = sprintf(esc_html__('Shortcode%sProblem', 'event_espresso'), ' '); |
| 1346 | 1346 | } |
| 1347 | 1347 | |
| 1348 | - return '<span style="color:' . $pg_colour . '; margin-right:2em;"><strong>' |
|
| 1348 | + return '<span style="color:'.$pg_colour.'; margin-right:2em;"><strong>' |
|
| 1349 | 1349 | . $pg_status |
| 1350 | - . '</strong></span><span style="color:' . $sc_colour . '"><strong>' . $sc_status . '</strong></span>'; |
|
| 1350 | + . '</strong></span><span style="color:'.$sc_colour.'"><strong>'.$sc_status.'</strong></span>'; |
|
| 1351 | 1351 | } |
| 1352 | 1352 | |
| 1353 | 1353 | |
@@ -11,8 +11,8 @@ discard block |
||
| 11 | 11 | /* @var EE_Question[] $all_questions */ |
| 12 | 12 | assert(isset($all_questions) && (empty($all_questions) || is_array($all_questions)));// list of unused questions |
| 13 | 13 | foreach ($all_questions as $unused_question) { |
| 14 | - assert($unused_question); |
|
| 15 | - assert($unused_question instanceof EE_Question); |
|
| 14 | + assert($unused_question); |
|
| 15 | + assert($unused_question instanceof EE_Question); |
|
| 16 | 16 | } |
| 17 | 17 | /* @var array $values . Array of arrays, where each sub-array contains 2 keys: 'id' (internal value) and 'name' (label for displaying) */ |
| 18 | 18 | assert(is_array($values)); |
@@ -31,8 +31,8 @@ discard block |
||
| 31 | 31 | <th> |
| 32 | 32 | <label for="QSG_name"> |
| 33 | 33 | <?php _e('Group Name', 'event_espresso'); ?><?php echo EEH_Template::get_help_tab_link( |
| 34 | - 'group_name_info' |
|
| 35 | - ); ?> |
|
| 34 | + 'group_name_info' |
|
| 35 | + ); ?> |
|
| 36 | 36 | </label> |
| 37 | 37 | </th> |
| 38 | 38 | <td> |
@@ -46,8 +46,8 @@ discard block |
||
| 46 | 46 | <th> |
| 47 | 47 | <label for="QSG_identifier"> |
| 48 | 48 | <?php _e('Group Identifier', 'event_espresso'); ?><?php echo EEH_Template::get_help_tab_link( |
| 49 | - 'group_identifier_info' |
|
| 50 | - ); ?> |
|
| 49 | + 'group_identifier_info' |
|
| 50 | + ); ?> |
|
| 51 | 51 | </label> |
| 52 | 52 | </th> |
| 53 | 53 | <td> |
@@ -66,8 +66,8 @@ discard block |
||
| 66 | 66 | <th> |
| 67 | 67 | <label for="QSG_desc"> |
| 68 | 68 | <?php _e('Description', 'event_espresso'); ?><?php echo EEH_Template::get_help_tab_link( |
| 69 | - 'group_description_info' |
|
| 70 | - ); ?> |
|
| 69 | + 'group_description_info' |
|
| 70 | + ); ?> |
|
| 71 | 71 | </label> |
| 72 | 72 | </th> |
| 73 | 73 | <td> |
@@ -80,8 +80,8 @@ discard block |
||
| 80 | 80 | <th> |
| 81 | 81 | <label for="QSG_order"> |
| 82 | 82 | <?php _e('Question Group Order', 'event_espresso'); ?><?php echo EEH_Template::get_help_tab_link( |
| 83 | - 'group_order_info' |
|
| 84 | - ); ?> |
|
| 83 | + 'group_order_info' |
|
| 84 | + ); ?> |
|
| 85 | 85 | </label> |
| 86 | 86 | </th> |
| 87 | 87 | <td> |
@@ -94,17 +94,17 @@ discard block |
||
| 94 | 94 | <th> |
| 95 | 95 | <label> |
| 96 | 96 | <?php _e('Show Name', 'event_espresso'); ?><?php echo EEH_Template::get_help_tab_link( |
| 97 | - 'show_group_name_info' |
|
| 98 | - ); ?> |
|
| 97 | + 'show_group_name_info' |
|
| 98 | + ); ?> |
|
| 99 | 99 | </label> |
| 100 | 100 | </th> |
| 101 | 101 | <td> |
| 102 | 102 | <label for="QSG_show_group_name"> |
| 103 | 103 | <?php echo EEH_Form_Fields::select_input( |
| 104 | - 'QSG_show_group_name', |
|
| 105 | - $values, |
|
| 106 | - $question_group->show_group_name() |
|
| 107 | - ); ?> |
|
| 104 | + 'QSG_show_group_name', |
|
| 105 | + $values, |
|
| 106 | + $question_group->show_group_name() |
|
| 107 | + ); ?> |
|
| 108 | 108 | <p class="description"><?php _e('Show Group Name on Registration Page?', 'event_espresso'); ?></p> |
| 109 | 109 | </label> |
| 110 | 110 | </td> |
@@ -114,20 +114,20 @@ discard block |
||
| 114 | 114 | <th> |
| 115 | 115 | <label> |
| 116 | 116 | <?php _e(' Show Description', 'event_espresso'); ?><?php echo EEH_Template::get_help_tab_link( |
| 117 | - 'show_group_description_info' |
|
| 118 | - ); ?> |
|
| 117 | + 'show_group_description_info' |
|
| 118 | + ); ?> |
|
| 119 | 119 | </label> |
| 120 | 120 | </th> |
| 121 | 121 | <td> |
| 122 | 122 | <label for="QSG_show_group_order"> |
| 123 | 123 | <?php echo EEH_Form_Fields::select_input( |
| 124 | - 'QSG_show_group_desc', |
|
| 125 | - $values, |
|
| 126 | - $question_group->show_group_desc() |
|
| 127 | - ); ?> |
|
| 124 | + 'QSG_show_group_desc', |
|
| 125 | + $values, |
|
| 126 | + $question_group->show_group_desc() |
|
| 127 | + ); ?> |
|
| 128 | 128 | <p class="description"><?php |
| 129 | - _e(' Show Group Description on Registration Page?', 'event_espresso'); |
|
| 130 | - ?></p> |
|
| 129 | + _e(' Show Group Description on Registration Page?', 'event_espresso'); |
|
| 130 | + ?></p> |
|
| 131 | 131 | </label> |
| 132 | 132 | <input type="hidden" name="QSG_system" value="<?php echo $question_group->system_group(); ?>"> |
| 133 | 133 | </td> |
@@ -143,82 +143,82 @@ discard block |
||
| 143 | 143 | <div class="form-table question-group-questions inside"> |
| 144 | 144 | <div class="padding"> |
| 145 | 145 | <p><span class="description"><?php |
| 146 | - _e( |
|
| 147 | - 'Select which questions should be shown in this group by checking or unchecking boxes. You can drag and drop questions to reorder them. Your changes will be updated when you save.', |
|
| 148 | - 'event_espresso' |
|
| 149 | - ); ?></span></p> |
|
| 146 | + _e( |
|
| 147 | + 'Select which questions should be shown in this group by checking or unchecking boxes. You can drag and drop questions to reorder them. Your changes will be updated when you save.', |
|
| 148 | + 'event_espresso' |
|
| 149 | + ); ?></span></p> |
|
| 150 | 150 | <div> |
| 151 | 151 | <ul class="question-list-sortable"> |
| 152 | 152 | <?php |
| 153 | - $question_order = 0; |
|
| 154 | - $question_group_questions = $question_group->questions(); |
|
| 155 | - foreach ($all_questions as $question_ID => $question) { |
|
| 156 | - if ($question instanceof EE_Question) { |
|
| 157 | - /*@var $question EE_Question*/ |
|
| 158 | - $checked = isset($question_group_questions[ $question_ID ]) ? ' checked="checked"' : ''; |
|
| 159 | - // disable questions from the personal information question group |
|
| 160 | - // is it required in the current question group? if so don't allow admins to remove it |
|
| 161 | - $disabled = in_array( |
|
| 162 | - $question->system_ID(), |
|
| 163 | - EEM_Question::instance()->required_system_questions_in_system_question_group( |
|
| 164 | - $QSG_system |
|
| 165 | - ) |
|
| 166 | - ) ? 'disabled="disabled"' : ''; |
|
| 167 | - // limit where system questions can appear |
|
| 168 | - if ($question->system_ID() && |
|
| 169 | - ! in_array( |
|
| 170 | - $question->system_ID(), |
|
| 171 | - EEM_Question::instance()->allowed_system_questions_in_system_question_group( |
|
| 172 | - $QSG_system |
|
| 173 | - ) |
|
| 174 | - ) |
|
| 175 | - ) { |
|
| 176 | - continue; // skip over system question not assigned to this group except for the address system group cause we want the address questions to display even if they aren't selected (but still not show the personal system questions). The third condition checks if we're displaying a non system question group and the question is a system question, then we skip because for non-system question groups we only want to show non-system questions. |
|
| 177 | - } |
|
| 178 | - ?> |
|
| 153 | + $question_order = 0; |
|
| 154 | + $question_group_questions = $question_group->questions(); |
|
| 155 | + foreach ($all_questions as $question_ID => $question) { |
|
| 156 | + if ($question instanceof EE_Question) { |
|
| 157 | + /*@var $question EE_Question*/ |
|
| 158 | + $checked = isset($question_group_questions[ $question_ID ]) ? ' checked="checked"' : ''; |
|
| 159 | + // disable questions from the personal information question group |
|
| 160 | + // is it required in the current question group? if so don't allow admins to remove it |
|
| 161 | + $disabled = in_array( |
|
| 162 | + $question->system_ID(), |
|
| 163 | + EEM_Question::instance()->required_system_questions_in_system_question_group( |
|
| 164 | + $QSG_system |
|
| 165 | + ) |
|
| 166 | + ) ? 'disabled="disabled"' : ''; |
|
| 167 | + // limit where system questions can appear |
|
| 168 | + if ($question->system_ID() && |
|
| 169 | + ! in_array( |
|
| 170 | + $question->system_ID(), |
|
| 171 | + EEM_Question::instance()->allowed_system_questions_in_system_question_group( |
|
| 172 | + $QSG_system |
|
| 173 | + ) |
|
| 174 | + ) |
|
| 175 | + ) { |
|
| 176 | + continue; // skip over system question not assigned to this group except for the address system group cause we want the address questions to display even if they aren't selected (but still not show the personal system questions). The third condition checks if we're displaying a non system question group and the question is a system question, then we skip because for non-system question groups we only want to show non-system questions. |
|
| 177 | + } |
|
| 178 | + ?> |
|
| 179 | 179 | <li class="ee-question-sortable"> |
| 180 | 180 | <label for="question-<?php echo $question_ID ?>"> |
| 181 | 181 | <input type="checkbox" name="questions[<?php echo $question_ID; ?>]" |
| 182 | 182 | id="question-<?php echo $question_ID; ?>" |
| 183 | 183 | value="<?php echo $question_ID; ?>"<?php echo $disabled; ?><?php echo $checked; ?>/> |
| 184 | 184 | <span class="question-text"><?php |
| 185 | - echo trim($question->display_text()) |
|
| 186 | - . (95 <= strlen(trim($question->display_text())) |
|
| 187 | - ? "…" |
|
| 188 | - : ''); |
|
| 189 | - ?> |
|
| 185 | + echo trim($question->display_text()) |
|
| 186 | + . (95 <= strlen(trim($question->display_text())) |
|
| 187 | + ? "…" |
|
| 188 | + : ''); |
|
| 189 | + ?> |
|
| 190 | 190 | </span> |
| 191 | 191 | <input class="question-group-QGQ_order" type="hidden" |
| 192 | 192 | name="question_orders[<?php echo $question_ID; ?>]" |
| 193 | 193 | value="<?php echo $question_order; ?>"> |
| 194 | 194 | </label> |
| 195 | 195 | <?php |
| 196 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 197 | - 'ee_edit_question', |
|
| 198 | - 'espresso_registration_form_edit_question', |
|
| 199 | - $question->ID() |
|
| 200 | - )) { |
|
| 201 | - $edit_query_args = array( |
|
| 202 | - 'action' => 'edit_question', |
|
| 203 | - 'QST_ID' => $question->ID(), |
|
| 204 | - ); |
|
| 205 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EE_FORMS_ADMIN_URL); |
|
| 196 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 197 | + 'ee_edit_question', |
|
| 198 | + 'espresso_registration_form_edit_question', |
|
| 199 | + $question->ID() |
|
| 200 | + )) { |
|
| 201 | + $edit_query_args = array( |
|
| 202 | + 'action' => 'edit_question', |
|
| 203 | + 'QST_ID' => $question->ID(), |
|
| 204 | + ); |
|
| 205 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EE_FORMS_ADMIN_URL); |
|
| 206 | 206 | |
| 207 | - echo '<a href="' . $edit_link . '" target="_blank" title="' . |
|
| 208 | - sprintf( |
|
| 209 | - esc_attr__('Edit %s', 'event_espresso'), |
|
| 210 | - $question->admin_label() |
|
| 211 | - ) |
|
| 212 | - . '"><span class="dashicons dashicons-edit"></span> |
|
| 207 | + echo '<a href="' . $edit_link . '" target="_blank" title="' . |
|
| 208 | + sprintf( |
|
| 209 | + esc_attr__('Edit %s', 'event_espresso'), |
|
| 210 | + $question->admin_label() |
|
| 211 | + ) |
|
| 212 | + . '"><span class="dashicons dashicons-edit"></span> |
|
| 213 | 213 | </a>'; |
| 214 | - } |
|
| 215 | - ?> |
|
| 214 | + } |
|
| 215 | + ?> |
|
| 216 | 216 | </li> |
| 217 | 217 | <?php |
| 218 | - $question_order++; |
|
| 219 | - } |
|
| 220 | - } |
|
| 221 | - ?> |
|
| 218 | + $question_order++; |
|
| 219 | + } |
|
| 220 | + } |
|
| 221 | + ?> |
|
| 222 | 222 | </ul> |
| 223 | 223 | </div> |
| 224 | 224 | </div> |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | assert($question_group); |
| 10 | 10 | assert($question_group instanceof EE_Question_Group); |
| 11 | 11 | /* @var EE_Question[] $all_questions */ |
| 12 | -assert(isset($all_questions) && (empty($all_questions) || is_array($all_questions)));// list of unused questions |
|
| 12 | +assert(isset($all_questions) && (empty($all_questions) || is_array($all_questions))); // list of unused questions |
|
| 13 | 13 | foreach ($all_questions as $unused_question) { |
| 14 | 14 | assert($unused_question); |
| 15 | 15 | assert($unused_question instanceof EE_Question); |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | <input id="QSG_identifier" name="QSG_identifier<?php echo $id; ?>" |
| 55 | 55 | value="<?php $question_group->f('QSG_identifier') ?>" type="text" |
| 56 | 56 | class="regular-text"<?php echo $disabled; ?>> |
| 57 | - <?php if (! empty($QSG_system)) { ?> |
|
| 57 | + <?php if ( ! empty($QSG_system)) { ?> |
|
| 58 | 58 | <p><span class="description" style="color:#D54E21;"> |
| 59 | 59 | <?php _e('System question group! This field cannot be changed.', 'event_espresso') ?> |
| 60 | 60 | </span><br/></p> |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | foreach ($all_questions as $question_ID => $question) { |
| 156 | 156 | if ($question instanceof EE_Question) { |
| 157 | 157 | /*@var $question EE_Question*/ |
| 158 | - $checked = isset($question_group_questions[ $question_ID ]) ? ' checked="checked"' : ''; |
|
| 158 | + $checked = isset($question_group_questions[$question_ID]) ? ' checked="checked"' : ''; |
|
| 159 | 159 | // disable questions from the personal information question group |
| 160 | 160 | // is it required in the current question group? if so don't allow admins to remove it |
| 161 | 161 | $disabled = in_array( |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | ); |
| 205 | 205 | $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EE_FORMS_ADMIN_URL); |
| 206 | 206 | |
| 207 | - echo '<a href="' . $edit_link . '" target="_blank" title="' . |
|
| 207 | + echo '<a href="'.$edit_link.'" target="_blank" title="'. |
|
| 208 | 208 | sprintf( |
| 209 | 209 | esc_attr__('Edit %s', 'event_espresso'), |
| 210 | 210 | $question->admin_label() |
@@ -18,8 +18,8 @@ discard block |
||
| 18 | 18 | if ($QST_system === 'country') { |
| 19 | 19 | echo EEH_HTML::div( |
| 20 | 20 | EEH_HTML::h4( |
| 21 | - '<span class="dashicons dashicons-info"></span>' . esc_html__('Did you know...', 'event_espresso') |
|
| 22 | - ) . |
|
| 21 | + '<span class="dashicons dashicons-info"></span>'.esc_html__('Did you know...', 'event_espresso') |
|
| 22 | + ). |
|
| 23 | 23 | EEH_HTML::p( |
| 24 | 24 | esc_html__( |
| 25 | 25 | 'If you add a State/Province Select input immediately after this Country Select input when building your registration form, then the State/Province Select input options will change to correspond with the choice made in this input. So for example, choosing "United States" in this Country Select input will populate the State/Province Select input with just the state options for the United States.', |
@@ -62,13 +62,13 @@ discard block |
||
| 62 | 62 | value="<?php $question->f('QST_admin_label') ?>"<?php echo $disabled_attr ?>/> |
| 63 | 63 | <input class="QST_order" type="hidden" id="QST_order<?php echo $id; ?>" |
| 64 | 64 | name="QST_order<?php echo $id; ?>" value="<?php echo $question->get('QST_order'); ?>"/> |
| 65 | - <?php if (! empty($QST_system)) { ?> |
|
| 65 | + <?php if ( ! empty($QST_system)) { ?> |
|
| 66 | 66 | <input type="hidden" id="QST_admin_label" name="QST_admin_label" |
| 67 | 67 | value="<?php echo $question->admin_label() ?>"/> |
| 68 | 68 | <?php } ?> |
| 69 | 69 | <br/> |
| 70 | 70 | <p class="description"> |
| 71 | - <?php if (! empty($QST_system)) { ?> |
|
| 71 | + <?php if ( ! empty($QST_system)) { ?> |
|
| 72 | 72 | <span class="description" style="color:#D54E21;"> |
| 73 | 73 | <?php esc_html_e('System question! This field cannot be changed.', 'event_espresso') ?> |
| 74 | 74 | </span> |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | <br/> |
| 97 | 97 | <p class="description"> |
| 98 | 98 | <?php |
| 99 | - if (! empty($QST_system)) { ?> |
|
| 99 | + if ( ! empty($QST_system)) { ?> |
|
| 100 | 100 | <span class="description" style="color:#D54E21;"> |
| 101 | 101 | <?php esc_html_e('System question! This field cannot be changed.', 'event_espresso') ?> |
| 102 | 102 | </span> |
@@ -124,16 +124,16 @@ discard block |
||
| 124 | 124 | |
| 125 | 125 | // Only display Confirm email for |
| 126 | 126 | if (empty($QST_system) |
| 127 | - || (! empty($QST_system) && $QST_system !== EEM_Attendee::system_question_email_confirm) |
|
| 127 | + || ( ! empty($QST_system) && $QST_system !== EEM_Attendee::system_question_email_confirm) |
|
| 128 | 128 | ) { |
| 129 | - unset($question_types[ EEM_Question::QST_type_email_confirm ]); |
|
| 129 | + unset($question_types[EEM_Question::QST_type_email_confirm]); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | echo EEH_Form_Fields::select_input( |
| 133 | - 'QST_type' . $id, |
|
| 133 | + 'QST_type'.$id, |
|
| 134 | 134 | $question_types, |
| 135 | 135 | $question->type(), |
| 136 | - 'id="QST_type' . $id . '"' . $disabled_attr |
|
| 136 | + 'id="QST_type'.$id.'"'.$disabled_attr |
|
| 137 | 137 | ); |
| 138 | 138 | if ($disabled) { ?> |
| 139 | 139 | <input type="hidden" id="QST_type" name="QST_type" value="<?php echo $question->type() ?>"/> |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | <?php |
| 234 | 234 | $count = 0; |
| 235 | 235 | $question_options = $question->options(); |
| 236 | - if (! empty($question_options)) { |
|
| 236 | + if ( ! empty($question_options)) { |
|
| 237 | 237 | foreach ($question_options as $option_id => $option) { |
| 238 | 238 | $disabled_attr = $has_answers || $option->get('QSO_system') ? ' disabled="disabled"' : ''; |
| 239 | 239 | ?> |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | value="<?php $option->f('QSO_desc') ?>"> |
| 257 | 257 | </td> |
| 258 | 258 | <td> |
| 259 | - <?php if (! $option->system()) { ?> |
|
| 259 | + <?php if ( ! $option->system()) { ?> |
|
| 260 | 260 | <span class="dashicons clickable dashicons-post-trash ee-icon-size-18 remove-option remove-item"></span> |
| 261 | 261 | <?php } ?> |
| 262 | 262 | <span class="dashicons dashicons-image-flip-vertical sortable-drag-handle ee-icon-size-18"></span> |
@@ -346,10 +346,10 @@ discard block |
||
| 346 | 346 | array('text' => esc_html__('Required', 'event_espresso'), 'id' => 1), |
| 347 | 347 | ); |
| 348 | 348 | echo EEH_Form_Fields::select_input( |
| 349 | - 'QST_required' . $id, |
|
| 349 | + 'QST_required'.$id, |
|
| 350 | 350 | $requiredOptions, |
| 351 | 351 | $question->required(), |
| 352 | - 'id="QST_required' . $id . '"' . $disabled_attr |
|
| 352 | + 'id="QST_required'.$id.'"'.$disabled_attr |
|
| 353 | 353 | ); |
| 354 | 354 | ?> |
| 355 | 355 | <p><span id="required_toggled_on" class="description" |
@@ -365,7 +365,7 @@ discard block |
||
| 365 | 365 | 'event_espresso' |
| 366 | 366 | ) ?> |
| 367 | 367 | </span></p> |
| 368 | - <?php if (! empty($disabled_attr) && in_array($QST_system, $system_required)) { ?> |
|
| 368 | + <?php if ( ! empty($disabled_attr) && in_array($QST_system, $system_required)) { ?> |
|
| 369 | 369 | <input type="hidden" id="QST_required" name="QST_required" value="1"/> |
| 370 | 370 | <p><span class="description" style="color:#D54E21;"> |
| 371 | 371 | <?php esc_html_e('System question! This field cannot be changed.', 'event_espresso') ?> |
@@ -19,32 +19,32 @@ discard block |
||
| 19 | 19 | $has_answers = $question->has_answers(); |
| 20 | 20 | |
| 21 | 21 | if ($QST_system === 'country') { |
| 22 | - echo EEH_HTML::div( |
|
| 23 | - EEH_HTML::h4( |
|
| 24 | - '<span class="dashicons dashicons-info"></span>' . esc_html__('Did you know...', 'event_espresso') |
|
| 25 | - ) . |
|
| 26 | - EEH_HTML::p( |
|
| 27 | - esc_html__( |
|
| 28 | - 'If you add a State/Province Select input immediately after this Country Select input when building your registration form, then the State/Province Select input options will change to correspond with the choice made in this input. So for example, choosing "United States" in this Country Select input will populate the State/Province Select input with just the state options for the United States.', |
|
| 29 | - 'event_espresso' |
|
| 30 | - ) |
|
| 31 | - ), |
|
| 32 | - '', |
|
| 33 | - 'ee-info-box' |
|
| 34 | - ); |
|
| 22 | + echo EEH_HTML::div( |
|
| 23 | + EEH_HTML::h4( |
|
| 24 | + '<span class="dashicons dashicons-info"></span>' . esc_html__('Did you know...', 'event_espresso') |
|
| 25 | + ) . |
|
| 26 | + EEH_HTML::p( |
|
| 27 | + esc_html__( |
|
| 28 | + 'If you add a State/Province Select input immediately after this Country Select input when building your registration form, then the State/Province Select input options will change to correspond with the choice made in this input. So for example, choosing "United States" in this Country Select input will populate the State/Province Select input with just the state options for the United States.', |
|
| 29 | + 'event_espresso' |
|
| 30 | + ) |
|
| 31 | + ), |
|
| 32 | + '', |
|
| 33 | + 'ee-info-box' |
|
| 34 | + ); |
|
| 35 | 35 | } |
| 36 | 36 | ?> |
| 37 | 37 | |
| 38 | 38 | <?php |
| 39 | - do_action('AHEE__questions_main_meta_box__template__inner_admin_page_content', $question); |
|
| 39 | + do_action('AHEE__questions_main_meta_box__template__inner_admin_page_content', $question); |
|
| 40 | 40 | ?> |
| 41 | 41 | |
| 42 | 42 | <div class="padding"> |
| 43 | 43 | <table class="form-table"> |
| 44 | 44 | <tbody> |
| 45 | 45 | <?php |
| 46 | - do_action('AHEE__questions_main_meta_box__template__before_table_form_table', $question); |
|
| 47 | - ?> |
|
| 46 | + do_action('AHEE__questions_main_meta_box__template__before_table_form_table', $question); |
|
| 47 | + ?> |
|
| 48 | 48 | <tr> |
| 49 | 49 | <th> |
| 50 | 50 | <label for="QST_display_text"><?php echo $fields['QST_display_text']->get_nicename(); ?></label> |
@@ -64,9 +64,9 @@ discard block |
||
| 64 | 64 | </th> |
| 65 | 65 | <td> |
| 66 | 66 | <?php |
| 67 | - $disabled_attr = ! empty($QST_system) ? ' disabled="disabled"' : ''; |
|
| 68 | - $id = ! empty($QST_system) ? '_disabled' : ''; |
|
| 69 | - ?> |
|
| 67 | + $disabled_attr = ! empty($QST_system) ? ' disabled="disabled"' : ''; |
|
| 68 | + $id = ! empty($QST_system) ? '_disabled' : ''; |
|
| 69 | + ?> |
|
| 70 | 70 | <input type="text" class="regular-text" id="QST_admin_label<?php echo $id ?>" |
| 71 | 71 | name="QST_admin_label<?php echo $id ?>" |
| 72 | 72 | value="<?php $question->f('QST_admin_label') ?>"<?php echo $disabled_attr ?>/> |
@@ -95,18 +95,18 @@ discard block |
||
| 95 | 95 | </th> |
| 96 | 96 | <td> |
| 97 | 97 | <?php |
| 98 | - $disabled_attr = ! empty($QST_system) ? ' disabled="disabled"' : ''; |
|
| 99 | - $id = ! empty($QST_system) ? '_disabled' : ''; |
|
| 100 | - $admin_only = $question->get('QST_admin_only'); |
|
| 101 | - $checked = ! empty($admin_only) ? ' checked="checked"' : ''; |
|
| 102 | - ?> |
|
| 98 | + $disabled_attr = ! empty($QST_system) ? ' disabled="disabled"' : ''; |
|
| 99 | + $id = ! empty($QST_system) ? '_disabled' : ''; |
|
| 100 | + $admin_only = $question->get('QST_admin_only'); |
|
| 101 | + $checked = ! empty($admin_only) ? ' checked="checked"' : ''; |
|
| 102 | + ?> |
|
| 103 | 103 | <input class="QST_admin_only" type="checkbox" id="QST_admin_only<?php echo $id; ?>" |
| 104 | 104 | name="QST_admin_only<?php echo $id; ?>" value="1"<?php echo $disabled_attr; |
| 105 | - echo $checked; ?>/> |
|
| 105 | + echo $checked; ?>/> |
|
| 106 | 106 | <br/> |
| 107 | 107 | <p class="description"> |
| 108 | 108 | <?php |
| 109 | - if (! empty($QST_system)) { ?> |
|
| 109 | + if (! empty($QST_system)) { ?> |
|
| 110 | 110 | <span class="description" style="color:#D54E21;"> |
| 111 | 111 | <?php esc_html_e('System question! This field cannot be changed.', 'event_espresso') ?> |
| 112 | 112 | </span> |
@@ -123,39 +123,39 @@ discard block |
||
| 123 | 123 | </th> |
| 124 | 124 | <td> |
| 125 | 125 | <?php |
| 126 | - $disabled = ! empty($QST_system) && $QST_system !== EEM_Attendee::system_question_phone; |
|
| 127 | - if ($disabled) { |
|
| 128 | - $disabled_attr = 'disabled="disabled"'; |
|
| 129 | - $id = '_disabled'; |
|
| 130 | - } else { |
|
| 131 | - $disabled_attr = ''; |
|
| 132 | - $id = ''; |
|
| 133 | - } |
|
| 126 | + $disabled = ! empty($QST_system) && $QST_system !== EEM_Attendee::system_question_phone; |
|
| 127 | + if ($disabled) { |
|
| 128 | + $disabled_attr = 'disabled="disabled"'; |
|
| 129 | + $id = '_disabled'; |
|
| 130 | + } else { |
|
| 131 | + $disabled_attr = ''; |
|
| 132 | + $id = ''; |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - // Only display Confirm email for |
|
| 136 | - if (empty($QST_system) |
|
| 137 | - || (! empty($QST_system) && $QST_system !== EEM_Attendee::system_question_email_confirm) |
|
| 138 | - ) { |
|
| 139 | - unset($question_types[ EEM_Question::QST_type_email_confirm ]); |
|
| 140 | - } |
|
| 135 | + // Only display Confirm email for |
|
| 136 | + if (empty($QST_system) |
|
| 137 | + || (! empty($QST_system) && $QST_system !== EEM_Attendee::system_question_email_confirm) |
|
| 138 | + ) { |
|
| 139 | + unset($question_types[ EEM_Question::QST_type_email_confirm ]); |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - echo EEH_Form_Fields::select_input( |
|
| 143 | - 'QST_type' . $id, |
|
| 144 | - $question_types, |
|
| 145 | - $question->type(), |
|
| 146 | - 'id="QST_type' . $id . '"' . $disabled_attr |
|
| 147 | - ); |
|
| 148 | - if ($disabled) { ?> |
|
| 142 | + echo EEH_Form_Fields::select_input( |
|
| 143 | + 'QST_type' . $id, |
|
| 144 | + $question_types, |
|
| 145 | + $question->type(), |
|
| 146 | + 'id="QST_type' . $id . '"' . $disabled_attr |
|
| 147 | + ); |
|
| 148 | + if ($disabled) { ?> |
|
| 149 | 149 | <input type="hidden" id="QST_type" name="QST_type" value="<?php echo $question->type() ?>"/> |
| 150 | 150 | <?php |
| 151 | - $explanatory_text = esc_html__('System question! This field cannot be changed.', 'event_espresso'); |
|
| 152 | - } else { |
|
| 153 | - $explanatory_text = esc_html__( |
|
| 154 | - 'Because there are currently answers for this question in the database, your options to change the question type have been limited to similar question-types.', |
|
| 155 | - 'event_espresso' |
|
| 156 | - ); |
|
| 157 | - } |
|
| 158 | - if ($disabled || $has_answers) { ?> |
|
| 151 | + $explanatory_text = esc_html__('System question! This field cannot be changed.', 'event_espresso'); |
|
| 152 | + } else { |
|
| 153 | + $explanatory_text = esc_html__( |
|
| 154 | + 'Because there are currently answers for this question in the database, your options to change the question type have been limited to similar question-types.', |
|
| 155 | + 'event_espresso' |
|
| 156 | + ); |
|
| 157 | + } |
|
| 158 | + if ($disabled || $has_answers) { ?> |
|
| 159 | 159 | <p><span class="description" style="color:#D54E21;"> |
| 160 | 160 | <?php echo $explanatory_text; ?> |
| 161 | 161 | </span></p> |
@@ -173,25 +173,25 @@ discard block |
||
| 173 | 173 | </th> |
| 174 | 174 | <td> |
| 175 | 175 | <input id="QST_max" name="QST_max" type="number" <?php echo $max_max === EE_INF ? '' |
| 176 | - : "max='$max_max'"; ?> value="<?php $question->f('QST_max'); ?>" min="1"> |
|
| 176 | + : "max='$max_max'"; ?> value="<?php $question->f('QST_max'); ?>" min="1"> |
|
| 177 | 177 | <p> |
| 178 | 178 | <span class="description"> |
| 179 | 179 | <?php esc_html_e( |
| 180 | - 'Maximum number of characters allowed when answering this question', |
|
| 181 | - 'event_espresso' |
|
| 182 | - ); ?> |
|
| 180 | + 'Maximum number of characters allowed when answering this question', |
|
| 181 | + 'event_espresso' |
|
| 182 | + ); ?> |
|
| 183 | 183 | </span> |
| 184 | 184 | </p> |
| 185 | 185 | <?php if ($QST_system) { ?> |
| 186 | 186 | <p> |
| 187 | 187 | <span class="description" style="color:#D54E21;"> |
| 188 | 188 | <?php printf( |
| 189 | - esc_html__( |
|
| 190 | - 'System question! The maximum number of characters that can be used for this question is %1$s', |
|
| 191 | - 'event_espresso' |
|
| 192 | - ), |
|
| 193 | - $max_max |
|
| 194 | - ); ?> |
|
| 189 | + esc_html__( |
|
| 190 | + 'System question! The maximum number of characters that can be used for this question is %1$s', |
|
| 191 | + 'event_espresso' |
|
| 192 | + ), |
|
| 193 | + $max_max |
|
| 194 | + ); ?> |
|
| 195 | 195 | </span> |
| 196 | 196 | </p> |
| 197 | 197 | <?php } ?> |
@@ -213,9 +213,9 @@ discard block |
||
| 213 | 213 | </th> |
| 214 | 214 | <th class="option-desc-header"> |
| 215 | 215 | <?php esc_html_e( |
| 216 | - 'Description (optional, only shown on registration form)', |
|
| 217 | - 'event_espresso' |
|
| 218 | - ) ?> |
|
| 216 | + 'Description (optional, only shown on registration form)', |
|
| 217 | + 'event_espresso' |
|
| 218 | + ) ?> |
|
| 219 | 219 | </th> |
| 220 | 220 | <th> |
| 221 | 221 | </th> |
@@ -241,12 +241,12 @@ discard block |
||
| 241 | 241 | </tr> |
| 242 | 242 | |
| 243 | 243 | <?php |
| 244 | - $count = 0; |
|
| 245 | - $question_options = $question->options(); |
|
| 246 | - if (! empty($question_options)) { |
|
| 247 | - foreach ($question_options as $option_id => $option) { |
|
| 248 | - $disabled_attr = $has_answers || $option->get('QSO_system') ? ' disabled="disabled"' : ''; |
|
| 249 | - ?> |
|
| 244 | + $count = 0; |
|
| 245 | + $question_options = $question->options(); |
|
| 246 | + if (! empty($question_options)) { |
|
| 247 | + foreach ($question_options as $option_id => $option) { |
|
| 248 | + $disabled_attr = $has_answers || $option->get('QSO_system') ? ' disabled="disabled"' : ''; |
|
| 249 | + ?> |
|
| 250 | 250 | <tr class="question-option ee-options-sortable"> |
| 251 | 251 | <td class="option-value-cell"> |
| 252 | 252 | <input type="hidden" class="QSO_order" |
@@ -272,21 +272,21 @@ discard block |
||
| 272 | 272 | <span class="dashicons dashicons-image-flip-vertical sortable-drag-handle ee-icon-size-18"></span> |
| 273 | 273 | </td> |
| 274 | 274 | <?php |
| 275 | - echo EEH_Form_Fields::hidden_input( |
|
| 276 | - "question_options[{$count}][QST_ID])", |
|
| 277 | - $option->question_ID() |
|
| 278 | - ); |
|
| 279 | - echo EEH_Form_Fields::hidden_input( |
|
| 280 | - "question_options[{$count}][QSO_ID])", |
|
| 281 | - $option->ID() |
|
| 282 | - ); |
|
| 283 | - $count++; |
|
| 284 | - ?> |
|
| 275 | + echo EEH_Form_Fields::hidden_input( |
|
| 276 | + "question_options[{$count}][QST_ID])", |
|
| 277 | + $option->question_ID() |
|
| 278 | + ); |
|
| 279 | + echo EEH_Form_Fields::hidden_input( |
|
| 280 | + "question_options[{$count}][QSO_ID])", |
|
| 281 | + $option->ID() |
|
| 282 | + ); |
|
| 283 | + $count++; |
|
| 284 | + ?> |
|
| 285 | 285 | </tr> |
| 286 | 286 | <?php |
| 287 | - } |
|
| 288 | - } else { |
|
| 289 | - ?> |
|
| 287 | + } |
|
| 288 | + } else { |
|
| 289 | + ?> |
|
| 290 | 290 | <tr class="question-option ee-options-sortable"> |
| 291 | 291 | <td class="option-value-cell"> |
| 292 | 292 | <input type="hidden" class="QSO_order" name="question_options[0][QSO_order]" value="0"/> |
@@ -299,19 +299,19 @@ discard block |
||
| 299 | 299 | </td> |
| 300 | 300 | <td> |
| 301 | 301 | <?php |
| 302 | - echo EEH_Form_Fields::hidden_input("question_options_count", $count); |
|
| 303 | - ?> |
|
| 302 | + echo EEH_Form_Fields::hidden_input("question_options_count", $count); |
|
| 303 | + ?> |
|
| 304 | 304 | </td> |
| 305 | 305 | </tr> |
| 306 | 306 | <?php |
| 307 | - } |
|
| 308 | - ?> |
|
| 307 | + } |
|
| 308 | + ?> |
|
| 309 | 309 | <tr style="display:none"> |
| 310 | 310 | <td colspan="3"> |
| 311 | 311 | <?php echo EEH_Form_Fields::hidden_input( |
| 312 | - "question_options_count", |
|
| 313 | - $count |
|
| 314 | - ); ?></td> |
|
| 312 | + "question_options_count", |
|
| 313 | + $count |
|
| 314 | + ); ?></td> |
|
| 315 | 315 | </tr> |
| 316 | 316 | </tbody> |
| 317 | 317 | </table> |
@@ -322,16 +322,16 @@ discard block |
||
| 322 | 322 | |
| 323 | 323 | <p class="description"> |
| 324 | 324 | <?php esc_html_e( |
| 325 | - 'Answer Options are the choices that you give people to select from for RADIO_BTN, CHECKBOX or DROPDOWN questions. The Value is a simple key that will be saved to the database and the description is optional. Note that values CANNOT contain any HTML, but descriptions can.', |
|
| 326 | - 'event_espresso' |
|
| 327 | - ) ?> |
|
| 325 | + 'Answer Options are the choices that you give people to select from for RADIO_BTN, CHECKBOX or DROPDOWN questions. The Value is a simple key that will be saved to the database and the description is optional. Note that values CANNOT contain any HTML, but descriptions can.', |
|
| 326 | + 'event_espresso' |
|
| 327 | + ) ?> |
|
| 328 | 328 | </p> |
| 329 | 329 | <?php if ($has_answers) : ?> |
| 330 | 330 | <p class="description" style="color:#D54E21;"> |
| 331 | 331 | <?php esc_html_e( |
| 332 | - 'Answer values that are uneditable are this way because there are registrations in the database that have answers for this question. If you need to correct a mistake, or edit an existing option value, then trash the existing one and create a new option with the changes. This will ensure that the existing registrations that chose the original answer will preserve that answer.', |
|
| 333 | - 'event_espresso' |
|
| 334 | - ); ?> |
|
| 332 | + 'Answer values that are uneditable are this way because there are registrations in the database that have answers for this question. If you need to correct a mistake, or edit an existing option value, then trash the existing one and create a new option with the changes. This will ensure that the existing registrations that chose the original answer will preserve that answer.', |
|
| 333 | + 'event_espresso' |
|
| 334 | + ); ?> |
|
| 335 | 335 | </p> |
| 336 | 336 | |
| 337 | 337 | <?php endif; ?> |
@@ -345,35 +345,35 @@ discard block |
||
| 345 | 345 | </th> |
| 346 | 346 | <td> |
| 347 | 347 | <?php |
| 348 | - $system_required = array('fname', 'email'); |
|
| 349 | - $disabled_attr = in_array($QST_system, $system_required) ? ' disabled="disabled"' : ''; |
|
| 350 | - $required_on = $question->get('QST_admin_only'); |
|
| 351 | - $show_required_msg = $required_on ? '' : ' display:none;'; |
|
| 352 | - $disabled_attr = $required_on || ! empty($disabled_attr) ? ' disabled="disabled"' : ''; |
|
| 353 | - $id = ! empty($disabled_attr) && in_array($QST_system, $system_required) ? '_disabled' : ''; |
|
| 354 | - $requiredOptions = array( |
|
| 355 | - array('text' => esc_html__('Optional', 'event_espresso'), 'id' => 0), |
|
| 356 | - array('text' => esc_html__('Required', 'event_espresso'), 'id' => 1), |
|
| 357 | - ); |
|
| 358 | - echo EEH_Form_Fields::select_input( |
|
| 359 | - 'QST_required' . $id, |
|
| 360 | - $requiredOptions, |
|
| 361 | - $question->required(), |
|
| 362 | - 'id="QST_required' . $id . '"' . $disabled_attr |
|
| 363 | - ); |
|
| 364 | - ?> |
|
| 348 | + $system_required = array('fname', 'email'); |
|
| 349 | + $disabled_attr = in_array($QST_system, $system_required) ? ' disabled="disabled"' : ''; |
|
| 350 | + $required_on = $question->get('QST_admin_only'); |
|
| 351 | + $show_required_msg = $required_on ? '' : ' display:none;'; |
|
| 352 | + $disabled_attr = $required_on || ! empty($disabled_attr) ? ' disabled="disabled"' : ''; |
|
| 353 | + $id = ! empty($disabled_attr) && in_array($QST_system, $system_required) ? '_disabled' : ''; |
|
| 354 | + $requiredOptions = array( |
|
| 355 | + array('text' => esc_html__('Optional', 'event_espresso'), 'id' => 0), |
|
| 356 | + array('text' => esc_html__('Required', 'event_espresso'), 'id' => 1), |
|
| 357 | + ); |
|
| 358 | + echo EEH_Form_Fields::select_input( |
|
| 359 | + 'QST_required' . $id, |
|
| 360 | + $requiredOptions, |
|
| 361 | + $question->required(), |
|
| 362 | + 'id="QST_required' . $id . '"' . $disabled_attr |
|
| 363 | + ); |
|
| 364 | + ?> |
|
| 365 | 365 | <p><span id="required_toggled_on" class="description" |
| 366 | 366 | style="color:#D54E21;<?php echo $show_required_msg; ?>"> |
| 367 | 367 | <?php esc_html_e( |
| 368 | - 'Required is set to optional, and this field is disabled, because the question is Admin-Only.', |
|
| 369 | - 'event_espresso' |
|
| 370 | - ) ?> |
|
| 368 | + 'Required is set to optional, and this field is disabled, because the question is Admin-Only.', |
|
| 369 | + 'event_espresso' |
|
| 370 | + ) ?> |
|
| 371 | 371 | </span></p> |
| 372 | 372 | <p><span id="required_toggled_off" class="description" style="color:#D54E21; display: none;"> |
| 373 | 373 | <?php esc_html_e( |
| 374 | - 'Required option field is no longer disabled because the question is not Admin-Only', |
|
| 375 | - 'event_espresso' |
|
| 376 | - ) ?> |
|
| 374 | + 'Required option field is no longer disabled because the question is not Admin-Only', |
|
| 375 | + 'event_espresso' |
|
| 376 | + ) ?> |
|
| 377 | 377 | </span></p> |
| 378 | 378 | <?php if (! empty($disabled_attr) && in_array($QST_system, $system_required)) { ?> |
| 379 | 379 | <input type="hidden" id="QST_required" name="QST_required" value="1"/> |
@@ -389,9 +389,9 @@ discard block |
||
| 389 | 389 | <th> |
| 390 | 390 | <label for="QST_required_text"> |
| 391 | 391 | <?php esc_html_e( |
| 392 | - 'Required Text', |
|
| 393 | - 'event_espresso' |
|
| 394 | - ); ?></label> <?php echo EEH_Template::get_help_tab_link('required_text_info'); ?> |
|
| 392 | + 'Required Text', |
|
| 393 | + 'event_espresso' |
|
| 394 | + ); ?></label> <?php echo EEH_Template::get_help_tab_link('required_text_info'); ?> |
|
| 395 | 395 | </th> |
| 396 | 396 | <td> |
| 397 | 397 | <input type="text" maxlength="100" class="regular-text" id="QST_required_text" name="QST_required_text" |
@@ -400,8 +400,8 @@ discard block |
||
| 400 | 400 | </td> |
| 401 | 401 | </tr> |
| 402 | 402 | <?php |
| 403 | - do_action('AHEE__questions_main_meta_box__template__after_table_form_table', $question); |
|
| 404 | - ?> |
|
| 403 | + do_action('AHEE__questions_main_meta_box__template__after_table_form_table', $question); |
|
| 404 | + ?> |
|
| 405 | 405 | </tbody> |
| 406 | 406 | </table> |
| 407 | 407 | |
@@ -409,5 +409,5 @@ discard block |
||
| 409 | 409 | </div> |
| 410 | 410 | |
| 411 | 411 | <?php |
| 412 | - do_action('AHEE__questions_main_meta_box__template__after_admin_page_content', $question); |
|
| 412 | + do_action('AHEE__questions_main_meta_box__template__after_admin_page_content', $question); |
|
| 413 | 413 | |