@@ -13,1095 +13,1095 @@ |
||
| 13 | 13 | class EED_Messages extends EED_Module |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * This holds the EE_messages controller |
|
| 18 | - * |
|
| 19 | - * @deprecated 4.9.0 |
|
| 20 | - * @var EE_messages $_EEMSG |
|
| 21 | - */ |
|
| 22 | - protected static $_EEMSG; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @type EE_Message_Resource_Manager $_message_resource_manager |
|
| 26 | - */ |
|
| 27 | - protected static $_message_resource_manager; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * This holds the EE_Messages_Processor business class. |
|
| 31 | - * |
|
| 32 | - * @type EE_Messages_Processor |
|
| 33 | - */ |
|
| 34 | - protected static $_MSG_PROCESSOR; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * holds all the paths for various messages components. |
|
| 38 | - * Utilized by autoloader registry |
|
| 39 | - * |
|
| 40 | - * @var array |
|
| 41 | - */ |
|
| 42 | - protected static $_MSG_PATHS; |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * This will hold an array of messages template packs that are registered in the messages system. |
|
| 47 | - * Format is: |
|
| 48 | - * array( |
|
| 49 | - * 'template_pack_dbref' => EE_Messages_Template_Pack (instance) |
|
| 50 | - * ) |
|
| 51 | - * |
|
| 52 | - * @var EE_Messages_Template_Pack[] |
|
| 53 | - */ |
|
| 54 | - protected static $_TMP_PACKS = array(); |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @return EED_Messages |
|
| 59 | - */ |
|
| 60 | - public static function instance() |
|
| 61 | - { |
|
| 62 | - return parent::get_instance(__CLASS__); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 68 | - * |
|
| 69 | - * @since 4.5.0 |
|
| 70 | - * @return void |
|
| 71 | - */ |
|
| 72 | - public static function set_hooks() |
|
| 73 | - { |
|
| 74 | - //actions |
|
| 75 | - add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
| 76 | - add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 77 | - array('EED_Messages', 'maybe_registration'), 10, 2); |
|
| 78 | - //filters |
|
| 79 | - add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
| 80 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 81 | - add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
| 82 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 83 | - //register routes |
|
| 84 | - self::_register_routes(); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 89 | - * |
|
| 90 | - * @access public |
|
| 91 | - * @return void |
|
| 92 | - */ |
|
| 93 | - public static function set_hooks_admin() |
|
| 94 | - { |
|
| 95 | - //actions |
|
| 96 | - add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
| 97 | - add_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
| 98 | - array('EED_Messages', 'payment_reminder'), 10); |
|
| 99 | - add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 100 | - array('EED_Messages', 'maybe_registration'), 10, 3); |
|
| 101 | - add_action('AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
| 102 | - array('EED_Messages', 'send_newsletter_message'), 10, 2); |
|
| 103 | - add_action('AHEE__EES_Espresso_Cancelled__process_shortcode__transaction', |
|
| 104 | - array('EED_Messages', 'cancelled_registration'), 10); |
|
| 105 | - add_action('AHEE__EE_Admin_Page___process_admin_payment_notification', |
|
| 106 | - array('EED_Messages', 'process_admin_payment'), 10, 1); |
|
| 107 | - //filters |
|
| 108 | - add_filter('FHEE__EE_Admin_Page___process_resend_registration__success', |
|
| 109 | - array('EED_Messages', 'process_resend'), 10, 2); |
|
| 110 | - add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
| 111 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 112 | - add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
| 113 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * All the message triggers done by route go in here. |
|
| 119 | - * |
|
| 120 | - * @since 4.5.0 |
|
| 121 | - * @return void |
|
| 122 | - */ |
|
| 123 | - protected static function _register_routes() |
|
| 124 | - { |
|
| 125 | - EE_Config::register_route('msg_url_trigger', 'Messages', 'run'); |
|
| 126 | - EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request'); |
|
| 127 | - EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger'); |
|
| 128 | - EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger'); |
|
| 129 | - do_action('AHEE__EED_Messages___register_routes'); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * This is called when a browser display trigger is executed. |
|
| 135 | - * The browser display trigger is typically used when a already generated message is displayed directly in the |
|
| 136 | - * browser. |
|
| 137 | - * |
|
| 138 | - * @since 4.9.0 |
|
| 139 | - * @param WP $WP |
|
| 140 | - */ |
|
| 141 | - public function browser_trigger($WP) |
|
| 142 | - { |
|
| 143 | - //ensure controller is loaded |
|
| 144 | - self::_load_controller(); |
|
| 145 | - $token = EE_Registry::instance()->REQ->get('token'); |
|
| 146 | - try { |
|
| 147 | - $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager); |
|
| 148 | - self::$_MSG_PROCESSOR->generate_and_send_now($mtg); |
|
| 149 | - } catch (EE_Error $e) { |
|
| 150 | - $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
| 151 | - 'event_espresso'); |
|
| 152 | - // add specific message for developers if WP_DEBUG in on |
|
| 153 | - $error_msg .= '||' . $e->getMessage(); |
|
| 154 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 155 | - } |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * This is called when a browser error trigger is executed. |
|
| 161 | - * When triggered this will grab the EE_Message matching the token in the request and use that to get the error |
|
| 162 | - * message and display it. |
|
| 163 | - * |
|
| 164 | - * @since 4.9.0 |
|
| 165 | - * @param $WP |
|
| 166 | - */ |
|
| 167 | - public function browser_error_trigger($WP) |
|
| 168 | - { |
|
| 169 | - $token = EE_Registry::instance()->REQ->get('token'); |
|
| 170 | - if ($token) { |
|
| 171 | - $message = EEM_Message::instance()->get_one_by_token($token); |
|
| 172 | - if ($message instanceof EE_Message) { |
|
| 173 | - header('HTTP/1.1 200 OK'); |
|
| 174 | - $error_msg = nl2br($message->error_message()); |
|
| 175 | - ?> |
|
| 16 | + /** |
|
| 17 | + * This holds the EE_messages controller |
|
| 18 | + * |
|
| 19 | + * @deprecated 4.9.0 |
|
| 20 | + * @var EE_messages $_EEMSG |
|
| 21 | + */ |
|
| 22 | + protected static $_EEMSG; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @type EE_Message_Resource_Manager $_message_resource_manager |
|
| 26 | + */ |
|
| 27 | + protected static $_message_resource_manager; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * This holds the EE_Messages_Processor business class. |
|
| 31 | + * |
|
| 32 | + * @type EE_Messages_Processor |
|
| 33 | + */ |
|
| 34 | + protected static $_MSG_PROCESSOR; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * holds all the paths for various messages components. |
|
| 38 | + * Utilized by autoloader registry |
|
| 39 | + * |
|
| 40 | + * @var array |
|
| 41 | + */ |
|
| 42 | + protected static $_MSG_PATHS; |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * This will hold an array of messages template packs that are registered in the messages system. |
|
| 47 | + * Format is: |
|
| 48 | + * array( |
|
| 49 | + * 'template_pack_dbref' => EE_Messages_Template_Pack (instance) |
|
| 50 | + * ) |
|
| 51 | + * |
|
| 52 | + * @var EE_Messages_Template_Pack[] |
|
| 53 | + */ |
|
| 54 | + protected static $_TMP_PACKS = array(); |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @return EED_Messages |
|
| 59 | + */ |
|
| 60 | + public static function instance() |
|
| 61 | + { |
|
| 62 | + return parent::get_instance(__CLASS__); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 68 | + * |
|
| 69 | + * @since 4.5.0 |
|
| 70 | + * @return void |
|
| 71 | + */ |
|
| 72 | + public static function set_hooks() |
|
| 73 | + { |
|
| 74 | + //actions |
|
| 75 | + add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
| 76 | + add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 77 | + array('EED_Messages', 'maybe_registration'), 10, 2); |
|
| 78 | + //filters |
|
| 79 | + add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
| 80 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 81 | + add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
| 82 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 83 | + //register routes |
|
| 84 | + self::_register_routes(); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 89 | + * |
|
| 90 | + * @access public |
|
| 91 | + * @return void |
|
| 92 | + */ |
|
| 93 | + public static function set_hooks_admin() |
|
| 94 | + { |
|
| 95 | + //actions |
|
| 96 | + add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
| 97 | + add_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
| 98 | + array('EED_Messages', 'payment_reminder'), 10); |
|
| 99 | + add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 100 | + array('EED_Messages', 'maybe_registration'), 10, 3); |
|
| 101 | + add_action('AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
| 102 | + array('EED_Messages', 'send_newsletter_message'), 10, 2); |
|
| 103 | + add_action('AHEE__EES_Espresso_Cancelled__process_shortcode__transaction', |
|
| 104 | + array('EED_Messages', 'cancelled_registration'), 10); |
|
| 105 | + add_action('AHEE__EE_Admin_Page___process_admin_payment_notification', |
|
| 106 | + array('EED_Messages', 'process_admin_payment'), 10, 1); |
|
| 107 | + //filters |
|
| 108 | + add_filter('FHEE__EE_Admin_Page___process_resend_registration__success', |
|
| 109 | + array('EED_Messages', 'process_resend'), 10, 2); |
|
| 110 | + add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
| 111 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 112 | + add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
| 113 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * All the message triggers done by route go in here. |
|
| 119 | + * |
|
| 120 | + * @since 4.5.0 |
|
| 121 | + * @return void |
|
| 122 | + */ |
|
| 123 | + protected static function _register_routes() |
|
| 124 | + { |
|
| 125 | + EE_Config::register_route('msg_url_trigger', 'Messages', 'run'); |
|
| 126 | + EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request'); |
|
| 127 | + EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger'); |
|
| 128 | + EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger'); |
|
| 129 | + do_action('AHEE__EED_Messages___register_routes'); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * This is called when a browser display trigger is executed. |
|
| 135 | + * The browser display trigger is typically used when a already generated message is displayed directly in the |
|
| 136 | + * browser. |
|
| 137 | + * |
|
| 138 | + * @since 4.9.0 |
|
| 139 | + * @param WP $WP |
|
| 140 | + */ |
|
| 141 | + public function browser_trigger($WP) |
|
| 142 | + { |
|
| 143 | + //ensure controller is loaded |
|
| 144 | + self::_load_controller(); |
|
| 145 | + $token = EE_Registry::instance()->REQ->get('token'); |
|
| 146 | + try { |
|
| 147 | + $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager); |
|
| 148 | + self::$_MSG_PROCESSOR->generate_and_send_now($mtg); |
|
| 149 | + } catch (EE_Error $e) { |
|
| 150 | + $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
| 151 | + 'event_espresso'); |
|
| 152 | + // add specific message for developers if WP_DEBUG in on |
|
| 153 | + $error_msg .= '||' . $e->getMessage(); |
|
| 154 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * This is called when a browser error trigger is executed. |
|
| 161 | + * When triggered this will grab the EE_Message matching the token in the request and use that to get the error |
|
| 162 | + * message and display it. |
|
| 163 | + * |
|
| 164 | + * @since 4.9.0 |
|
| 165 | + * @param $WP |
|
| 166 | + */ |
|
| 167 | + public function browser_error_trigger($WP) |
|
| 168 | + { |
|
| 169 | + $token = EE_Registry::instance()->REQ->get('token'); |
|
| 170 | + if ($token) { |
|
| 171 | + $message = EEM_Message::instance()->get_one_by_token($token); |
|
| 172 | + if ($message instanceof EE_Message) { |
|
| 173 | + header('HTTP/1.1 200 OK'); |
|
| 174 | + $error_msg = nl2br($message->error_message()); |
|
| 175 | + ?> |
|
| 176 | 176 | <!DOCTYPE html> |
| 177 | 177 | <html> |
| 178 | 178 | <head></head> |
| 179 | 179 | <body> |
| 180 | 180 | <?php echo empty($error_msg) |
| 181 | - ? esc_html__('Unfortunately, we were unable to capture the error message for this message.', |
|
| 182 | - 'event_espresso') |
|
| 183 | - : wp_kses( |
|
| 184 | - $error_msg, |
|
| 185 | - array( |
|
| 186 | - 'a' => array( |
|
| 187 | - 'href' => array(), |
|
| 188 | - 'title' => array(), |
|
| 189 | - ), |
|
| 190 | - 'span' => array(), |
|
| 191 | - 'div' => array(), |
|
| 192 | - 'p' => array(), |
|
| 193 | - 'strong' => array(), |
|
| 194 | - 'em' => array(), |
|
| 195 | - 'br' => array(), |
|
| 196 | - ) |
|
| 197 | - ); ?> |
|
| 181 | + ? esc_html__('Unfortunately, we were unable to capture the error message for this message.', |
|
| 182 | + 'event_espresso') |
|
| 183 | + : wp_kses( |
|
| 184 | + $error_msg, |
|
| 185 | + array( |
|
| 186 | + 'a' => array( |
|
| 187 | + 'href' => array(), |
|
| 188 | + 'title' => array(), |
|
| 189 | + ), |
|
| 190 | + 'span' => array(), |
|
| 191 | + 'div' => array(), |
|
| 192 | + 'p' => array(), |
|
| 193 | + 'strong' => array(), |
|
| 194 | + 'em' => array(), |
|
| 195 | + 'br' => array(), |
|
| 196 | + ) |
|
| 197 | + ); ?> |
|
| 198 | 198 | </body> |
| 199 | 199 | </html> |
| 200 | 200 | <?php |
| 201 | - exit; |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - return; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * This runs when the msg_url_trigger route has initiated. |
|
| 210 | - * |
|
| 211 | - * @since 4.5.0 |
|
| 212 | - * @param WP $WP |
|
| 213 | - * @throws EE_Error |
|
| 214 | - * @return void |
|
| 215 | - */ |
|
| 216 | - public function run($WP) |
|
| 217 | - { |
|
| 218 | - //ensure controller is loaded |
|
| 219 | - self::_load_controller(); |
|
| 220 | - // attempt to process message |
|
| 221 | - try { |
|
| 222 | - /** @type EE_Message_To_Generate_From_Request $message_to_generate */ |
|
| 223 | - $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
| 224 | - self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate); |
|
| 225 | - } catch (EE_Error $e) { |
|
| 226 | - $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
| 227 | - 'event_espresso'); |
|
| 228 | - // add specific message for developers if WP_DEBUG in on |
|
| 229 | - $error_msg .= '||' . $e->getMessage(); |
|
| 230 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 231 | - } |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * This is triggered by the 'msg_cron_trigger' route. |
|
| 237 | - * |
|
| 238 | - * @param WP $WP |
|
| 239 | - */ |
|
| 240 | - public function execute_batch_request($WP) |
|
| 241 | - { |
|
| 242 | - $this->run_cron(); |
|
| 243 | - header('HTTP/1.1 200 OK'); |
|
| 244 | - exit(); |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp |
|
| 250 | - * request. |
|
| 251 | - */ |
|
| 252 | - public function run_cron() |
|
| 253 | - { |
|
| 254 | - self::_load_controller(); |
|
| 255 | - //get required vars |
|
| 256 | - $cron_type = EE_Registry::instance()->REQ->get('type'); |
|
| 257 | - $transient_key = EE_Registry::instance()->REQ->get('key'); |
|
| 258 | - |
|
| 259 | - //now let's verify transient, if not valid exit immediately |
|
| 260 | - if (! get_transient($transient_key)) { |
|
| 261 | - /** |
|
| 262 | - * trigger error so this gets in the error logs. This is important because it happens on a non-user request. |
|
| 263 | - */ |
|
| 264 | - trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso')); |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - //if made it here, lets' delete the transient to keep the db clean |
|
| 268 | - delete_transient($transient_key); |
|
| 269 | - |
|
| 270 | - if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { |
|
| 271 | - |
|
| 272 | - $method = 'batch_' . $cron_type . '_from_queue'; |
|
| 273 | - if (method_exists(self::$_MSG_PROCESSOR, $method)) { |
|
| 274 | - self::$_MSG_PROCESSOR->$method(); |
|
| 275 | - } else { |
|
| 276 | - //no matching task |
|
| 277 | - /** |
|
| 278 | - * trigger error so this gets in the error logs. This is important because it happens on a non user request. |
|
| 279 | - */ |
|
| 280 | - trigger_error(esc_attr(sprintf(__('There is no task corresponding to this route %s', 'event_espresso'), |
|
| 281 | - $cron_type))); |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - do_action('FHEE__EED_Messages__run_cron__end'); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * This is used to retrieve the template pack for the given name. |
|
| 291 | - * Retrieved packs are cached on the static $_TMP_PACKS array. If there is no class matching the given name then |
|
| 292 | - * the default template pack is returned. |
|
| 293 | - * |
|
| 294 | - * @deprecated 4.9.0 @see EEH_MSG_Template::get_template_pack() |
|
| 295 | - * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used |
|
| 296 | - * in generating the Pack class name). |
|
| 297 | - * @return EE_Messages_Template_Pack |
|
| 298 | - */ |
|
| 299 | - public static function get_template_pack($template_pack_name) |
|
| 300 | - { |
|
| 301 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 302 | - return EEH_MSG_Template::get_template_pack($template_pack_name); |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * Retrieves an array of all template packs. |
|
| 308 | - * Array is in the format array( 'dbref' => EE_Messages_Template_Pack ) |
|
| 309 | - * |
|
| 310 | - * @deprecated 4.9.0 @see EEH_MSG_Template_Pack::get_template_pack_collection |
|
| 311 | - * @return EE_Messages_Template_Pack[] |
|
| 312 | - */ |
|
| 313 | - public static function get_template_packs() |
|
| 314 | - { |
|
| 315 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 316 | - |
|
| 317 | - //for backward compat, let's make sure this returns in the same format as originally. |
|
| 318 | - $template_pack_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 319 | - $template_pack_collection->rewind(); |
|
| 320 | - $template_packs = array(); |
|
| 321 | - while ($template_pack_collection->valid()) { |
|
| 322 | - $template_packs[$template_pack_collection->current()->dbref] = $template_pack_collection->current(); |
|
| 323 | - $template_pack_collection->next(); |
|
| 324 | - } |
|
| 325 | - return $template_packs; |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - |
|
| 329 | - /** |
|
| 330 | - * This simply makes sure the autoloaders are registered for the EE_messages system. |
|
| 331 | - * |
|
| 332 | - * @since 4.5.0 |
|
| 333 | - * @return void |
|
| 334 | - */ |
|
| 335 | - public static function set_autoloaders() |
|
| 336 | - { |
|
| 337 | - if (empty(self::$_MSG_PATHS)) { |
|
| 338 | - self::_set_messages_paths(); |
|
| 339 | - foreach (self::$_MSG_PATHS as $path) { |
|
| 340 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path); |
|
| 341 | - } |
|
| 342 | - // add aliases |
|
| 343 | - EEH_Autoloader::add_alias('EE_messages', 'EE_messages'); |
|
| 344 | - EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger'); |
|
| 345 | - } |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - |
|
| 349 | - /** |
|
| 350 | - * Take care of adding all the paths for the messages components to the $_MSG_PATHS property |
|
| 351 | - * for use by the Messages Autoloaders |
|
| 352 | - * |
|
| 353 | - * @since 4.5.0 |
|
| 354 | - * @return void. |
|
| 355 | - */ |
|
| 356 | - protected static function _set_messages_paths() |
|
| 357 | - { |
|
| 358 | - $dir_ref = array( |
|
| 359 | - 'messages/message_type', |
|
| 360 | - 'messages/messenger', |
|
| 361 | - 'messages/defaults', |
|
| 362 | - 'messages/defaults/email', |
|
| 363 | - 'messages/data_class', |
|
| 364 | - 'messages/validators', |
|
| 365 | - 'messages/validators/email', |
|
| 366 | - 'messages/validators/html', |
|
| 367 | - 'shortcodes', |
|
| 368 | - ); |
|
| 369 | - $paths = array(); |
|
| 370 | - foreach ($dir_ref as $index => $dir) { |
|
| 371 | - $paths[$index] = EE_LIBRARIES . $dir; |
|
| 372 | - } |
|
| 373 | - self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths); |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - |
|
| 377 | - /** |
|
| 378 | - * Takes care of loading dependencies |
|
| 379 | - * |
|
| 380 | - * @since 4.5.0 |
|
| 381 | - * @return void |
|
| 382 | - */ |
|
| 383 | - protected static function _load_controller() |
|
| 384 | - { |
|
| 385 | - if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
| 386 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
| 387 | - self::set_autoloaders(); |
|
| 388 | - self::$_EEMSG = EE_Registry::instance()->load_lib('messages'); |
|
| 389 | - self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
| 390 | - self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 391 | - } |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - |
|
| 395 | - /** |
|
| 396 | - * @param EE_Transaction $transaction |
|
| 397 | - */ |
|
| 398 | - public static function payment_reminder(EE_Transaction $transaction) |
|
| 399 | - { |
|
| 400 | - self::_load_controller(); |
|
| 401 | - $data = array($transaction, null); |
|
| 402 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data); |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - |
|
| 406 | - /** |
|
| 407 | - * Any messages triggers for after successful gateway payments should go in here. |
|
| 408 | - * |
|
| 409 | - * @param EE_Transaction object |
|
| 410 | - * @param EE_Payment object |
|
| 411 | - * @return void |
|
| 412 | - */ |
|
| 413 | - public static function payment(EE_Transaction $transaction, EE_Payment $payment) |
|
| 414 | - { |
|
| 415 | - self::_load_controller(); |
|
| 416 | - $data = array($transaction, $payment); |
|
| 417 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 418 | - $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
| 419 | - //if payment amount is less than 0 then switch to payment_refund message type. |
|
| 420 | - $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
| 421 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - |
|
| 425 | - /** |
|
| 426 | - * @param EE_Transaction $transaction |
|
| 427 | - */ |
|
| 428 | - public static function cancelled_registration(EE_Transaction $transaction) |
|
| 429 | - { |
|
| 430 | - self::_load_controller(); |
|
| 431 | - $data = array($transaction, null); |
|
| 432 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data); |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - |
|
| 436 | - /** |
|
| 437 | - * Trigger for Registration messages |
|
| 438 | - * Note that what registration message type is sent depends on what the reg status is for the registrations on the |
|
| 439 | - * incoming transaction. |
|
| 440 | - * |
|
| 441 | - * @param EE_Registration $registration |
|
| 442 | - * @param array $extra_details |
|
| 443 | - * @return void |
|
| 444 | - */ |
|
| 445 | - public static function maybe_registration(EE_Registration $registration, $extra_details = array()) |
|
| 446 | - { |
|
| 447 | - |
|
| 448 | - if (! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
| 449 | - //no messages please |
|
| 450 | - return; |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - |
|
| 454 | - //get all registrations so we make sure we send messages for the right status. |
|
| 455 | - $all_registrations = $registration->transaction()->registrations(); |
|
| 456 | - |
|
| 457 | - //cached array of statuses so we only trigger messages once per status. |
|
| 458 | - $statuses_sent = array(); |
|
| 459 | - self::_load_controller(); |
|
| 460 | - $mtgs = array(); |
|
| 461 | - |
|
| 462 | - //loop through registrations and trigger messages once per status. |
|
| 463 | - foreach ($all_registrations as $reg) { |
|
| 464 | - |
|
| 465 | - //already triggered? |
|
| 466 | - if (in_array($reg->status_ID(), $statuses_sent)) { |
|
| 467 | - continue; |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID()); |
|
| 471 | - $mtgs = array_merge( |
|
| 472 | - $mtgs, |
|
| 473 | - self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
| 474 | - $message_type, |
|
| 475 | - array($registration->transaction(), null, $reg->status_ID()) |
|
| 476 | - ) |
|
| 477 | - ); |
|
| 478 | - $statuses_sent[] = $reg->status_ID(); |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - if (count($statuses_sent) > 1) { |
|
| 482 | - $mtgs = array_merge( |
|
| 483 | - $mtgs, |
|
| 484 | - self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
| 485 | - 'registration_summary', |
|
| 486 | - array($registration->transaction(), null) |
|
| 487 | - ) |
|
| 488 | - ); |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - //batch queue and initiate request |
|
| 492 | - self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs); |
|
| 493 | - self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - |
|
| 497 | - /** |
|
| 498 | - * This is a helper method used to very whether a registration notification should be sent or |
|
| 499 | - * not. Prevents duplicate notifications going out for registration context notifications. |
|
| 500 | - * |
|
| 501 | - * @param EE_Registration $registration [description] |
|
| 502 | - * @param array $extra_details [description] |
|
| 503 | - * @return bool true = send away, false = nope halt the presses. |
|
| 504 | - */ |
|
| 505 | - protected static function _verify_registration_notification_send( |
|
| 506 | - EE_Registration $registration, |
|
| 507 | - $extra_details = array() |
|
| 508 | - ) { |
|
| 509 | - //self::log( |
|
| 510 | - // __CLASS__, __FUNCTION__, __LINE__, |
|
| 511 | - // $registration->transaction(), |
|
| 512 | - // array( '$extra_details' => $extra_details ) |
|
| 513 | - //); |
|
| 514 | - // currently only using this to send messages for the primary registrant |
|
| 515 | - if (! $registration->is_primary_registrant()) { |
|
| 516 | - return false; |
|
| 517 | - } |
|
| 518 | - // first we check if we're in admin and not doing front ajax |
|
| 519 | - if (is_admin() && ! EE_FRONT_AJAX) { |
|
| 520 | - //make sure appropriate admin params are set for sending messages |
|
| 521 | - if (empty($_REQUEST['txn_reg_status_change']['send_notifications']) || ! absint($_REQUEST['txn_reg_status_change']['send_notifications'])) { |
|
| 522 | - //no messages sent please. |
|
| 523 | - return false; |
|
| 524 | - } |
|
| 525 | - } else { |
|
| 526 | - // frontend request (either regular or via AJAX) |
|
| 527 | - // TXN is NOT finalized ? |
|
| 528 | - if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
| 529 | - return false; |
|
| 530 | - } |
|
| 531 | - // return visit but nothing changed ??? |
|
| 532 | - if ( |
|
| 533 | - isset($extra_details['revisit'], $extra_details['status_updates']) && |
|
| 534 | - $extra_details['revisit'] && ! $extra_details['status_updates'] |
|
| 535 | - ) { |
|
| 536 | - return false; |
|
| 537 | - } |
|
| 538 | - // NOT sending messages && reg status is something other than "Not-Approved" |
|
| 539 | - if ( |
|
| 540 | - ! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) && |
|
| 541 | - $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
| 542 | - ) { |
|
| 543 | - return false; |
|
| 544 | - } |
|
| 545 | - } |
|
| 546 | - // release the kraken |
|
| 547 | - return true; |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - |
|
| 551 | - /** |
|
| 552 | - * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that |
|
| 553 | - * status id. |
|
| 554 | - * |
|
| 555 | - * @deprecated 4.9.0 Use EEH_MSG_Template::reg_status_to_message_type_array() |
|
| 556 | - * or EEH_MSG_Template::convert_reg_status_to_message_type |
|
| 557 | - * @param string $reg_status |
|
| 558 | - * @return array |
|
| 559 | - */ |
|
| 560 | - protected static function _get_reg_status_array($reg_status = '') |
|
| 561 | - { |
|
| 562 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 563 | - return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
| 564 | - ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
| 565 | - : EEH_MSG_Template::reg_status_to_message_type_array(); |
|
| 566 | - } |
|
| 567 | - |
|
| 568 | - |
|
| 569 | - /** |
|
| 570 | - * Simply returns the payment message type for the given payment status. |
|
| 571 | - * |
|
| 572 | - * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array |
|
| 573 | - * or EEH_MSG_Template::convert_payment_status_to_message_type |
|
| 574 | - * @param string $payment_status The payment status being matched. |
|
| 575 | - * @return string|bool The payment message type slug matching the status or false if no match. |
|
| 576 | - */ |
|
| 577 | - protected static function _get_payment_message_type($payment_status) |
|
| 578 | - { |
|
| 579 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 580 | - return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
| 581 | - ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
| 582 | - : false; |
|
| 583 | - } |
|
| 584 | - |
|
| 585 | - |
|
| 586 | - /** |
|
| 587 | - * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
| 588 | - * |
|
| 589 | - * @access public |
|
| 590 | - * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages |
|
| 591 | - * @return bool success/fail |
|
| 592 | - */ |
|
| 593 | - public static function process_resend($req_data) |
|
| 594 | - { |
|
| 595 | - self::_load_controller(); |
|
| 596 | - |
|
| 597 | - //if $msgID in this request then skip to the new resend_message |
|
| 598 | - if (EE_Registry::instance()->REQ->get('MSG_ID')) { |
|
| 599 | - return self::resend_message(); |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - //make sure any incoming request data is set on the REQ so that it gets picked up later. |
|
| 603 | - $req_data = (array)$req_data; |
|
| 604 | - foreach ($req_data as $request_key => $request_value) { |
|
| 605 | - EE_Registry::instance()->REQ->set($request_key, $request_value); |
|
| 606 | - } |
|
| 607 | - |
|
| 608 | - if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()) { |
|
| 609 | - return false; |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - try { |
|
| 613 | - self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send); |
|
| 614 | - self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
| 615 | - } catch (EE_Error $e) { |
|
| 616 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 617 | - return false; |
|
| 618 | - } |
|
| 619 | - EE_Error::add_success( |
|
| 620 | - __('Messages have been successfully queued for generation and sending.', 'event_espresso') |
|
| 621 | - ); |
|
| 622 | - return true; //everything got queued. |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - |
|
| 626 | - /** |
|
| 627 | - * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
| 628 | - * |
|
| 629 | - * @return bool |
|
| 630 | - */ |
|
| 631 | - public static function resend_message() |
|
| 632 | - { |
|
| 633 | - self::_load_controller(); |
|
| 634 | - |
|
| 635 | - $msgID = EE_Registry::instance()->REQ->get('MSG_ID'); |
|
| 636 | - if (! $msgID) { |
|
| 637 | - EE_Error::add_error(__('Something went wrong because there is no "MSG_ID" value in the request', |
|
| 638 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 639 | - return false; |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array)$msgID); |
|
| 643 | - |
|
| 644 | - //setup success message. |
|
| 645 | - $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
| 646 | - EE_Error::add_success(sprintf( |
|
| 647 | - _n( |
|
| 648 | - 'There was %d message queued for resending.', |
|
| 649 | - 'There were %d messages queued for resending.', |
|
| 650 | - $count_ready_for_resend, |
|
| 651 | - 'event_espresso' |
|
| 652 | - ), |
|
| 653 | - $count_ready_for_resend |
|
| 654 | - )); |
|
| 655 | - return true; |
|
| 656 | - } |
|
| 657 | - |
|
| 658 | - |
|
| 659 | - /** |
|
| 660 | - * Message triggers for manual payment applied by admin |
|
| 661 | - * |
|
| 662 | - * @param EE_Payment $payment EE_payment object |
|
| 663 | - * @return bool success/fail |
|
| 664 | - */ |
|
| 665 | - public static function process_admin_payment(EE_Payment $payment) |
|
| 666 | - { |
|
| 667 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 668 | - //we need to get the transaction object |
|
| 669 | - $transaction = $payment->transaction(); |
|
| 670 | - if ($transaction instanceof EE_Transaction) { |
|
| 671 | - $data = array($transaction, $payment); |
|
| 672 | - $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
| 673 | - |
|
| 674 | - //if payment amount is less than 0 then switch to payment_refund message type. |
|
| 675 | - $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
| 676 | - |
|
| 677 | - //if payment_refund is selected, but the status is NOT accepted. Then change message type to false so NO message notification goes out. |
|
| 678 | - $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved ? false : $message_type; |
|
| 679 | - |
|
| 680 | - self::_load_controller(); |
|
| 681 | - |
|
| 682 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
| 683 | - |
|
| 684 | - //get count of queued for generation |
|
| 685 | - $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(array( |
|
| 686 | - EEM_Message::status_incomplete, |
|
| 687 | - EEM_Message::status_idle, |
|
| 688 | - )); |
|
| 689 | - |
|
| 690 | - if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) { |
|
| 691 | - add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
| 692 | - return true; |
|
| 693 | - } else { |
|
| 694 | - $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::instance()->stati_indicating_failed_sending()); |
|
| 695 | - /** |
|
| 696 | - * Verify that there are actually errors. If not then we return a success message because the queue might have been emptied due to successful |
|
| 697 | - * IMMEDIATE generation. |
|
| 698 | - */ |
|
| 699 | - if ($count_failed > 0) { |
|
| 700 | - EE_Error::add_error(sprintf( |
|
| 701 | - _n( |
|
| 702 | - 'The payment notification generation failed.', |
|
| 703 | - '%d payment notifications failed being sent.', |
|
| 704 | - $count_failed, |
|
| 705 | - 'event_espresso' |
|
| 706 | - ), |
|
| 707 | - $count_failed |
|
| 708 | - ), __FILE__, __FUNCTION__, __LINE__); |
|
| 709 | - |
|
| 710 | - return false; |
|
| 711 | - } else { |
|
| 712 | - add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
| 713 | - return true; |
|
| 714 | - } |
|
| 715 | - } |
|
| 716 | - } else { |
|
| 717 | - EE_Error::add_error( |
|
| 718 | - 'Unable to generate the payment notification because the given value for the transaction is invalid.', |
|
| 719 | - 'event_espresso' |
|
| 720 | - ); |
|
| 721 | - return false; |
|
| 722 | - } |
|
| 723 | - } |
|
| 724 | - |
|
| 725 | - |
|
| 726 | - /** |
|
| 727 | - * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger |
|
| 728 | - * |
|
| 729 | - * @since 4.3.0 |
|
| 730 | - * @param EE_Registration[] $registrations an array of EE_Registration objects |
|
| 731 | - * @param int $grp_id a specific message template group id. |
|
| 732 | - * @return void |
|
| 733 | - */ |
|
| 734 | - public static function send_newsletter_message($registrations, $grp_id) |
|
| 735 | - { |
|
| 736 | - //make sure mtp is id and set it in the EE_Request Handler later messages setup. |
|
| 737 | - EE_Registry::instance()->REQ->set('GRP_ID', (int)$grp_id); |
|
| 738 | - self::_load_controller(); |
|
| 739 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations); |
|
| 740 | - } |
|
| 741 | - |
|
| 742 | - |
|
| 743 | - /** |
|
| 744 | - * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url |
|
| 745 | - * |
|
| 746 | - * @since 4.3.0 |
|
| 747 | - * @param string $registration_message_trigger_url |
|
| 748 | - * @param EE_Registration $registration |
|
| 749 | - * @param string $messenger |
|
| 750 | - * @param string $message_type |
|
| 751 | - * @return string |
|
| 752 | - */ |
|
| 753 | - public static function registration_message_trigger_url( |
|
| 754 | - $registration_message_trigger_url, |
|
| 755 | - EE_Registration $registration, |
|
| 756 | - $messenger = 'html', |
|
| 757 | - $message_type = 'invoice' |
|
| 758 | - ) { |
|
| 759 | - // whitelist $messenger |
|
| 760 | - switch ($messenger) { |
|
| 761 | - case 'pdf' : |
|
| 762 | - $sending_messenger = 'pdf'; |
|
| 763 | - $generating_messenger = 'html'; |
|
| 764 | - break; |
|
| 765 | - case 'html' : |
|
| 766 | - default : |
|
| 767 | - $sending_messenger = 'html'; |
|
| 768 | - $generating_messenger = 'html'; |
|
| 769 | - break; |
|
| 770 | - } |
|
| 771 | - // whitelist $message_type |
|
| 772 | - switch ($message_type) { |
|
| 773 | - case 'receipt' : |
|
| 774 | - $message_type = 'receipt'; |
|
| 775 | - break; |
|
| 776 | - case 'invoice' : |
|
| 777 | - default : |
|
| 778 | - $message_type = 'invoice'; |
|
| 779 | - break; |
|
| 780 | - } |
|
| 781 | - // verify that both the messenger AND the message type are active |
|
| 782 | - if (EEH_MSG_Template::is_messenger_active($sending_messenger) && EEH_MSG_Template::is_mt_active($message_type)) { |
|
| 783 | - //need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?) |
|
| 784 | - $template_query_params = array( |
|
| 785 | - 'MTP_is_active' => true, |
|
| 786 | - 'MTP_messenger' => $generating_messenger, |
|
| 787 | - 'MTP_message_type' => $message_type, |
|
| 788 | - 'Event.EVT_ID' => $registration->event_ID(), |
|
| 789 | - ); |
|
| 790 | - //get the message template group. |
|
| 791 | - $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
| 792 | - //if we don't have an EE_Message_Template_Group then return |
|
| 793 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 794 | - // remove EVT_ID from query params so that global templates get picked up |
|
| 795 | - unset($template_query_params['Event.EVT_ID']); |
|
| 796 | - //get global template as the fallback |
|
| 797 | - $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
| 798 | - } |
|
| 799 | - //if we don't have an EE_Message_Template_Group then return |
|
| 800 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 801 | - return ''; |
|
| 802 | - } |
|
| 803 | - // generate the URL |
|
| 804 | - $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger( |
|
| 805 | - $sending_messenger, |
|
| 806 | - $generating_messenger, |
|
| 807 | - 'purchaser', |
|
| 808 | - $message_type, |
|
| 809 | - $registration, |
|
| 810 | - $msg_template_group->ID(), |
|
| 811 | - $registration->transaction_ID() |
|
| 812 | - ); |
|
| 813 | - |
|
| 814 | - } |
|
| 815 | - return $registration_message_trigger_url; |
|
| 816 | - } |
|
| 817 | - |
|
| 818 | - |
|
| 819 | - /** |
|
| 820 | - * Use to generate and return a message preview! |
|
| 821 | - * |
|
| 822 | - * @param string $type This should correspond with a valid message type |
|
| 823 | - * @param string $context This should correspond with a valid context for the message type |
|
| 824 | - * @param string $messenger This should correspond with a valid messenger. |
|
| 825 | - * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular |
|
| 826 | - * preview |
|
| 827 | - * @return bool|string The body of the message or if send is requested, sends. |
|
| 828 | - * @throws EE_Error |
|
| 829 | - */ |
|
| 830 | - public static function preview_message($type, $context, $messenger, $send = false) |
|
| 831 | - { |
|
| 832 | - self::_load_controller(); |
|
| 833 | - $mtg = new EE_Message_To_Generate( |
|
| 834 | - $messenger, |
|
| 835 | - $type, |
|
| 836 | - array(), |
|
| 837 | - $context, |
|
| 838 | - true |
|
| 839 | - ); |
|
| 840 | - $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send); |
|
| 841 | - if ($generated_preview_queue instanceof EE_Messages_Queue) { |
|
| 842 | - //loop through all content for the preview and remove any persisted records. |
|
| 843 | - $content = ''; |
|
| 844 | - foreach ($generated_preview_queue->get_message_repository() as $message) { |
|
| 845 | - $content = $message->content(); |
|
| 846 | - if ($message->ID() > 0 && $message->STS_ID() !== EEM_Message::status_failed) { |
|
| 847 | - $message->delete(); |
|
| 848 | - } |
|
| 849 | - } |
|
| 850 | - return $content; |
|
| 851 | - } else { |
|
| 852 | - return $generated_preview_queue; |
|
| 853 | - } |
|
| 854 | - } |
|
| 855 | - |
|
| 856 | - |
|
| 857 | - /** |
|
| 858 | - * This is a method that allows for sending a message using a messenger matching the string given and the provided |
|
| 859 | - * EE_Message_Queue object. The EE_Message_Queue object is used to create a single aggregate EE_Message via the |
|
| 860 | - * content found in the EE_Message objects in the queue. |
|
| 861 | - * |
|
| 862 | - * @since 4.9.0 |
|
| 863 | - * @param string $messenger a string matching a valid active messenger in the system |
|
| 864 | - * @param string $message_type Although it seems contrary to the name of the method, a message |
|
| 865 | - * type name is still required to send along the message type to the |
|
| 866 | - * messenger because this is used for determining what specific |
|
| 867 | - * variations might be loaded for the generated message. |
|
| 868 | - * @param EE_Messages_Queue $queue |
|
| 869 | - * @param string $custom_subject Can be used to set what the custom subject string will be on the |
|
| 870 | - * aggregate EE_Message object. |
|
| 871 | - * @return bool success or fail. |
|
| 872 | - */ |
|
| 873 | - public static function send_message_with_messenger_only( |
|
| 874 | - $messenger, |
|
| 875 | - $message_type, |
|
| 876 | - EE_Messages_Queue $queue, |
|
| 877 | - $custom_subject = '' |
|
| 878 | - ) { |
|
| 879 | - self::_load_controller(); |
|
| 880 | - /** @type EE_Message_To_Generate_From_Queue $message_to_generate */ |
|
| 881 | - $message_to_generate = EE_Registry::instance()->load_lib( |
|
| 882 | - 'Message_To_Generate_From_Queue', |
|
| 883 | - array( |
|
| 884 | - $messenger, |
|
| 885 | - $message_type, |
|
| 886 | - $queue, |
|
| 887 | - $custom_subject, |
|
| 888 | - ) |
|
| 889 | - ); |
|
| 890 | - return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate); |
|
| 891 | - } |
|
| 892 | - |
|
| 893 | - |
|
| 894 | - /** |
|
| 895 | - * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation) |
|
| 896 | - * |
|
| 897 | - * @since 4.9.0 |
|
| 898 | - * @param array $message_ids An array of message ids |
|
| 899 | - * @return bool | EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated |
|
| 900 | - * messages. |
|
| 901 | - */ |
|
| 902 | - public static function generate_now($message_ids) |
|
| 903 | - { |
|
| 904 | - self::_load_controller(); |
|
| 905 | - $messages = EEM_Message::instance()->get_all( |
|
| 906 | - array( |
|
| 907 | - 0 => array( |
|
| 908 | - 'MSG_ID' => array('IN', $message_ids), |
|
| 909 | - 'STS_ID' => EEM_Message::status_incomplete, |
|
| 910 | - ), |
|
| 911 | - ) |
|
| 912 | - ); |
|
| 913 | - $generated_queue = false; |
|
| 914 | - if ($messages) { |
|
| 915 | - $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages); |
|
| 916 | - } |
|
| 917 | - |
|
| 918 | - if (! $generated_queue instanceof EE_Messages_Queue) { |
|
| 919 | - EE_Error::add_error( |
|
| 920 | - __('The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.', |
|
| 921 | - 'event_espresso'), |
|
| 922 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 923 | - ); |
|
| 924 | - } |
|
| 925 | - return $generated_queue; |
|
| 926 | - } |
|
| 927 | - |
|
| 928 | - |
|
| 929 | - /** |
|
| 930 | - * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or, |
|
| 931 | - * EEM_Message::status_idle |
|
| 932 | - * |
|
| 933 | - * @since 4.9.0 |
|
| 934 | - * @param $message_ids |
|
| 935 | - * @return bool | EE_Messages_Queue false if no messages sent. |
|
| 936 | - */ |
|
| 937 | - public static function send_now($message_ids) |
|
| 938 | - { |
|
| 939 | - self::_load_controller(); |
|
| 940 | - $messages = EEM_Message::instance()->get_all( |
|
| 941 | - array( |
|
| 942 | - 0 => array( |
|
| 943 | - 'MSG_ID' => array('IN', $message_ids), |
|
| 944 | - 'STS_ID' => array( |
|
| 945 | - 'IN', |
|
| 946 | - array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry), |
|
| 947 | - ), |
|
| 948 | - ), |
|
| 949 | - ) |
|
| 950 | - ); |
|
| 951 | - $sent_queue = false; |
|
| 952 | - if ($messages) { |
|
| 953 | - $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages); |
|
| 954 | - } |
|
| 955 | - |
|
| 956 | - if (! $sent_queue instanceof EE_Messages_Queue) { |
|
| 957 | - EE_Error::add_error( |
|
| 958 | - __('The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', |
|
| 959 | - 'event_espresso'), |
|
| 960 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 961 | - ); |
|
| 962 | - } else { |
|
| 963 | - //can count how many sent by using the messages in the queue |
|
| 964 | - $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent()); |
|
| 965 | - if ($sent_count > 0) { |
|
| 966 | - EE_Error::add_success( |
|
| 967 | - sprintf( |
|
| 968 | - _n( |
|
| 969 | - 'There was %d message successfully sent.', |
|
| 970 | - 'There were %d messages successfully sent.', |
|
| 971 | - $sent_count, |
|
| 972 | - 'event_espresso' |
|
| 973 | - ), |
|
| 974 | - $sent_count |
|
| 975 | - ) |
|
| 976 | - ); |
|
| 977 | - } else { |
|
| 978 | - EE_Error::overwrite_errors(); |
|
| 979 | - EE_Error::add_error( |
|
| 980 | - __('No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error. |
|
| 201 | + exit; |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + return; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * This runs when the msg_url_trigger route has initiated. |
|
| 210 | + * |
|
| 211 | + * @since 4.5.0 |
|
| 212 | + * @param WP $WP |
|
| 213 | + * @throws EE_Error |
|
| 214 | + * @return void |
|
| 215 | + */ |
|
| 216 | + public function run($WP) |
|
| 217 | + { |
|
| 218 | + //ensure controller is loaded |
|
| 219 | + self::_load_controller(); |
|
| 220 | + // attempt to process message |
|
| 221 | + try { |
|
| 222 | + /** @type EE_Message_To_Generate_From_Request $message_to_generate */ |
|
| 223 | + $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
| 224 | + self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate); |
|
| 225 | + } catch (EE_Error $e) { |
|
| 226 | + $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
| 227 | + 'event_espresso'); |
|
| 228 | + // add specific message for developers if WP_DEBUG in on |
|
| 229 | + $error_msg .= '||' . $e->getMessage(); |
|
| 230 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 231 | + } |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * This is triggered by the 'msg_cron_trigger' route. |
|
| 237 | + * |
|
| 238 | + * @param WP $WP |
|
| 239 | + */ |
|
| 240 | + public function execute_batch_request($WP) |
|
| 241 | + { |
|
| 242 | + $this->run_cron(); |
|
| 243 | + header('HTTP/1.1 200 OK'); |
|
| 244 | + exit(); |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp |
|
| 250 | + * request. |
|
| 251 | + */ |
|
| 252 | + public function run_cron() |
|
| 253 | + { |
|
| 254 | + self::_load_controller(); |
|
| 255 | + //get required vars |
|
| 256 | + $cron_type = EE_Registry::instance()->REQ->get('type'); |
|
| 257 | + $transient_key = EE_Registry::instance()->REQ->get('key'); |
|
| 258 | + |
|
| 259 | + //now let's verify transient, if not valid exit immediately |
|
| 260 | + if (! get_transient($transient_key)) { |
|
| 261 | + /** |
|
| 262 | + * trigger error so this gets in the error logs. This is important because it happens on a non-user request. |
|
| 263 | + */ |
|
| 264 | + trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso')); |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + //if made it here, lets' delete the transient to keep the db clean |
|
| 268 | + delete_transient($transient_key); |
|
| 269 | + |
|
| 270 | + if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { |
|
| 271 | + |
|
| 272 | + $method = 'batch_' . $cron_type . '_from_queue'; |
|
| 273 | + if (method_exists(self::$_MSG_PROCESSOR, $method)) { |
|
| 274 | + self::$_MSG_PROCESSOR->$method(); |
|
| 275 | + } else { |
|
| 276 | + //no matching task |
|
| 277 | + /** |
|
| 278 | + * trigger error so this gets in the error logs. This is important because it happens on a non user request. |
|
| 279 | + */ |
|
| 280 | + trigger_error(esc_attr(sprintf(__('There is no task corresponding to this route %s', 'event_espresso'), |
|
| 281 | + $cron_type))); |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + do_action('FHEE__EED_Messages__run_cron__end'); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * This is used to retrieve the template pack for the given name. |
|
| 291 | + * Retrieved packs are cached on the static $_TMP_PACKS array. If there is no class matching the given name then |
|
| 292 | + * the default template pack is returned. |
|
| 293 | + * |
|
| 294 | + * @deprecated 4.9.0 @see EEH_MSG_Template::get_template_pack() |
|
| 295 | + * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used |
|
| 296 | + * in generating the Pack class name). |
|
| 297 | + * @return EE_Messages_Template_Pack |
|
| 298 | + */ |
|
| 299 | + public static function get_template_pack($template_pack_name) |
|
| 300 | + { |
|
| 301 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 302 | + return EEH_MSG_Template::get_template_pack($template_pack_name); |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * Retrieves an array of all template packs. |
|
| 308 | + * Array is in the format array( 'dbref' => EE_Messages_Template_Pack ) |
|
| 309 | + * |
|
| 310 | + * @deprecated 4.9.0 @see EEH_MSG_Template_Pack::get_template_pack_collection |
|
| 311 | + * @return EE_Messages_Template_Pack[] |
|
| 312 | + */ |
|
| 313 | + public static function get_template_packs() |
|
| 314 | + { |
|
| 315 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 316 | + |
|
| 317 | + //for backward compat, let's make sure this returns in the same format as originally. |
|
| 318 | + $template_pack_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 319 | + $template_pack_collection->rewind(); |
|
| 320 | + $template_packs = array(); |
|
| 321 | + while ($template_pack_collection->valid()) { |
|
| 322 | + $template_packs[$template_pack_collection->current()->dbref] = $template_pack_collection->current(); |
|
| 323 | + $template_pack_collection->next(); |
|
| 324 | + } |
|
| 325 | + return $template_packs; |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + |
|
| 329 | + /** |
|
| 330 | + * This simply makes sure the autoloaders are registered for the EE_messages system. |
|
| 331 | + * |
|
| 332 | + * @since 4.5.0 |
|
| 333 | + * @return void |
|
| 334 | + */ |
|
| 335 | + public static function set_autoloaders() |
|
| 336 | + { |
|
| 337 | + if (empty(self::$_MSG_PATHS)) { |
|
| 338 | + self::_set_messages_paths(); |
|
| 339 | + foreach (self::$_MSG_PATHS as $path) { |
|
| 340 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path); |
|
| 341 | + } |
|
| 342 | + // add aliases |
|
| 343 | + EEH_Autoloader::add_alias('EE_messages', 'EE_messages'); |
|
| 344 | + EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger'); |
|
| 345 | + } |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + |
|
| 349 | + /** |
|
| 350 | + * Take care of adding all the paths for the messages components to the $_MSG_PATHS property |
|
| 351 | + * for use by the Messages Autoloaders |
|
| 352 | + * |
|
| 353 | + * @since 4.5.0 |
|
| 354 | + * @return void. |
|
| 355 | + */ |
|
| 356 | + protected static function _set_messages_paths() |
|
| 357 | + { |
|
| 358 | + $dir_ref = array( |
|
| 359 | + 'messages/message_type', |
|
| 360 | + 'messages/messenger', |
|
| 361 | + 'messages/defaults', |
|
| 362 | + 'messages/defaults/email', |
|
| 363 | + 'messages/data_class', |
|
| 364 | + 'messages/validators', |
|
| 365 | + 'messages/validators/email', |
|
| 366 | + 'messages/validators/html', |
|
| 367 | + 'shortcodes', |
|
| 368 | + ); |
|
| 369 | + $paths = array(); |
|
| 370 | + foreach ($dir_ref as $index => $dir) { |
|
| 371 | + $paths[$index] = EE_LIBRARIES . $dir; |
|
| 372 | + } |
|
| 373 | + self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths); |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + |
|
| 377 | + /** |
|
| 378 | + * Takes care of loading dependencies |
|
| 379 | + * |
|
| 380 | + * @since 4.5.0 |
|
| 381 | + * @return void |
|
| 382 | + */ |
|
| 383 | + protected static function _load_controller() |
|
| 384 | + { |
|
| 385 | + if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
| 386 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
| 387 | + self::set_autoloaders(); |
|
| 388 | + self::$_EEMSG = EE_Registry::instance()->load_lib('messages'); |
|
| 389 | + self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
| 390 | + self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 391 | + } |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + |
|
| 395 | + /** |
|
| 396 | + * @param EE_Transaction $transaction |
|
| 397 | + */ |
|
| 398 | + public static function payment_reminder(EE_Transaction $transaction) |
|
| 399 | + { |
|
| 400 | + self::_load_controller(); |
|
| 401 | + $data = array($transaction, null); |
|
| 402 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data); |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + |
|
| 406 | + /** |
|
| 407 | + * Any messages triggers for after successful gateway payments should go in here. |
|
| 408 | + * |
|
| 409 | + * @param EE_Transaction object |
|
| 410 | + * @param EE_Payment object |
|
| 411 | + * @return void |
|
| 412 | + */ |
|
| 413 | + public static function payment(EE_Transaction $transaction, EE_Payment $payment) |
|
| 414 | + { |
|
| 415 | + self::_load_controller(); |
|
| 416 | + $data = array($transaction, $payment); |
|
| 417 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 418 | + $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
| 419 | + //if payment amount is less than 0 then switch to payment_refund message type. |
|
| 420 | + $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
| 421 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + |
|
| 425 | + /** |
|
| 426 | + * @param EE_Transaction $transaction |
|
| 427 | + */ |
|
| 428 | + public static function cancelled_registration(EE_Transaction $transaction) |
|
| 429 | + { |
|
| 430 | + self::_load_controller(); |
|
| 431 | + $data = array($transaction, null); |
|
| 432 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data); |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + |
|
| 436 | + /** |
|
| 437 | + * Trigger for Registration messages |
|
| 438 | + * Note that what registration message type is sent depends on what the reg status is for the registrations on the |
|
| 439 | + * incoming transaction. |
|
| 440 | + * |
|
| 441 | + * @param EE_Registration $registration |
|
| 442 | + * @param array $extra_details |
|
| 443 | + * @return void |
|
| 444 | + */ |
|
| 445 | + public static function maybe_registration(EE_Registration $registration, $extra_details = array()) |
|
| 446 | + { |
|
| 447 | + |
|
| 448 | + if (! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
| 449 | + //no messages please |
|
| 450 | + return; |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + |
|
| 454 | + //get all registrations so we make sure we send messages for the right status. |
|
| 455 | + $all_registrations = $registration->transaction()->registrations(); |
|
| 456 | + |
|
| 457 | + //cached array of statuses so we only trigger messages once per status. |
|
| 458 | + $statuses_sent = array(); |
|
| 459 | + self::_load_controller(); |
|
| 460 | + $mtgs = array(); |
|
| 461 | + |
|
| 462 | + //loop through registrations and trigger messages once per status. |
|
| 463 | + foreach ($all_registrations as $reg) { |
|
| 464 | + |
|
| 465 | + //already triggered? |
|
| 466 | + if (in_array($reg->status_ID(), $statuses_sent)) { |
|
| 467 | + continue; |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID()); |
|
| 471 | + $mtgs = array_merge( |
|
| 472 | + $mtgs, |
|
| 473 | + self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
| 474 | + $message_type, |
|
| 475 | + array($registration->transaction(), null, $reg->status_ID()) |
|
| 476 | + ) |
|
| 477 | + ); |
|
| 478 | + $statuses_sent[] = $reg->status_ID(); |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + if (count($statuses_sent) > 1) { |
|
| 482 | + $mtgs = array_merge( |
|
| 483 | + $mtgs, |
|
| 484 | + self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
| 485 | + 'registration_summary', |
|
| 486 | + array($registration->transaction(), null) |
|
| 487 | + ) |
|
| 488 | + ); |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + //batch queue and initiate request |
|
| 492 | + self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs); |
|
| 493 | + self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + |
|
| 497 | + /** |
|
| 498 | + * This is a helper method used to very whether a registration notification should be sent or |
|
| 499 | + * not. Prevents duplicate notifications going out for registration context notifications. |
|
| 500 | + * |
|
| 501 | + * @param EE_Registration $registration [description] |
|
| 502 | + * @param array $extra_details [description] |
|
| 503 | + * @return bool true = send away, false = nope halt the presses. |
|
| 504 | + */ |
|
| 505 | + protected static function _verify_registration_notification_send( |
|
| 506 | + EE_Registration $registration, |
|
| 507 | + $extra_details = array() |
|
| 508 | + ) { |
|
| 509 | + //self::log( |
|
| 510 | + // __CLASS__, __FUNCTION__, __LINE__, |
|
| 511 | + // $registration->transaction(), |
|
| 512 | + // array( '$extra_details' => $extra_details ) |
|
| 513 | + //); |
|
| 514 | + // currently only using this to send messages for the primary registrant |
|
| 515 | + if (! $registration->is_primary_registrant()) { |
|
| 516 | + return false; |
|
| 517 | + } |
|
| 518 | + // first we check if we're in admin and not doing front ajax |
|
| 519 | + if (is_admin() && ! EE_FRONT_AJAX) { |
|
| 520 | + //make sure appropriate admin params are set for sending messages |
|
| 521 | + if (empty($_REQUEST['txn_reg_status_change']['send_notifications']) || ! absint($_REQUEST['txn_reg_status_change']['send_notifications'])) { |
|
| 522 | + //no messages sent please. |
|
| 523 | + return false; |
|
| 524 | + } |
|
| 525 | + } else { |
|
| 526 | + // frontend request (either regular or via AJAX) |
|
| 527 | + // TXN is NOT finalized ? |
|
| 528 | + if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
| 529 | + return false; |
|
| 530 | + } |
|
| 531 | + // return visit but nothing changed ??? |
|
| 532 | + if ( |
|
| 533 | + isset($extra_details['revisit'], $extra_details['status_updates']) && |
|
| 534 | + $extra_details['revisit'] && ! $extra_details['status_updates'] |
|
| 535 | + ) { |
|
| 536 | + return false; |
|
| 537 | + } |
|
| 538 | + // NOT sending messages && reg status is something other than "Not-Approved" |
|
| 539 | + if ( |
|
| 540 | + ! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) && |
|
| 541 | + $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
| 542 | + ) { |
|
| 543 | + return false; |
|
| 544 | + } |
|
| 545 | + } |
|
| 546 | + // release the kraken |
|
| 547 | + return true; |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + |
|
| 551 | + /** |
|
| 552 | + * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that |
|
| 553 | + * status id. |
|
| 554 | + * |
|
| 555 | + * @deprecated 4.9.0 Use EEH_MSG_Template::reg_status_to_message_type_array() |
|
| 556 | + * or EEH_MSG_Template::convert_reg_status_to_message_type |
|
| 557 | + * @param string $reg_status |
|
| 558 | + * @return array |
|
| 559 | + */ |
|
| 560 | + protected static function _get_reg_status_array($reg_status = '') |
|
| 561 | + { |
|
| 562 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 563 | + return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
| 564 | + ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
| 565 | + : EEH_MSG_Template::reg_status_to_message_type_array(); |
|
| 566 | + } |
|
| 567 | + |
|
| 568 | + |
|
| 569 | + /** |
|
| 570 | + * Simply returns the payment message type for the given payment status. |
|
| 571 | + * |
|
| 572 | + * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array |
|
| 573 | + * or EEH_MSG_Template::convert_payment_status_to_message_type |
|
| 574 | + * @param string $payment_status The payment status being matched. |
|
| 575 | + * @return string|bool The payment message type slug matching the status or false if no match. |
|
| 576 | + */ |
|
| 577 | + protected static function _get_payment_message_type($payment_status) |
|
| 578 | + { |
|
| 579 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 580 | + return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
| 581 | + ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
| 582 | + : false; |
|
| 583 | + } |
|
| 584 | + |
|
| 585 | + |
|
| 586 | + /** |
|
| 587 | + * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
| 588 | + * |
|
| 589 | + * @access public |
|
| 590 | + * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages |
|
| 591 | + * @return bool success/fail |
|
| 592 | + */ |
|
| 593 | + public static function process_resend($req_data) |
|
| 594 | + { |
|
| 595 | + self::_load_controller(); |
|
| 596 | + |
|
| 597 | + //if $msgID in this request then skip to the new resend_message |
|
| 598 | + if (EE_Registry::instance()->REQ->get('MSG_ID')) { |
|
| 599 | + return self::resend_message(); |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + //make sure any incoming request data is set on the REQ so that it gets picked up later. |
|
| 603 | + $req_data = (array)$req_data; |
|
| 604 | + foreach ($req_data as $request_key => $request_value) { |
|
| 605 | + EE_Registry::instance()->REQ->set($request_key, $request_value); |
|
| 606 | + } |
|
| 607 | + |
|
| 608 | + if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()) { |
|
| 609 | + return false; |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + try { |
|
| 613 | + self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send); |
|
| 614 | + self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
| 615 | + } catch (EE_Error $e) { |
|
| 616 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 617 | + return false; |
|
| 618 | + } |
|
| 619 | + EE_Error::add_success( |
|
| 620 | + __('Messages have been successfully queued for generation and sending.', 'event_espresso') |
|
| 621 | + ); |
|
| 622 | + return true; //everything got queued. |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + |
|
| 626 | + /** |
|
| 627 | + * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
| 628 | + * |
|
| 629 | + * @return bool |
|
| 630 | + */ |
|
| 631 | + public static function resend_message() |
|
| 632 | + { |
|
| 633 | + self::_load_controller(); |
|
| 634 | + |
|
| 635 | + $msgID = EE_Registry::instance()->REQ->get('MSG_ID'); |
|
| 636 | + if (! $msgID) { |
|
| 637 | + EE_Error::add_error(__('Something went wrong because there is no "MSG_ID" value in the request', |
|
| 638 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 639 | + return false; |
|
| 640 | + } |
|
| 641 | + |
|
| 642 | + self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array)$msgID); |
|
| 643 | + |
|
| 644 | + //setup success message. |
|
| 645 | + $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
| 646 | + EE_Error::add_success(sprintf( |
|
| 647 | + _n( |
|
| 648 | + 'There was %d message queued for resending.', |
|
| 649 | + 'There were %d messages queued for resending.', |
|
| 650 | + $count_ready_for_resend, |
|
| 651 | + 'event_espresso' |
|
| 652 | + ), |
|
| 653 | + $count_ready_for_resend |
|
| 654 | + )); |
|
| 655 | + return true; |
|
| 656 | + } |
|
| 657 | + |
|
| 658 | + |
|
| 659 | + /** |
|
| 660 | + * Message triggers for manual payment applied by admin |
|
| 661 | + * |
|
| 662 | + * @param EE_Payment $payment EE_payment object |
|
| 663 | + * @return bool success/fail |
|
| 664 | + */ |
|
| 665 | + public static function process_admin_payment(EE_Payment $payment) |
|
| 666 | + { |
|
| 667 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 668 | + //we need to get the transaction object |
|
| 669 | + $transaction = $payment->transaction(); |
|
| 670 | + if ($transaction instanceof EE_Transaction) { |
|
| 671 | + $data = array($transaction, $payment); |
|
| 672 | + $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
| 673 | + |
|
| 674 | + //if payment amount is less than 0 then switch to payment_refund message type. |
|
| 675 | + $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
| 676 | + |
|
| 677 | + //if payment_refund is selected, but the status is NOT accepted. Then change message type to false so NO message notification goes out. |
|
| 678 | + $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved ? false : $message_type; |
|
| 679 | + |
|
| 680 | + self::_load_controller(); |
|
| 681 | + |
|
| 682 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
| 683 | + |
|
| 684 | + //get count of queued for generation |
|
| 685 | + $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(array( |
|
| 686 | + EEM_Message::status_incomplete, |
|
| 687 | + EEM_Message::status_idle, |
|
| 688 | + )); |
|
| 689 | + |
|
| 690 | + if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) { |
|
| 691 | + add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
| 692 | + return true; |
|
| 693 | + } else { |
|
| 694 | + $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::instance()->stati_indicating_failed_sending()); |
|
| 695 | + /** |
|
| 696 | + * Verify that there are actually errors. If not then we return a success message because the queue might have been emptied due to successful |
|
| 697 | + * IMMEDIATE generation. |
|
| 698 | + */ |
|
| 699 | + if ($count_failed > 0) { |
|
| 700 | + EE_Error::add_error(sprintf( |
|
| 701 | + _n( |
|
| 702 | + 'The payment notification generation failed.', |
|
| 703 | + '%d payment notifications failed being sent.', |
|
| 704 | + $count_failed, |
|
| 705 | + 'event_espresso' |
|
| 706 | + ), |
|
| 707 | + $count_failed |
|
| 708 | + ), __FILE__, __FUNCTION__, __LINE__); |
|
| 709 | + |
|
| 710 | + return false; |
|
| 711 | + } else { |
|
| 712 | + add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
| 713 | + return true; |
|
| 714 | + } |
|
| 715 | + } |
|
| 716 | + } else { |
|
| 717 | + EE_Error::add_error( |
|
| 718 | + 'Unable to generate the payment notification because the given value for the transaction is invalid.', |
|
| 719 | + 'event_espresso' |
|
| 720 | + ); |
|
| 721 | + return false; |
|
| 722 | + } |
|
| 723 | + } |
|
| 724 | + |
|
| 725 | + |
|
| 726 | + /** |
|
| 727 | + * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger |
|
| 728 | + * |
|
| 729 | + * @since 4.3.0 |
|
| 730 | + * @param EE_Registration[] $registrations an array of EE_Registration objects |
|
| 731 | + * @param int $grp_id a specific message template group id. |
|
| 732 | + * @return void |
|
| 733 | + */ |
|
| 734 | + public static function send_newsletter_message($registrations, $grp_id) |
|
| 735 | + { |
|
| 736 | + //make sure mtp is id and set it in the EE_Request Handler later messages setup. |
|
| 737 | + EE_Registry::instance()->REQ->set('GRP_ID', (int)$grp_id); |
|
| 738 | + self::_load_controller(); |
|
| 739 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations); |
|
| 740 | + } |
|
| 741 | + |
|
| 742 | + |
|
| 743 | + /** |
|
| 744 | + * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url |
|
| 745 | + * |
|
| 746 | + * @since 4.3.0 |
|
| 747 | + * @param string $registration_message_trigger_url |
|
| 748 | + * @param EE_Registration $registration |
|
| 749 | + * @param string $messenger |
|
| 750 | + * @param string $message_type |
|
| 751 | + * @return string |
|
| 752 | + */ |
|
| 753 | + public static function registration_message_trigger_url( |
|
| 754 | + $registration_message_trigger_url, |
|
| 755 | + EE_Registration $registration, |
|
| 756 | + $messenger = 'html', |
|
| 757 | + $message_type = 'invoice' |
|
| 758 | + ) { |
|
| 759 | + // whitelist $messenger |
|
| 760 | + switch ($messenger) { |
|
| 761 | + case 'pdf' : |
|
| 762 | + $sending_messenger = 'pdf'; |
|
| 763 | + $generating_messenger = 'html'; |
|
| 764 | + break; |
|
| 765 | + case 'html' : |
|
| 766 | + default : |
|
| 767 | + $sending_messenger = 'html'; |
|
| 768 | + $generating_messenger = 'html'; |
|
| 769 | + break; |
|
| 770 | + } |
|
| 771 | + // whitelist $message_type |
|
| 772 | + switch ($message_type) { |
|
| 773 | + case 'receipt' : |
|
| 774 | + $message_type = 'receipt'; |
|
| 775 | + break; |
|
| 776 | + case 'invoice' : |
|
| 777 | + default : |
|
| 778 | + $message_type = 'invoice'; |
|
| 779 | + break; |
|
| 780 | + } |
|
| 781 | + // verify that both the messenger AND the message type are active |
|
| 782 | + if (EEH_MSG_Template::is_messenger_active($sending_messenger) && EEH_MSG_Template::is_mt_active($message_type)) { |
|
| 783 | + //need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?) |
|
| 784 | + $template_query_params = array( |
|
| 785 | + 'MTP_is_active' => true, |
|
| 786 | + 'MTP_messenger' => $generating_messenger, |
|
| 787 | + 'MTP_message_type' => $message_type, |
|
| 788 | + 'Event.EVT_ID' => $registration->event_ID(), |
|
| 789 | + ); |
|
| 790 | + //get the message template group. |
|
| 791 | + $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
| 792 | + //if we don't have an EE_Message_Template_Group then return |
|
| 793 | + if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 794 | + // remove EVT_ID from query params so that global templates get picked up |
|
| 795 | + unset($template_query_params['Event.EVT_ID']); |
|
| 796 | + //get global template as the fallback |
|
| 797 | + $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
| 798 | + } |
|
| 799 | + //if we don't have an EE_Message_Template_Group then return |
|
| 800 | + if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 801 | + return ''; |
|
| 802 | + } |
|
| 803 | + // generate the URL |
|
| 804 | + $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger( |
|
| 805 | + $sending_messenger, |
|
| 806 | + $generating_messenger, |
|
| 807 | + 'purchaser', |
|
| 808 | + $message_type, |
|
| 809 | + $registration, |
|
| 810 | + $msg_template_group->ID(), |
|
| 811 | + $registration->transaction_ID() |
|
| 812 | + ); |
|
| 813 | + |
|
| 814 | + } |
|
| 815 | + return $registration_message_trigger_url; |
|
| 816 | + } |
|
| 817 | + |
|
| 818 | + |
|
| 819 | + /** |
|
| 820 | + * Use to generate and return a message preview! |
|
| 821 | + * |
|
| 822 | + * @param string $type This should correspond with a valid message type |
|
| 823 | + * @param string $context This should correspond with a valid context for the message type |
|
| 824 | + * @param string $messenger This should correspond with a valid messenger. |
|
| 825 | + * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular |
|
| 826 | + * preview |
|
| 827 | + * @return bool|string The body of the message or if send is requested, sends. |
|
| 828 | + * @throws EE_Error |
|
| 829 | + */ |
|
| 830 | + public static function preview_message($type, $context, $messenger, $send = false) |
|
| 831 | + { |
|
| 832 | + self::_load_controller(); |
|
| 833 | + $mtg = new EE_Message_To_Generate( |
|
| 834 | + $messenger, |
|
| 835 | + $type, |
|
| 836 | + array(), |
|
| 837 | + $context, |
|
| 838 | + true |
|
| 839 | + ); |
|
| 840 | + $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send); |
|
| 841 | + if ($generated_preview_queue instanceof EE_Messages_Queue) { |
|
| 842 | + //loop through all content for the preview and remove any persisted records. |
|
| 843 | + $content = ''; |
|
| 844 | + foreach ($generated_preview_queue->get_message_repository() as $message) { |
|
| 845 | + $content = $message->content(); |
|
| 846 | + if ($message->ID() > 0 && $message->STS_ID() !== EEM_Message::status_failed) { |
|
| 847 | + $message->delete(); |
|
| 848 | + } |
|
| 849 | + } |
|
| 850 | + return $content; |
|
| 851 | + } else { |
|
| 852 | + return $generated_preview_queue; |
|
| 853 | + } |
|
| 854 | + } |
|
| 855 | + |
|
| 856 | + |
|
| 857 | + /** |
|
| 858 | + * This is a method that allows for sending a message using a messenger matching the string given and the provided |
|
| 859 | + * EE_Message_Queue object. The EE_Message_Queue object is used to create a single aggregate EE_Message via the |
|
| 860 | + * content found in the EE_Message objects in the queue. |
|
| 861 | + * |
|
| 862 | + * @since 4.9.0 |
|
| 863 | + * @param string $messenger a string matching a valid active messenger in the system |
|
| 864 | + * @param string $message_type Although it seems contrary to the name of the method, a message |
|
| 865 | + * type name is still required to send along the message type to the |
|
| 866 | + * messenger because this is used for determining what specific |
|
| 867 | + * variations might be loaded for the generated message. |
|
| 868 | + * @param EE_Messages_Queue $queue |
|
| 869 | + * @param string $custom_subject Can be used to set what the custom subject string will be on the |
|
| 870 | + * aggregate EE_Message object. |
|
| 871 | + * @return bool success or fail. |
|
| 872 | + */ |
|
| 873 | + public static function send_message_with_messenger_only( |
|
| 874 | + $messenger, |
|
| 875 | + $message_type, |
|
| 876 | + EE_Messages_Queue $queue, |
|
| 877 | + $custom_subject = '' |
|
| 878 | + ) { |
|
| 879 | + self::_load_controller(); |
|
| 880 | + /** @type EE_Message_To_Generate_From_Queue $message_to_generate */ |
|
| 881 | + $message_to_generate = EE_Registry::instance()->load_lib( |
|
| 882 | + 'Message_To_Generate_From_Queue', |
|
| 883 | + array( |
|
| 884 | + $messenger, |
|
| 885 | + $message_type, |
|
| 886 | + $queue, |
|
| 887 | + $custom_subject, |
|
| 888 | + ) |
|
| 889 | + ); |
|
| 890 | + return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate); |
|
| 891 | + } |
|
| 892 | + |
|
| 893 | + |
|
| 894 | + /** |
|
| 895 | + * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation) |
|
| 896 | + * |
|
| 897 | + * @since 4.9.0 |
|
| 898 | + * @param array $message_ids An array of message ids |
|
| 899 | + * @return bool | EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated |
|
| 900 | + * messages. |
|
| 901 | + */ |
|
| 902 | + public static function generate_now($message_ids) |
|
| 903 | + { |
|
| 904 | + self::_load_controller(); |
|
| 905 | + $messages = EEM_Message::instance()->get_all( |
|
| 906 | + array( |
|
| 907 | + 0 => array( |
|
| 908 | + 'MSG_ID' => array('IN', $message_ids), |
|
| 909 | + 'STS_ID' => EEM_Message::status_incomplete, |
|
| 910 | + ), |
|
| 911 | + ) |
|
| 912 | + ); |
|
| 913 | + $generated_queue = false; |
|
| 914 | + if ($messages) { |
|
| 915 | + $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages); |
|
| 916 | + } |
|
| 917 | + |
|
| 918 | + if (! $generated_queue instanceof EE_Messages_Queue) { |
|
| 919 | + EE_Error::add_error( |
|
| 920 | + __('The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.', |
|
| 921 | + 'event_espresso'), |
|
| 922 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 923 | + ); |
|
| 924 | + } |
|
| 925 | + return $generated_queue; |
|
| 926 | + } |
|
| 927 | + |
|
| 928 | + |
|
| 929 | + /** |
|
| 930 | + * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or, |
|
| 931 | + * EEM_Message::status_idle |
|
| 932 | + * |
|
| 933 | + * @since 4.9.0 |
|
| 934 | + * @param $message_ids |
|
| 935 | + * @return bool | EE_Messages_Queue false if no messages sent. |
|
| 936 | + */ |
|
| 937 | + public static function send_now($message_ids) |
|
| 938 | + { |
|
| 939 | + self::_load_controller(); |
|
| 940 | + $messages = EEM_Message::instance()->get_all( |
|
| 941 | + array( |
|
| 942 | + 0 => array( |
|
| 943 | + 'MSG_ID' => array('IN', $message_ids), |
|
| 944 | + 'STS_ID' => array( |
|
| 945 | + 'IN', |
|
| 946 | + array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry), |
|
| 947 | + ), |
|
| 948 | + ), |
|
| 949 | + ) |
|
| 950 | + ); |
|
| 951 | + $sent_queue = false; |
|
| 952 | + if ($messages) { |
|
| 953 | + $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages); |
|
| 954 | + } |
|
| 955 | + |
|
| 956 | + if (! $sent_queue instanceof EE_Messages_Queue) { |
|
| 957 | + EE_Error::add_error( |
|
| 958 | + __('The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', |
|
| 959 | + 'event_espresso'), |
|
| 960 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 961 | + ); |
|
| 962 | + } else { |
|
| 963 | + //can count how many sent by using the messages in the queue |
|
| 964 | + $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent()); |
|
| 965 | + if ($sent_count > 0) { |
|
| 966 | + EE_Error::add_success( |
|
| 967 | + sprintf( |
|
| 968 | + _n( |
|
| 969 | + 'There was %d message successfully sent.', |
|
| 970 | + 'There were %d messages successfully sent.', |
|
| 971 | + $sent_count, |
|
| 972 | + 'event_espresso' |
|
| 973 | + ), |
|
| 974 | + $sent_count |
|
| 975 | + ) |
|
| 976 | + ); |
|
| 977 | + } else { |
|
| 978 | + EE_Error::overwrite_errors(); |
|
| 979 | + EE_Error::add_error( |
|
| 980 | + __('No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error. |
|
| 981 | 981 | If there was an error, you can look at the messages in the message activity list table for any error messages.', |
| 982 | - 'event_espresso'), |
|
| 983 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 984 | - ); |
|
| 985 | - } |
|
| 986 | - } |
|
| 987 | - return $sent_queue; |
|
| 988 | - } |
|
| 989 | - |
|
| 990 | - |
|
| 991 | - /** |
|
| 992 | - * This will queue the incoming message ids for resending. |
|
| 993 | - * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued. |
|
| 994 | - * |
|
| 995 | - * @since 4.9.0 |
|
| 996 | - * @param array $message_ids An array of EE_Message IDs |
|
| 997 | - * @return bool true means messages were successfully queued for resending, false means none were queued for |
|
| 998 | - * resending. |
|
| 999 | - */ |
|
| 1000 | - public static function queue_for_resending($message_ids) |
|
| 1001 | - { |
|
| 1002 | - self::_load_controller(); |
|
| 1003 | - self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids); |
|
| 1004 | - |
|
| 1005 | - //get queue and count |
|
| 1006 | - $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
| 1007 | - |
|
| 1008 | - if ( |
|
| 1009 | - $queue_count > 0 |
|
| 1010 | - ) { |
|
| 1011 | - EE_Error::add_success( |
|
| 1012 | - sprintf( |
|
| 1013 | - _n( |
|
| 1014 | - '%d message successfully queued for resending.', |
|
| 1015 | - '%d messages successfully queued for resending.', |
|
| 1016 | - $queue_count, |
|
| 1017 | - 'event_espresso' |
|
| 1018 | - ), |
|
| 1019 | - $queue_count |
|
| 1020 | - ) |
|
| 1021 | - ); |
|
| 1022 | - /** |
|
| 1023 | - * @see filter usage in EE_Messages_Queue::initiate_request_by_priority |
|
| 1024 | - */ |
|
| 1025 | - } elseif ( |
|
| 1026 | - apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true) |
|
| 1027 | - || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
| 1028 | - ) { |
|
| 1029 | - $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent); |
|
| 1030 | - if ($queue_count > 0) { |
|
| 1031 | - EE_Error::add_success( |
|
| 1032 | - sprintf( |
|
| 1033 | - _n( |
|
| 1034 | - '%d message successfully sent.', |
|
| 1035 | - '%d messages successfully sent.', |
|
| 1036 | - $queue_count, |
|
| 1037 | - 'event_espresso' |
|
| 1038 | - ), |
|
| 1039 | - $queue_count |
|
| 1040 | - ) |
|
| 1041 | - ); |
|
| 1042 | - } else { |
|
| 1043 | - EE_Error::add_error( |
|
| 1044 | - __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
| 1045 | - 'event_espresso'), |
|
| 1046 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1047 | - ); |
|
| 1048 | - } |
|
| 1049 | - } else { |
|
| 1050 | - EE_Error::add_error( |
|
| 1051 | - __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
| 1052 | - 'event_espresso'), |
|
| 1053 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1054 | - ); |
|
| 1055 | - } |
|
| 1056 | - return (bool)$queue_count; |
|
| 1057 | - } |
|
| 1058 | - |
|
| 1059 | - |
|
| 1060 | - /** |
|
| 1061 | - * debug |
|
| 1062 | - * |
|
| 1063 | - * @param string $class |
|
| 1064 | - * @param string $func |
|
| 1065 | - * @param string $line |
|
| 1066 | - * @param \EE_Transaction $transaction |
|
| 1067 | - * @param array $info |
|
| 1068 | - * @param bool $display_request |
|
| 1069 | - */ |
|
| 1070 | - protected static function log( |
|
| 1071 | - $class = '', |
|
| 1072 | - $func = '', |
|
| 1073 | - $line = '', |
|
| 1074 | - EE_Transaction $transaction, |
|
| 1075 | - $info = array(), |
|
| 1076 | - $display_request = false |
|
| 1077 | - ) { |
|
| 1078 | - if (WP_DEBUG && false) { |
|
| 1079 | - if ($transaction instanceof EE_Transaction) { |
|
| 1080 | - // don't serialize objects |
|
| 1081 | - $info = EEH_Debug_Tools::strip_objects($info); |
|
| 1082 | - $info['TXN_status'] = $transaction->status_ID(); |
|
| 1083 | - $info['TXN_reg_steps'] = $transaction->reg_steps(); |
|
| 1084 | - if ($transaction->ID()) { |
|
| 1085 | - $index = 'EE_Transaction: ' . $transaction->ID(); |
|
| 1086 | - EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
|
| 1087 | - } |
|
| 1088 | - } |
|
| 1089 | - } |
|
| 1090 | - |
|
| 1091 | - } |
|
| 1092 | - |
|
| 1093 | - |
|
| 1094 | - /** |
|
| 1095 | - * Resets all the static properties in this class when called. |
|
| 1096 | - */ |
|
| 1097 | - public static function reset() |
|
| 1098 | - { |
|
| 1099 | - self::$_EEMSG = null; |
|
| 1100 | - self::$_message_resource_manager = null; |
|
| 1101 | - self::$_MSG_PROCESSOR = null; |
|
| 1102 | - self::$_MSG_PATHS = null; |
|
| 1103 | - self::$_TMP_PACKS = array(); |
|
| 1104 | - } |
|
| 982 | + 'event_espresso'), |
|
| 983 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 984 | + ); |
|
| 985 | + } |
|
| 986 | + } |
|
| 987 | + return $sent_queue; |
|
| 988 | + } |
|
| 989 | + |
|
| 990 | + |
|
| 991 | + /** |
|
| 992 | + * This will queue the incoming message ids for resending. |
|
| 993 | + * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued. |
|
| 994 | + * |
|
| 995 | + * @since 4.9.0 |
|
| 996 | + * @param array $message_ids An array of EE_Message IDs |
|
| 997 | + * @return bool true means messages were successfully queued for resending, false means none were queued for |
|
| 998 | + * resending. |
|
| 999 | + */ |
|
| 1000 | + public static function queue_for_resending($message_ids) |
|
| 1001 | + { |
|
| 1002 | + self::_load_controller(); |
|
| 1003 | + self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids); |
|
| 1004 | + |
|
| 1005 | + //get queue and count |
|
| 1006 | + $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
| 1007 | + |
|
| 1008 | + if ( |
|
| 1009 | + $queue_count > 0 |
|
| 1010 | + ) { |
|
| 1011 | + EE_Error::add_success( |
|
| 1012 | + sprintf( |
|
| 1013 | + _n( |
|
| 1014 | + '%d message successfully queued for resending.', |
|
| 1015 | + '%d messages successfully queued for resending.', |
|
| 1016 | + $queue_count, |
|
| 1017 | + 'event_espresso' |
|
| 1018 | + ), |
|
| 1019 | + $queue_count |
|
| 1020 | + ) |
|
| 1021 | + ); |
|
| 1022 | + /** |
|
| 1023 | + * @see filter usage in EE_Messages_Queue::initiate_request_by_priority |
|
| 1024 | + */ |
|
| 1025 | + } elseif ( |
|
| 1026 | + apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true) |
|
| 1027 | + || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
| 1028 | + ) { |
|
| 1029 | + $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent); |
|
| 1030 | + if ($queue_count > 0) { |
|
| 1031 | + EE_Error::add_success( |
|
| 1032 | + sprintf( |
|
| 1033 | + _n( |
|
| 1034 | + '%d message successfully sent.', |
|
| 1035 | + '%d messages successfully sent.', |
|
| 1036 | + $queue_count, |
|
| 1037 | + 'event_espresso' |
|
| 1038 | + ), |
|
| 1039 | + $queue_count |
|
| 1040 | + ) |
|
| 1041 | + ); |
|
| 1042 | + } else { |
|
| 1043 | + EE_Error::add_error( |
|
| 1044 | + __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
| 1045 | + 'event_espresso'), |
|
| 1046 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1047 | + ); |
|
| 1048 | + } |
|
| 1049 | + } else { |
|
| 1050 | + EE_Error::add_error( |
|
| 1051 | + __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
| 1052 | + 'event_espresso'), |
|
| 1053 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1054 | + ); |
|
| 1055 | + } |
|
| 1056 | + return (bool)$queue_count; |
|
| 1057 | + } |
|
| 1058 | + |
|
| 1059 | + |
|
| 1060 | + /** |
|
| 1061 | + * debug |
|
| 1062 | + * |
|
| 1063 | + * @param string $class |
|
| 1064 | + * @param string $func |
|
| 1065 | + * @param string $line |
|
| 1066 | + * @param \EE_Transaction $transaction |
|
| 1067 | + * @param array $info |
|
| 1068 | + * @param bool $display_request |
|
| 1069 | + */ |
|
| 1070 | + protected static function log( |
|
| 1071 | + $class = '', |
|
| 1072 | + $func = '', |
|
| 1073 | + $line = '', |
|
| 1074 | + EE_Transaction $transaction, |
|
| 1075 | + $info = array(), |
|
| 1076 | + $display_request = false |
|
| 1077 | + ) { |
|
| 1078 | + if (WP_DEBUG && false) { |
|
| 1079 | + if ($transaction instanceof EE_Transaction) { |
|
| 1080 | + // don't serialize objects |
|
| 1081 | + $info = EEH_Debug_Tools::strip_objects($info); |
|
| 1082 | + $info['TXN_status'] = $transaction->status_ID(); |
|
| 1083 | + $info['TXN_reg_steps'] = $transaction->reg_steps(); |
|
| 1084 | + if ($transaction->ID()) { |
|
| 1085 | + $index = 'EE_Transaction: ' . $transaction->ID(); |
|
| 1086 | + EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
|
| 1087 | + } |
|
| 1088 | + } |
|
| 1089 | + } |
|
| 1090 | + |
|
| 1091 | + } |
|
| 1092 | + |
|
| 1093 | + |
|
| 1094 | + /** |
|
| 1095 | + * Resets all the static properties in this class when called. |
|
| 1096 | + */ |
|
| 1097 | + public static function reset() |
|
| 1098 | + { |
|
| 1099 | + self::$_EEMSG = null; |
|
| 1100 | + self::$_message_resource_manager = null; |
|
| 1101 | + self::$_MSG_PROCESSOR = null; |
|
| 1102 | + self::$_MSG_PATHS = null; |
|
| 1103 | + self::$_TMP_PACKS = array(); |
|
| 1104 | + } |
|
| 1105 | 1105 | |
| 1106 | 1106 | } |
| 1107 | 1107 | // End of file EED_Messages.module.php |
@@ -656,8 +656,8 @@ discard block |
||
| 656 | 656 | } |
| 657 | 657 | |
| 658 | 658 | //reset contexts and addressees |
| 659 | - $this->_contexts = $original_contexts; |
|
| 660 | - $this->_addressees = array(); |
|
| 659 | + $this->_contexts = $original_contexts; |
|
| 660 | + $this->_addressees = array(); |
|
| 661 | 661 | return $addressees; |
| 662 | 662 | } |
| 663 | 663 | |
@@ -874,8 +874,8 @@ discard block |
||
| 874 | 874 | //set the attendee array to blank on each loop; |
| 875 | 875 | $aee = array(); |
| 876 | 876 | if ( isset( $this->_data->reg_obj ) |
| 877 | - && ( $this->_data->reg_obj->attendee_ID() != $att_id ) |
|
| 878 | - && $this->_single_message |
|
| 877 | + && ( $this->_data->reg_obj->attendee_ID() != $att_id ) |
|
| 878 | + && $this->_single_message |
|
| 879 | 879 | ) { |
| 880 | 880 | continue; |
| 881 | 881 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 3 | - exit( 'NO direct script access allowed' ); |
|
| 2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 3 | + exit('NO direct script access allowed'); |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | * EE_Base_Class_Object |
| 280 | 280 | * @return mixed ( EE_Base_Class||EE_Base_Class[] ) |
| 281 | 281 | */ |
| 282 | - abstract protected function _get_data_for_context( $context, EE_Registration $registration, $id ); |
|
| 282 | + abstract protected function _get_data_for_context($context, EE_Registration $registration, $id); |
|
| 283 | 283 | |
| 284 | 284 | |
| 285 | 285 | |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | * @deprecated 4.9.0 |
| 307 | 307 | * @return int |
| 308 | 308 | */ |
| 309 | - protected function _get_id_for_msg_url( $context, EE_Registration $registration ) { |
|
| 309 | + protected function _get_id_for_msg_url($context, EE_Registration $registration) { |
|
| 310 | 310 | return 0; |
| 311 | 311 | } |
| 312 | 312 | |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | * sending. |
| 336 | 336 | * @since 4.9.0 |
| 337 | 337 | */ |
| 338 | - public function do_messenger_hooks( $messenger = null ) { |
|
| 338 | + public function do_messenger_hooks($messenger = null) { |
|
| 339 | 339 | $this->_active_messenger = $messenger; |
| 340 | 340 | $this->_do_messenger_hooks(); |
| 341 | 341 | } |
@@ -384,10 +384,10 @@ discard block |
||
| 384 | 384 | * @param mixed $data This sets the data property for the message type with the incoming data used for generating. |
| 385 | 385 | * @return string (the reference for the data handler) (will be an empty string if could not be determined). |
| 386 | 386 | */ |
| 387 | - public function get_data_handler( $data ) { |
|
| 387 | + public function get_data_handler($data) { |
|
| 388 | 388 | $this->_data = $data; |
| 389 | 389 | $this->_set_data_handler(); |
| 390 | - return apply_filters( 'FHEE__EE_message_type__get_data_handler', $this->_data_handler, $this ); |
|
| 390 | + return apply_filters('FHEE__EE_message_type__get_data_handler', $this->_data_handler, $this); |
|
| 391 | 391 | } |
| 392 | 392 | |
| 393 | 393 | |
@@ -424,26 +424,26 @@ discard block |
||
| 424 | 424 | * @deprecated 4.9.0 Likely 4.9.10 or 4.10.0 will remove this method completely |
| 425 | 425 | * @return string generated url |
| 426 | 426 | */ |
| 427 | - public function get_url_trigger( $context, $sending_messenger, EE_Registration $registration ) { |
|
| 427 | + public function get_url_trigger($context, $sending_messenger, EE_Registration $registration) { |
|
| 428 | 428 | //validate context |
| 429 | 429 | //valid context? |
| 430 | - if ( ! isset( $this->_contexts[ $context ] ) ) { |
|
| 430 | + if ( ! isset($this->_contexts[$context])) { |
|
| 431 | 431 | throw new EE_Error( |
| 432 | 432 | sprintf( |
| 433 | - __( 'The context %s is not a valid context for %s.', 'event_espresso' ), |
|
| 433 | + __('The context %s is not a valid context for %s.', 'event_espresso'), |
|
| 434 | 434 | $context, |
| 435 | - get_class( $this ) |
|
| 435 | + get_class($this) |
|
| 436 | 436 | ) |
| 437 | 437 | ); |
| 438 | 438 | } |
| 439 | 439 | //valid sending_messenger? |
| 440 | 440 | $not_valid_msgr = false; |
| 441 | - foreach ( $this->_with_messengers as $generating => $sendings ) { |
|
| 442 | - if ( empty( $sendings ) || array_search( $sending_messenger, $sendings ) === false ) { |
|
| 441 | + foreach ($this->_with_messengers as $generating => $sendings) { |
|
| 442 | + if (empty($sendings) || array_search($sending_messenger, $sendings) === false) { |
|
| 443 | 443 | $not_valid_msgr = true; |
| 444 | 444 | } |
| 445 | 445 | } |
| 446 | - if ( $not_valid_msgr ) { |
|
| 446 | + if ($not_valid_msgr) { |
|
| 447 | 447 | throw new EE_Error( |
| 448 | 448 | sprintf( |
| 449 | 449 | __( |
@@ -451,7 +451,7 @@ discard block |
||
| 451 | 451 | 'event_espresso' |
| 452 | 452 | ), |
| 453 | 453 | $sending_messenger, |
| 454 | - get_class( $this ) |
|
| 454 | + get_class($this) |
|
| 455 | 455 | ) |
| 456 | 456 | ); |
| 457 | 457 | } |
@@ -462,7 +462,7 @@ discard block |
||
| 462 | 462 | $this->name, |
| 463 | 463 | $registration, |
| 464 | 464 | $this->_GRP_ID, |
| 465 | - $this->_get_id_for_msg_url( $context, $registration ) |
|
| 465 | + $this->_get_id_for_msg_url($context, $registration) |
|
| 466 | 466 | ); |
| 467 | 467 | } |
| 468 | 468 | |
@@ -481,26 +481,26 @@ discard block |
||
| 481 | 481 | * EE_Base_Class_Object |
| 482 | 482 | * @return mixed (EE_Base_Class||EE_Base_Class[]) |
| 483 | 483 | */ |
| 484 | - public function get_data_for_context( $context, EE_Registration $registration, $id = 0 ) { |
|
| 484 | + public function get_data_for_context($context, EE_Registration $registration, $id = 0) { |
|
| 485 | 485 | //valid context? |
| 486 | - if ( ! isset( $this->_contexts[ $context ] ) ) { |
|
| 486 | + if ( ! isset($this->_contexts[$context])) { |
|
| 487 | 487 | throw new EE_Error( |
| 488 | 488 | sprintf( |
| 489 | - __( 'The context %s is not a valid context for %s.', 'event_espresso' ), |
|
| 489 | + __('The context %s is not a valid context for %s.', 'event_espresso'), |
|
| 490 | 490 | $context, |
| 491 | - get_class( $this ) |
|
| 491 | + get_class($this) |
|
| 492 | 492 | ) |
| 493 | 493 | ); |
| 494 | 494 | } |
| 495 | 495 | //get data and apply global and class specific filters on it. |
| 496 | 496 | $data = apply_filters( |
| 497 | 497 | 'FHEE__EE_message_type__get_data_for_context__data', |
| 498 | - $this->_get_data_for_context( $context, $registration, $id ), |
|
| 498 | + $this->_get_data_for_context($context, $registration, $id), |
|
| 499 | 499 | $this |
| 500 | 500 | ); |
| 501 | - $data = apply_filters( 'FHEE__' . get_class( $this ) . '__get_data_for_context__data', $data, $this ); |
|
| 501 | + $data = apply_filters('FHEE__'.get_class($this).'__get_data_for_context__data', $data, $this); |
|
| 502 | 502 | //if empty then something went wrong! |
| 503 | - if ( empty( $data ) ) { |
|
| 503 | + if (empty($data)) { |
|
| 504 | 504 | throw new EE_Error( |
| 505 | 505 | sprintf( |
| 506 | 506 | __( |
@@ -544,7 +544,7 @@ discard block |
||
| 544 | 544 | */ |
| 545 | 545 | protected function _set_with_messengers() { |
| 546 | 546 | $this->_with_messengers = array( |
| 547 | - 'email' => array( 'html' ), |
|
| 547 | + 'email' => array('html'), |
|
| 548 | 548 | ); |
| 549 | 549 | } |
| 550 | 550 | |
@@ -558,7 +558,7 @@ discard block |
||
| 558 | 558 | */ |
| 559 | 559 | public function with_messengers() { |
| 560 | 560 | return apply_filters( |
| 561 | - 'FHEE__EE_message_type__get_with_messengers__with_messengers__' . get_class( $this ), |
|
| 561 | + 'FHEE__EE_message_type__get_with_messengers__with_messengers__'.get_class($this), |
|
| 562 | 562 | $this->_with_messengers |
| 563 | 563 | ); |
| 564 | 564 | } |
@@ -585,7 +585,7 @@ discard block |
||
| 585 | 585 | $messengers = array() |
| 586 | 586 | ) { |
| 587 | 587 | //we can also further refine the context by action (if present). |
| 588 | - return $this->_get_admin_page_content( $page, $action, $extra, $messengers ); |
|
| 588 | + return $this->_get_admin_page_content($page, $action, $extra, $messengers); |
|
| 589 | 589 | } |
| 590 | 590 | |
| 591 | 591 | |
@@ -620,10 +620,10 @@ discard block |
||
| 620 | 620 | public function get_master_templates() { |
| 621 | 621 | //first class specific filter then filter that by the global filter. |
| 622 | 622 | $master_templates = apply_filters( |
| 623 | - 'FHEE__' . get_class( $this ) . '__get_master_templates', |
|
| 623 | + 'FHEE__'.get_class($this).'__get_master_templates', |
|
| 624 | 624 | $this->_master_templates |
| 625 | 625 | ); |
| 626 | - return apply_filters( 'FHEE__EE_message_type__get_master_templates', $master_templates, $this ); |
|
| 626 | + return apply_filters('FHEE__EE_message_type__get_master_templates', $master_templates, $this); |
|
| 627 | 627 | } |
| 628 | 628 | |
| 629 | 629 | |
@@ -637,21 +637,21 @@ discard block |
||
| 637 | 637 | * @return array An array indexed by context where each context is an array of EE_Messages_Addressee objects for |
| 638 | 638 | * that context |
| 639 | 639 | */ |
| 640 | - public function get_addressees( EE_Messages_incoming_data $data, $context = '' ) { |
|
| 640 | + public function get_addressees(EE_Messages_incoming_data $data, $context = '') { |
|
| 641 | 641 | //override _data |
| 642 | 642 | $this->_data = $data; |
| 643 | 643 | $addressees = array(); |
| 644 | 644 | $original_contexts = $this->_contexts; |
| 645 | 645 | //if incoming context then limit to that context |
| 646 | - if ( ! empty( $context ) ) { |
|
| 647 | - $cntxt = ! empty( $this->_contexts[ $context ] ) ? $this->_contexts[ $context ] : ''; |
|
| 648 | - if ( ! empty( $cntxt ) ) { |
|
| 646 | + if ( ! empty($context)) { |
|
| 647 | + $cntxt = ! empty($this->_contexts[$context]) ? $this->_contexts[$context] : ''; |
|
| 648 | + if ( ! empty($cntxt)) { |
|
| 649 | 649 | $this->_contexts = array(); |
| 650 | - $this->_contexts[ $context ] = $cntxt; |
|
| 650 | + $this->_contexts[$context] = $cntxt; |
|
| 651 | 651 | } |
| 652 | 652 | } |
| 653 | 653 | $this->_set_default_addressee_data(); |
| 654 | - if ( $this->_process_data() ) { |
|
| 654 | + if ($this->_process_data()) { |
|
| 655 | 655 | $addressees = $this->_addressees; |
| 656 | 656 | } |
| 657 | 657 | |
@@ -671,14 +671,14 @@ discard block |
||
| 671 | 671 | */ |
| 672 | 672 | protected function _process_data() { |
| 673 | 673 | //at a minimum, we NEED EE_Attendee objects. |
| 674 | - if ( empty( $this->_data->attendees ) ) { |
|
| 675 | - return false; //there's no data to process! |
|
| 674 | + if (empty($this->_data->attendees)) { |
|
| 675 | + return false; //there's no data to process! |
|
| 676 | 676 | } |
| 677 | 677 | // process addressees for each context. Child classes will have to have methods for |
| 678 | 678 | // each context defined to handle the processing of the data object within them |
| 679 | - foreach ( $this->_contexts as $context => $details ) { |
|
| 680 | - $xpctd_method = '_' . $context . '_addressees'; |
|
| 681 | - if ( ! method_exists( $this, $xpctd_method ) ) { |
|
| 679 | + foreach ($this->_contexts as $context => $details) { |
|
| 680 | + $xpctd_method = '_'.$context.'_addressees'; |
|
| 681 | + if ( ! method_exists($this, $xpctd_method)) { |
|
| 682 | 682 | throw new EE_Error( |
| 683 | 683 | sprintf( |
| 684 | 684 | __( |
@@ -690,7 +690,7 @@ discard block |
||
| 690 | 690 | ) |
| 691 | 691 | ); |
| 692 | 692 | } |
| 693 | - $this->_addressees[ $context ] = call_user_func( array( $this, $xpctd_method ) ); |
|
| 693 | + $this->_addressees[$context] = call_user_func(array($this, $xpctd_method)); |
|
| 694 | 694 | } |
| 695 | 695 | return true; //data was processed successfully. |
| 696 | 696 | } |
@@ -712,7 +712,7 @@ discard block |
||
| 712 | 712 | 'grand_total_line_item' => $this->_data->grand_total_line_item, |
| 713 | 713 | 'txn' => $this->_data->txn, |
| 714 | 714 | 'payments' => $this->_data->payments, |
| 715 | - 'payment' => isset( $this->_data->payment ) && $this->_data->payment instanceof EE_Payment |
|
| 715 | + 'payment' => isset($this->_data->payment) && $this->_data->payment instanceof EE_Payment |
|
| 716 | 716 | ? $this->_data->payment |
| 717 | 717 | : null, |
| 718 | 718 | 'reg_objs' => $this->_data->reg_objs, |
@@ -725,7 +725,7 @@ discard block |
||
| 725 | 725 | 'txn_status' => $this->_data->txn_status, |
| 726 | 726 | 'total_ticket_count' => $this->_data->total_ticket_count, |
| 727 | 727 | ); |
| 728 | - if ( is_array( $this->_data->primary_attendee_data ) ) { |
|
| 728 | + if (is_array($this->_data->primary_attendee_data)) { |
|
| 729 | 729 | $this->_default_addressee_data = array_merge( |
| 730 | 730 | $this->_default_addressee_data, |
| 731 | 731 | $this->_data->primary_attendee_data |
@@ -769,24 +769,24 @@ discard block |
||
| 769 | 769 | 'messenger', |
| 770 | 770 | ); |
| 771 | 771 | $contexts = $this->get_contexts(); |
| 772 | - foreach ( $contexts as $context => $details ) { |
|
| 773 | - $this->_valid_shortcodes[ $context ] = $all_shortcodes; |
|
| 772 | + foreach ($contexts as $context => $details) { |
|
| 773 | + $this->_valid_shortcodes[$context] = $all_shortcodes; |
|
| 774 | 774 | //make sure non admin context does not include the event_author shortcodes |
| 775 | - if ( $context != 'admin' ) { |
|
| 776 | - if ( ( $key = array_search( 'event_author', $this->_valid_shortcodes[ $context ] ) ) !== false ) { |
|
| 777 | - unset( $this->_valid_shortcodes[ $context ][ $key ] ); |
|
| 775 | + if ($context != 'admin') { |
|
| 776 | + if (($key = array_search('event_author', $this->_valid_shortcodes[$context])) !== false) { |
|
| 777 | + unset($this->_valid_shortcodes[$context][$key]); |
|
| 778 | 778 | } |
| 779 | 779 | } |
| 780 | 780 | } |
| 781 | 781 | // make sure admin context does not include the recipient_details shortcodes |
| 782 | 782 | // IF we have admin context hooked in message types might not have that context. |
| 783 | - if ( ! empty( $this->_valid_shortcodes['admin'] ) ) { |
|
| 784 | - if ( ( $key = array_search( 'recipient_details', $this->_valid_shortcodes['admin'] ) ) !== false ) { |
|
| 785 | - unset( $this->_valid_shortcodes['admin'][ $key ] ); |
|
| 783 | + if ( ! empty($this->_valid_shortcodes['admin'])) { |
|
| 784 | + if (($key = array_search('recipient_details', $this->_valid_shortcodes['admin'])) !== false) { |
|
| 785 | + unset($this->_valid_shortcodes['admin'][$key]); |
|
| 786 | 786 | } |
| 787 | 787 | //make sure admin context does not include the recipient_details shortcodes |
| 788 | - if ( ( $key = array_search( 'recipient_list', $this->_valid_shortcodes['admin'] ) ) !== false ) { |
|
| 789 | - unset( $this->_valid_shortcodes['admin'][ $key ] ); |
|
| 788 | + if (($key = array_search('recipient_list', $this->_valid_shortcodes['admin'])) !== false) { |
|
| 789 | + unset($this->_valid_shortcodes['admin'][$key]); |
|
| 790 | 790 | } |
| 791 | 791 | } |
| 792 | 792 | } |
@@ -799,9 +799,9 @@ discard block |
||
| 799 | 799 | * @param array $new_config array of valid shortcodes (by context) |
| 800 | 800 | * @return void sets valid_shortcodes property |
| 801 | 801 | */ |
| 802 | - public function reset_valid_shortcodes_config( $new_config ) { |
|
| 803 | - foreach ( $new_config as $context => $shortcodes ) { |
|
| 804 | - $this->_valid_shortcodes[ $context ] = $shortcodes; |
|
| 802 | + public function reset_valid_shortcodes_config($new_config) { |
|
| 803 | + foreach ($new_config as $context => $shortcodes) { |
|
| 804 | + $this->_valid_shortcodes[$context] = $shortcodes; |
|
| 805 | 805 | } |
| 806 | 806 | } |
| 807 | 807 | |
@@ -818,13 +818,13 @@ discard block |
||
| 818 | 818 | $addressees = array(); |
| 819 | 819 | // first we need to get the event admin user id for all the events |
| 820 | 820 | // and setup an addressee object for each unique admin user. |
| 821 | - foreach ( $this->_data->events as $line_ref => $event ) { |
|
| 822 | - $admin_id = $this->_get_event_admin_id( $event['ID'] ); |
|
| 821 | + foreach ($this->_data->events as $line_ref => $event) { |
|
| 822 | + $admin_id = $this->_get_event_admin_id($event['ID']); |
|
| 823 | 823 | //make sure we are just including the events that belong to this admin! |
| 824 | - $admin_events[ $admin_id ][ $line_ref ] = $event; |
|
| 824 | + $admin_events[$admin_id][$line_ref] = $event; |
|
| 825 | 825 | } |
| 826 | 826 | //k now we can loop through the event_admins and setup the addressee data. |
| 827 | - foreach ( $admin_events as $admin_id => $event_details ) { |
|
| 827 | + foreach ($admin_events as $admin_id => $event_details) { |
|
| 828 | 828 | $aee = array( |
| 829 | 829 | 'user_id' => $admin_id, |
| 830 | 830 | 'events' => $event_details, |
@@ -832,8 +832,8 @@ discard block |
||
| 832 | 832 | 'recipient_id' => $admin_id, |
| 833 | 833 | 'recipient_type' => 'WP_User', |
| 834 | 834 | ); |
| 835 | - $aee = array_merge( $this->_default_addressee_data, $aee ); |
|
| 836 | - $addressees[] = new EE_Messages_Addressee( $aee ); |
|
| 835 | + $aee = array_merge($this->_default_addressee_data, $aee); |
|
| 836 | + $addressees[] = new EE_Messages_Addressee($aee); |
|
| 837 | 837 | } |
| 838 | 838 | return $addressees; |
| 839 | 839 | } |
@@ -853,7 +853,7 @@ discard block |
||
| 853 | 853 | $aee['recipient_id'] = $aee['primary_att_obj'] instanceof EE_Attendee ? $aee['primary_att_obj']->ID() : 0; |
| 854 | 854 | $aee['recipient_type'] = 'Attendee'; |
| 855 | 855 | //great now we can instantiate the $addressee object and return (as an array); |
| 856 | - $add[] = new EE_Messages_Addressee( $aee ); |
|
| 856 | + $add[] = new EE_Messages_Addressee($aee); |
|
| 857 | 857 | return $add; |
| 858 | 858 | } |
| 859 | 859 | |
@@ -870,25 +870,25 @@ discard block |
||
| 870 | 870 | //we just have to loop through the attendees. We'll also set the attached events for each attendee. |
| 871 | 871 | //use to verify unique attendee emails... we don't want to sent multiple copies to the same attendee do we? |
| 872 | 872 | $already_processed = array(); |
| 873 | - foreach ( $this->_data->attendees as $att_id => $details ) { |
|
| 873 | + foreach ($this->_data->attendees as $att_id => $details) { |
|
| 874 | 874 | //set the attendee array to blank on each loop; |
| 875 | 875 | $aee = array(); |
| 876 | - if ( isset( $this->_data->reg_obj ) |
|
| 877 | - && ( $this->_data->reg_obj->attendee_ID() != $att_id ) |
|
| 876 | + if (isset($this->_data->reg_obj) |
|
| 877 | + && ($this->_data->reg_obj->attendee_ID() != $att_id) |
|
| 878 | 878 | && $this->_single_message |
| 879 | 879 | ) { |
| 880 | 880 | continue; |
| 881 | 881 | } |
| 882 | 882 | // is $this->_regs_for_sending present? |
| 883 | 883 | // If so, let's make sure we ONLY generate addressee for registrations in that array. |
| 884 | - if ( ! empty( $this->_regs_for_sending ) && is_array( $this->_regs_for_sending ) ) { |
|
| 885 | - $regs_allowed = array_intersect_key( array_flip( $this->_regs_for_sending ), $details['reg_objs'] ); |
|
| 886 | - if ( empty( $regs_allowed ) ) { |
|
| 884 | + if ( ! empty($this->_regs_for_sending) && is_array($this->_regs_for_sending)) { |
|
| 885 | + $regs_allowed = array_intersect_key(array_flip($this->_regs_for_sending), $details['reg_objs']); |
|
| 886 | + if (empty($regs_allowed)) { |
|
| 887 | 887 | continue; |
| 888 | 888 | } |
| 889 | 889 | } |
| 890 | 890 | if ( |
| 891 | - in_array( $details['attendee_email'], $already_processed ) |
|
| 891 | + in_array($details['attendee_email'], $already_processed) |
|
| 892 | 892 | && apply_filters( |
| 893 | 893 | 'FHEE__EE_message_type___attendee_addressees__prevent_duplicate_email_sends', |
| 894 | 894 | true, |
@@ -899,14 +899,14 @@ discard block |
||
| 899 | 899 | continue; |
| 900 | 900 | } |
| 901 | 901 | $already_processed[] = $details['attendee_email']; |
| 902 | - foreach ( $details as $item => $value ) { |
|
| 903 | - $aee[ $item ] = $value; |
|
| 904 | - if ( $item == 'line_ref' ) { |
|
| 905 | - foreach ( $value as $event_id ) { |
|
| 906 | - $aee['events'][ $event_id ] = $this->_data->events[ $event_id ]; |
|
| 902 | + foreach ($details as $item => $value) { |
|
| 903 | + $aee[$item] = $value; |
|
| 904 | + if ($item == 'line_ref') { |
|
| 905 | + foreach ($value as $event_id) { |
|
| 906 | + $aee['events'][$event_id] = $this->_data->events[$event_id]; |
|
| 907 | 907 | } |
| 908 | 908 | } |
| 909 | - if ( $item == 'attendee_email' ) { |
|
| 909 | + if ($item == 'attendee_email') { |
|
| 910 | 910 | $aee['attendee_email'] = $value; |
| 911 | 911 | } |
| 912 | 912 | /*if ( $item == 'registration_id' ) { |
@@ -915,13 +915,13 @@ discard block |
||
| 915 | 915 | } |
| 916 | 916 | // note the FIRST reg object in this array is the one |
| 917 | 917 | // we'll use for this attendee as the primary registration for this attendee. |
| 918 | - $aee['reg_obj'] = reset( $this->_data->attendees[ $att_id ]['reg_objs'] ); |
|
| 918 | + $aee['reg_obj'] = reset($this->_data->attendees[$att_id]['reg_objs']); |
|
| 919 | 919 | $aee['attendees'] = $this->_data->attendees; |
| 920 | 920 | $aee['recipient_id'] = $att_id; |
| 921 | 921 | $aee['recipient_type'] = 'Attendee'; |
| 922 | 922 | //merge in the primary attendee data |
| 923 | - $aee = array_merge( $this->_default_addressee_data, $aee ); |
|
| 924 | - $add[] = new EE_Messages_Addressee( $aee ); |
|
| 923 | + $aee = array_merge($this->_default_addressee_data, $aee); |
|
| 924 | + $add[] = new EE_Messages_Addressee($aee); |
|
| 925 | 925 | } |
| 926 | 926 | return $add; |
| 927 | 927 | } |
@@ -932,8 +932,8 @@ discard block |
||
| 932 | 932 | * @param $event_id |
| 933 | 933 | * @return int |
| 934 | 934 | */ |
| 935 | - protected function _get_event_admin_id( $event_id ) { |
|
| 936 | - $event = EEM_Event::instance()->get_one_by_ID( $event_id ); |
|
| 935 | + protected function _get_event_admin_id($event_id) { |
|
| 936 | + $event = EEM_Event::instance()->get_one_by_ID($event_id); |
|
| 937 | 937 | return $event instanceof EE_Event ? $event->wp_user() : 0; |
| 938 | 938 | } |
| 939 | 939 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | /** |
| 5 | 5 | * Event Espresso |
@@ -23,670 +23,670 @@ discard block |
||
| 23 | 23 | class EE_Attendee extends EE_CPT_Base implements EEI_Contact, EEI_Address, EEI_Admin_Links, EEI_Attendee |
| 24 | 24 | { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Sets some dynamic defaults |
|
| 28 | - * |
|
| 29 | - * @param array $fieldValues |
|
| 30 | - * @param bool $bydb |
|
| 31 | - * @param string $timezone |
|
| 32 | - * @param array $date_formats |
|
| 33 | - */ |
|
| 34 | - protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = array()) |
|
| 35 | - { |
|
| 36 | - if (! isset($fieldValues['ATT_full_name'])) { |
|
| 37 | - $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : ''; |
|
| 38 | - $lname = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : ''; |
|
| 39 | - $fieldValues['ATT_full_name'] = $fname . $lname; |
|
| 40 | - } |
|
| 41 | - if (! isset($fieldValues['ATT_slug'])) { |
|
| 42 | - // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20)); |
|
| 43 | - $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']); |
|
| 44 | - } |
|
| 45 | - if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
| 46 | - $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50); |
|
| 47 | - } |
|
| 48 | - parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @param array $props_n_values incoming values |
|
| 54 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 55 | - * used.) |
|
| 56 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 57 | - * date_format and the second value is the time format |
|
| 58 | - * @return EE_Attendee |
|
| 59 | - */ |
|
| 60 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 61 | - { |
|
| 62 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 63 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @param array $props_n_values incoming values from the database |
|
| 69 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 70 | - * the website will be used. |
|
| 71 | - * @return EE_Attendee |
|
| 72 | - */ |
|
| 73 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 74 | - { |
|
| 75 | - return new self($props_n_values, true, $timezone); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Set Attendee First Name |
|
| 81 | - * |
|
| 82 | - * @access public |
|
| 83 | - * @param string $fname |
|
| 84 | - */ |
|
| 85 | - public function set_fname($fname = '') |
|
| 86 | - { |
|
| 87 | - $this->set('ATT_fname', $fname); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Set Attendee Last Name |
|
| 93 | - * |
|
| 94 | - * @access public |
|
| 95 | - * @param string $lname |
|
| 96 | - */ |
|
| 97 | - public function set_lname($lname = '') |
|
| 98 | - { |
|
| 99 | - $this->set('ATT_lname', $lname); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Set Attendee Address |
|
| 105 | - * |
|
| 106 | - * @access public |
|
| 107 | - * @param string $address |
|
| 108 | - */ |
|
| 109 | - public function set_address($address = '') |
|
| 110 | - { |
|
| 111 | - $this->set('ATT_address', $address); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Set Attendee Address2 |
|
| 117 | - * |
|
| 118 | - * @access public |
|
| 119 | - * @param string $address2 |
|
| 120 | - */ |
|
| 121 | - public function set_address2($address2 = '') |
|
| 122 | - { |
|
| 123 | - $this->set('ATT_address2', $address2); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Set Attendee City |
|
| 129 | - * |
|
| 130 | - * @access public |
|
| 131 | - * @param string $city |
|
| 132 | - */ |
|
| 133 | - public function set_city($city = '') |
|
| 134 | - { |
|
| 135 | - $this->set('ATT_city', $city); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * Set Attendee State ID |
|
| 141 | - * |
|
| 142 | - * @access public |
|
| 143 | - * @param int $STA_ID |
|
| 144 | - */ |
|
| 145 | - public function set_state($STA_ID = 0) |
|
| 146 | - { |
|
| 147 | - $this->set('STA_ID', $STA_ID); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * Set Attendee Country ISO Code |
|
| 153 | - * |
|
| 154 | - * @access public |
|
| 155 | - * @param string $CNT_ISO |
|
| 156 | - */ |
|
| 157 | - public function set_country($CNT_ISO = '') |
|
| 158 | - { |
|
| 159 | - $this->set('CNT_ISO', $CNT_ISO); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Set Attendee Zip/Postal Code |
|
| 165 | - * |
|
| 166 | - * @access public |
|
| 167 | - * @param string $zip |
|
| 168 | - */ |
|
| 169 | - public function set_zip($zip = '') |
|
| 170 | - { |
|
| 171 | - $this->set('ATT_zip', $zip); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * Set Attendee Email Address |
|
| 177 | - * |
|
| 178 | - * @access public |
|
| 179 | - * @param string $email |
|
| 180 | - */ |
|
| 181 | - public function set_email($email = '') |
|
| 182 | - { |
|
| 183 | - $this->set('ATT_email', $email); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * Set Attendee Phone |
|
| 189 | - * |
|
| 190 | - * @access public |
|
| 191 | - * @param string $phone |
|
| 192 | - */ |
|
| 193 | - public function set_phone($phone = '') |
|
| 194 | - { |
|
| 195 | - $this->set('ATT_phone', $phone); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * set deleted |
|
| 201 | - * |
|
| 202 | - * @access public |
|
| 203 | - * @param bool $ATT_deleted |
|
| 204 | - */ |
|
| 205 | - public function set_deleted($ATT_deleted = false) |
|
| 206 | - { |
|
| 207 | - $this->set('ATT_deleted', $ATT_deleted); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * Returns the value for the post_author id saved with the cpt |
|
| 213 | - * |
|
| 214 | - * @since 4.5.0 |
|
| 215 | - * @return int |
|
| 216 | - */ |
|
| 217 | - public function wp_user() |
|
| 218 | - { |
|
| 219 | - return $this->get('ATT_author'); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * get Attendee First Name |
|
| 225 | - * |
|
| 226 | - * @access public |
|
| 227 | - * @return string |
|
| 228 | - */ |
|
| 229 | - public function fname() |
|
| 230 | - { |
|
| 231 | - return $this->get('ATT_fname'); |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * echoes out the attendee's first name |
|
| 237 | - * |
|
| 238 | - * @return void |
|
| 239 | - */ |
|
| 240 | - public function e_full_name() |
|
| 241 | - { |
|
| 242 | - echo $this->full_name(); |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - |
|
| 246 | - /** |
|
| 247 | - * Returns the first and last name concatenated together with a space. |
|
| 248 | - * |
|
| 249 | - * @param bool $apply_html_entities |
|
| 250 | - * @return string |
|
| 251 | - */ |
|
| 252 | - public function full_name($apply_html_entities = false) |
|
| 253 | - { |
|
| 254 | - $full_name = array( |
|
| 255 | - $this->fname(), |
|
| 256 | - $this->lname() |
|
| 257 | - ); |
|
| 258 | - $full_name = array_filter($full_name); |
|
| 259 | - $full_name = implode(' ', $full_name); |
|
| 260 | - return $apply_html_entities ? htmlentities($full_name, ENT_QUOTES, 'UTF-8') : $full_name; |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * This returns the value of the `ATT_full_name` field which is usually equivalent to calling `full_name()` unless |
|
| 266 | - * the post_title field has been directly modified in the db for the post (espresso_attendees post type) for this |
|
| 267 | - * attendee. |
|
| 268 | - * |
|
| 269 | - * @param bool $apply_html_entities |
|
| 270 | - * @return string |
|
| 271 | - */ |
|
| 272 | - public function ATT_full_name($apply_html_entities = false) |
|
| 273 | - { |
|
| 274 | - return $apply_html_entities |
|
| 275 | - ? htmlentities($this->get('ATT_full_name'), ENT_QUOTES, 'UTF-8') |
|
| 276 | - : $this->get('ATT_full_name'); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * get Attendee Last Name |
|
| 282 | - * |
|
| 283 | - * @access public |
|
| 284 | - * @return string |
|
| 285 | - */ |
|
| 286 | - public function lname() |
|
| 287 | - { |
|
| 288 | - return $this->get('ATT_lname'); |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * Gets the attendee's full address as an array so client code can decide hwo to display it |
|
| 294 | - * |
|
| 295 | - * @return array numerically indexed, with each part of the address that is known. |
|
| 296 | - * Eg, if the user only responded to state and country, |
|
| 297 | - * it would be array(0=>'Alabama',1=>'USA') |
|
| 298 | - * @return array |
|
| 299 | - */ |
|
| 300 | - public function full_address_as_array() |
|
| 301 | - { |
|
| 302 | - $full_address_array = array(); |
|
| 303 | - $initial_address_fields = array('ATT_address', 'ATT_address2', 'ATT_city',); |
|
| 304 | - foreach ($initial_address_fields as $address_field_name) { |
|
| 305 | - $address_fields_value = $this->get($address_field_name); |
|
| 306 | - if (! empty($address_fields_value)) { |
|
| 307 | - $full_address_array[] = $address_fields_value; |
|
| 308 | - } |
|
| 309 | - } |
|
| 310 | - //now handle state and country |
|
| 311 | - $state_obj = $this->state_obj(); |
|
| 312 | - if (! empty($state_obj)) { |
|
| 313 | - $full_address_array[] = $state_obj->name(); |
|
| 314 | - } |
|
| 315 | - $country_obj = $this->country_obj(); |
|
| 316 | - if (! empty($country_obj)) { |
|
| 317 | - $full_address_array[] = $country_obj->name(); |
|
| 318 | - } |
|
| 319 | - //lastly get the xip |
|
| 320 | - $zip_value = $this->zip(); |
|
| 321 | - if (! empty($zip_value)) { |
|
| 322 | - $full_address_array[] = $zip_value; |
|
| 323 | - } |
|
| 324 | - return $full_address_array; |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * get Attendee Address |
|
| 330 | - * |
|
| 331 | - * @return string |
|
| 332 | - */ |
|
| 333 | - public function address() |
|
| 334 | - { |
|
| 335 | - return $this->get('ATT_address'); |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - |
|
| 339 | - /** |
|
| 340 | - * get Attendee Address2 |
|
| 341 | - * |
|
| 342 | - * @return string |
|
| 343 | - */ |
|
| 344 | - public function address2() |
|
| 345 | - { |
|
| 346 | - return $this->get('ATT_address2'); |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * get Attendee City |
|
| 352 | - * |
|
| 353 | - * @return string |
|
| 354 | - */ |
|
| 355 | - public function city() |
|
| 356 | - { |
|
| 357 | - return $this->get('ATT_city'); |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - |
|
| 361 | - /** |
|
| 362 | - * get Attendee State ID |
|
| 363 | - * |
|
| 364 | - * @return string |
|
| 365 | - */ |
|
| 366 | - public function state_ID() |
|
| 367 | - { |
|
| 368 | - return $this->get('STA_ID'); |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * @return string |
|
| 374 | - */ |
|
| 375 | - public function state_abbrev() |
|
| 376 | - { |
|
| 377 | - return $this->state_obj() instanceof EE_State ? $this->state_obj()->abbrev() : ''; |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - |
|
| 381 | - /** |
|
| 382 | - * Gets the state set to this attendee |
|
| 383 | - * |
|
| 384 | - * @return EE_State |
|
| 385 | - */ |
|
| 386 | - public function state_obj() |
|
| 387 | - { |
|
| 388 | - return $this->get_first_related('State'); |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - |
|
| 392 | - /** |
|
| 393 | - * Returns the state's name, otherwise 'Unknown' |
|
| 394 | - * |
|
| 395 | - * @return string |
|
| 396 | - */ |
|
| 397 | - public function state_name() |
|
| 398 | - { |
|
| 399 | - if ($this->state_obj()) { |
|
| 400 | - return $this->state_obj()->name(); |
|
| 401 | - } else { |
|
| 402 | - return ''; |
|
| 403 | - } |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - |
|
| 407 | - /** |
|
| 408 | - * either displays the state abbreviation or the state name, as determined |
|
| 409 | - * by the "FHEE__EEI_Address__state__use_abbreviation" filter. |
|
| 410 | - * defaults to abbreviation |
|
| 411 | - * |
|
| 412 | - * @return string |
|
| 413 | - */ |
|
| 414 | - public function state() |
|
| 415 | - { |
|
| 416 | - if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) { |
|
| 417 | - return $this->state_abbrev(); |
|
| 418 | - } else { |
|
| 419 | - return $this->state_name(); |
|
| 420 | - } |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * get Attendee Country ISO Code |
|
| 426 | - * |
|
| 427 | - * @return string |
|
| 428 | - */ |
|
| 429 | - public function country_ID() |
|
| 430 | - { |
|
| 431 | - return $this->get('CNT_ISO'); |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - |
|
| 435 | - /** |
|
| 436 | - * Gets country set for this attendee |
|
| 437 | - * |
|
| 438 | - * @return EE_Country |
|
| 439 | - */ |
|
| 440 | - public function country_obj() |
|
| 441 | - { |
|
| 442 | - return $this->get_first_related('Country'); |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - |
|
| 446 | - /** |
|
| 447 | - * Returns the country's name if known, otherwise 'Unknown' |
|
| 448 | - * |
|
| 449 | - * @return string |
|
| 450 | - */ |
|
| 451 | - public function country_name() |
|
| 452 | - { |
|
| 453 | - if ($this->country_obj()) { |
|
| 454 | - return $this->country_obj()->name(); |
|
| 455 | - } else { |
|
| 456 | - return ''; |
|
| 457 | - } |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - |
|
| 461 | - /** |
|
| 462 | - * either displays the country ISO2 code or the country name, as determined |
|
| 463 | - * by the "FHEE__EEI_Address__country__use_abbreviation" filter. |
|
| 464 | - * defaults to abbreviation |
|
| 465 | - * |
|
| 466 | - * @return string |
|
| 467 | - */ |
|
| 468 | - public function country() |
|
| 469 | - { |
|
| 470 | - if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) { |
|
| 471 | - return $this->country_ID(); |
|
| 472 | - } else { |
|
| 473 | - return $this->country_name(); |
|
| 474 | - } |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - |
|
| 478 | - /** |
|
| 479 | - * get Attendee Zip/Postal Code |
|
| 480 | - * |
|
| 481 | - * @return string |
|
| 482 | - */ |
|
| 483 | - public function zip() |
|
| 484 | - { |
|
| 485 | - return $this->get('ATT_zip'); |
|
| 486 | - } |
|
| 487 | - |
|
| 488 | - |
|
| 489 | - /** |
|
| 490 | - * get Attendee Email Address |
|
| 491 | - * |
|
| 492 | - * @return string |
|
| 493 | - */ |
|
| 494 | - public function email() |
|
| 495 | - { |
|
| 496 | - return $this->get('ATT_email'); |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - |
|
| 500 | - /** |
|
| 501 | - * get Attendee Phone # |
|
| 502 | - * |
|
| 503 | - * @return string |
|
| 504 | - */ |
|
| 505 | - public function phone() |
|
| 506 | - { |
|
| 507 | - return $this->get('ATT_phone'); |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - |
|
| 511 | - /** |
|
| 512 | - * get deleted |
|
| 513 | - * |
|
| 514 | - * @return bool |
|
| 515 | - */ |
|
| 516 | - public function deleted() |
|
| 517 | - { |
|
| 518 | - return $this->get('ATT_deleted'); |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - |
|
| 522 | - /** |
|
| 523 | - * Gets registrations of this attendee |
|
| 524 | - * |
|
| 525 | - * @param array $query_params |
|
| 526 | - * @return EE_Registration[] |
|
| 527 | - */ |
|
| 528 | - public function get_registrations($query_params = array()) |
|
| 529 | - { |
|
| 530 | - return $this->get_many_related('Registration', $query_params); |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - |
|
| 534 | - /** |
|
| 535 | - * Gets the most recent registration of this attendee |
|
| 536 | - * |
|
| 537 | - * @return EE_Registration |
|
| 538 | - */ |
|
| 539 | - public function get_most_recent_registration() |
|
| 540 | - { |
|
| 541 | - return $this->get_first_related('Registration', |
|
| 542 | - array('order_by' => array('REG_date' => 'DESC'))); //null, 'REG_date', 'DESC', '=', 'OBJECT_K'); |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - |
|
| 546 | - /** |
|
| 547 | - * Gets the most recent registration for this attend at this event |
|
| 548 | - * |
|
| 549 | - * @param int $event_id |
|
| 550 | - * @return EE_Registration |
|
| 551 | - */ |
|
| 552 | - public function get_most_recent_registration_for_event($event_id) |
|
| 553 | - { |
|
| 554 | - return $this->get_first_related('Registration', |
|
| 555 | - array(array('EVT_ID' => $event_id), 'order_by' => array('REG_date' => 'DESC')));//, '=', 'OBJECT_K' ); |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - |
|
| 559 | - /** |
|
| 560 | - * returns any events attached to this attendee ($_Event property); |
|
| 561 | - * |
|
| 562 | - * @return array |
|
| 563 | - */ |
|
| 564 | - public function events() |
|
| 565 | - { |
|
| 566 | - return $this->get_many_related('Event'); |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - |
|
| 570 | - /** |
|
| 571 | - * Gets the billing info array where keys match espresso_reg_page_billing_inputs(), |
|
| 572 | - * and keys are their cleaned values. @see EE_Attendee::save_and_clean_billing_info_for_payment_method() which was |
|
| 573 | - * used to save the billing info |
|
| 574 | - * |
|
| 575 | - * @param EE_Payment_Method $payment_method the _gateway_name property on the gateway class |
|
| 576 | - * @return EE_Form_Section_Proper|null |
|
| 577 | - */ |
|
| 578 | - public function billing_info_for_payment_method($payment_method) |
|
| 579 | - { |
|
| 580 | - $pm_type = $payment_method->type_obj(); |
|
| 581 | - if (! $pm_type instanceof EE_PMT_Base) { |
|
| 582 | - return null; |
|
| 583 | - } |
|
| 584 | - $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true); |
|
| 585 | - if (! $billing_info) { |
|
| 586 | - return null; |
|
| 587 | - } |
|
| 588 | - $billing_form = $pm_type->billing_form(); |
|
| 589 | - if ($billing_form instanceof EE_Form_Section_Proper) { |
|
| 590 | - $billing_form->receive_form_submission(array($billing_form->name() => $billing_info), false); |
|
| 591 | - } |
|
| 592 | - return $billing_form; |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - |
|
| 596 | - /** |
|
| 597 | - * Gets the postmeta key that holds this attendee's billing info for the |
|
| 598 | - * specified payment method |
|
| 599 | - * |
|
| 600 | - * @param EE_Payment_Method $payment_method |
|
| 601 | - * @return string |
|
| 602 | - */ |
|
| 603 | - public function get_billing_info_postmeta_name($payment_method) |
|
| 604 | - { |
|
| 605 | - if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
| 606 | - return 'billing_info_' . $payment_method->type_obj()->system_name(); |
|
| 607 | - } else { |
|
| 608 | - return null; |
|
| 609 | - } |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - |
|
| 613 | - /** |
|
| 614 | - * Saves the billing info to the attendee. @see EE_Attendee::billing_info_for_payment_method() which is used to |
|
| 615 | - * retrieve it |
|
| 616 | - * |
|
| 617 | - * @param EE_Billing_Attendee_Info_Form $billing_form |
|
| 618 | - * @param EE_Payment_Method $payment_method |
|
| 619 | - * @return boolean |
|
| 620 | - */ |
|
| 621 | - public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method) |
|
| 622 | - { |
|
| 623 | - if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
| 624 | - EE_Error::add_error(__('Cannot save billing info because there is none.', 'event_espresso')); |
|
| 625 | - return false; |
|
| 626 | - } |
|
| 627 | - $billing_form->clean_sensitive_data(); |
|
| 628 | - return update_post_meta($this->ID(), $this->get_billing_info_postmeta_name($payment_method), |
|
| 629 | - $billing_form->input_values(true)); |
|
| 630 | - } |
|
| 631 | - |
|
| 632 | - |
|
| 633 | - /** |
|
| 634 | - * Return the link to the admin details for the object. |
|
| 635 | - * |
|
| 636 | - * @return string |
|
| 637 | - */ |
|
| 638 | - public function get_admin_details_link() |
|
| 639 | - { |
|
| 640 | - return $this->get_admin_edit_link(); |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - |
|
| 644 | - /** |
|
| 645 | - * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
| 646 | - * |
|
| 647 | - * @return string |
|
| 648 | - */ |
|
| 649 | - public function get_admin_edit_link() |
|
| 650 | - { |
|
| 651 | - EE_Registry::instance()->load_helper('URL'); |
|
| 652 | - return EEH_URL::add_query_args_and_nonce( |
|
| 653 | - array( |
|
| 654 | - 'page' => 'espresso_registrations', |
|
| 655 | - 'action' => 'edit_attendee', |
|
| 656 | - 'post' => $this->ID(), |
|
| 657 | - ), |
|
| 658 | - admin_url('admin.php') |
|
| 659 | - ); |
|
| 660 | - } |
|
| 661 | - |
|
| 662 | - |
|
| 663 | - /** |
|
| 664 | - * Returns the link to a settings page for the object. |
|
| 665 | - * |
|
| 666 | - * @return string |
|
| 667 | - */ |
|
| 668 | - public function get_admin_settings_link() |
|
| 669 | - { |
|
| 670 | - return $this->get_admin_edit_link(); |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - |
|
| 674 | - /** |
|
| 675 | - * Returns the link to the "overview" for the object (typically the "list table" view). |
|
| 676 | - * |
|
| 677 | - * @return string |
|
| 678 | - */ |
|
| 679 | - public function get_admin_overview_link() |
|
| 680 | - { |
|
| 681 | - EE_Registry::instance()->load_helper('URL'); |
|
| 682 | - return EEH_URL::add_query_args_and_nonce( |
|
| 683 | - array( |
|
| 684 | - 'page' => 'espresso_registrations', |
|
| 685 | - 'action' => 'contact_list', |
|
| 686 | - ), |
|
| 687 | - admin_url('admin.php') |
|
| 688 | - ); |
|
| 689 | - } |
|
| 26 | + /** |
|
| 27 | + * Sets some dynamic defaults |
|
| 28 | + * |
|
| 29 | + * @param array $fieldValues |
|
| 30 | + * @param bool $bydb |
|
| 31 | + * @param string $timezone |
|
| 32 | + * @param array $date_formats |
|
| 33 | + */ |
|
| 34 | + protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = array()) |
|
| 35 | + { |
|
| 36 | + if (! isset($fieldValues['ATT_full_name'])) { |
|
| 37 | + $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : ''; |
|
| 38 | + $lname = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : ''; |
|
| 39 | + $fieldValues['ATT_full_name'] = $fname . $lname; |
|
| 40 | + } |
|
| 41 | + if (! isset($fieldValues['ATT_slug'])) { |
|
| 42 | + // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20)); |
|
| 43 | + $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']); |
|
| 44 | + } |
|
| 45 | + if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
| 46 | + $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50); |
|
| 47 | + } |
|
| 48 | + parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @param array $props_n_values incoming values |
|
| 54 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 55 | + * used.) |
|
| 56 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 57 | + * date_format and the second value is the time format |
|
| 58 | + * @return EE_Attendee |
|
| 59 | + */ |
|
| 60 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 61 | + { |
|
| 62 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 63 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @param array $props_n_values incoming values from the database |
|
| 69 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 70 | + * the website will be used. |
|
| 71 | + * @return EE_Attendee |
|
| 72 | + */ |
|
| 73 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 74 | + { |
|
| 75 | + return new self($props_n_values, true, $timezone); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Set Attendee First Name |
|
| 81 | + * |
|
| 82 | + * @access public |
|
| 83 | + * @param string $fname |
|
| 84 | + */ |
|
| 85 | + public function set_fname($fname = '') |
|
| 86 | + { |
|
| 87 | + $this->set('ATT_fname', $fname); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Set Attendee Last Name |
|
| 93 | + * |
|
| 94 | + * @access public |
|
| 95 | + * @param string $lname |
|
| 96 | + */ |
|
| 97 | + public function set_lname($lname = '') |
|
| 98 | + { |
|
| 99 | + $this->set('ATT_lname', $lname); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Set Attendee Address |
|
| 105 | + * |
|
| 106 | + * @access public |
|
| 107 | + * @param string $address |
|
| 108 | + */ |
|
| 109 | + public function set_address($address = '') |
|
| 110 | + { |
|
| 111 | + $this->set('ATT_address', $address); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Set Attendee Address2 |
|
| 117 | + * |
|
| 118 | + * @access public |
|
| 119 | + * @param string $address2 |
|
| 120 | + */ |
|
| 121 | + public function set_address2($address2 = '') |
|
| 122 | + { |
|
| 123 | + $this->set('ATT_address2', $address2); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Set Attendee City |
|
| 129 | + * |
|
| 130 | + * @access public |
|
| 131 | + * @param string $city |
|
| 132 | + */ |
|
| 133 | + public function set_city($city = '') |
|
| 134 | + { |
|
| 135 | + $this->set('ATT_city', $city); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * Set Attendee State ID |
|
| 141 | + * |
|
| 142 | + * @access public |
|
| 143 | + * @param int $STA_ID |
|
| 144 | + */ |
|
| 145 | + public function set_state($STA_ID = 0) |
|
| 146 | + { |
|
| 147 | + $this->set('STA_ID', $STA_ID); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * Set Attendee Country ISO Code |
|
| 153 | + * |
|
| 154 | + * @access public |
|
| 155 | + * @param string $CNT_ISO |
|
| 156 | + */ |
|
| 157 | + public function set_country($CNT_ISO = '') |
|
| 158 | + { |
|
| 159 | + $this->set('CNT_ISO', $CNT_ISO); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Set Attendee Zip/Postal Code |
|
| 165 | + * |
|
| 166 | + * @access public |
|
| 167 | + * @param string $zip |
|
| 168 | + */ |
|
| 169 | + public function set_zip($zip = '') |
|
| 170 | + { |
|
| 171 | + $this->set('ATT_zip', $zip); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * Set Attendee Email Address |
|
| 177 | + * |
|
| 178 | + * @access public |
|
| 179 | + * @param string $email |
|
| 180 | + */ |
|
| 181 | + public function set_email($email = '') |
|
| 182 | + { |
|
| 183 | + $this->set('ATT_email', $email); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * Set Attendee Phone |
|
| 189 | + * |
|
| 190 | + * @access public |
|
| 191 | + * @param string $phone |
|
| 192 | + */ |
|
| 193 | + public function set_phone($phone = '') |
|
| 194 | + { |
|
| 195 | + $this->set('ATT_phone', $phone); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * set deleted |
|
| 201 | + * |
|
| 202 | + * @access public |
|
| 203 | + * @param bool $ATT_deleted |
|
| 204 | + */ |
|
| 205 | + public function set_deleted($ATT_deleted = false) |
|
| 206 | + { |
|
| 207 | + $this->set('ATT_deleted', $ATT_deleted); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * Returns the value for the post_author id saved with the cpt |
|
| 213 | + * |
|
| 214 | + * @since 4.5.0 |
|
| 215 | + * @return int |
|
| 216 | + */ |
|
| 217 | + public function wp_user() |
|
| 218 | + { |
|
| 219 | + return $this->get('ATT_author'); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * get Attendee First Name |
|
| 225 | + * |
|
| 226 | + * @access public |
|
| 227 | + * @return string |
|
| 228 | + */ |
|
| 229 | + public function fname() |
|
| 230 | + { |
|
| 231 | + return $this->get('ATT_fname'); |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * echoes out the attendee's first name |
|
| 237 | + * |
|
| 238 | + * @return void |
|
| 239 | + */ |
|
| 240 | + public function e_full_name() |
|
| 241 | + { |
|
| 242 | + echo $this->full_name(); |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + |
|
| 246 | + /** |
|
| 247 | + * Returns the first and last name concatenated together with a space. |
|
| 248 | + * |
|
| 249 | + * @param bool $apply_html_entities |
|
| 250 | + * @return string |
|
| 251 | + */ |
|
| 252 | + public function full_name($apply_html_entities = false) |
|
| 253 | + { |
|
| 254 | + $full_name = array( |
|
| 255 | + $this->fname(), |
|
| 256 | + $this->lname() |
|
| 257 | + ); |
|
| 258 | + $full_name = array_filter($full_name); |
|
| 259 | + $full_name = implode(' ', $full_name); |
|
| 260 | + return $apply_html_entities ? htmlentities($full_name, ENT_QUOTES, 'UTF-8') : $full_name; |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * This returns the value of the `ATT_full_name` field which is usually equivalent to calling `full_name()` unless |
|
| 266 | + * the post_title field has been directly modified in the db for the post (espresso_attendees post type) for this |
|
| 267 | + * attendee. |
|
| 268 | + * |
|
| 269 | + * @param bool $apply_html_entities |
|
| 270 | + * @return string |
|
| 271 | + */ |
|
| 272 | + public function ATT_full_name($apply_html_entities = false) |
|
| 273 | + { |
|
| 274 | + return $apply_html_entities |
|
| 275 | + ? htmlentities($this->get('ATT_full_name'), ENT_QUOTES, 'UTF-8') |
|
| 276 | + : $this->get('ATT_full_name'); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * get Attendee Last Name |
|
| 282 | + * |
|
| 283 | + * @access public |
|
| 284 | + * @return string |
|
| 285 | + */ |
|
| 286 | + public function lname() |
|
| 287 | + { |
|
| 288 | + return $this->get('ATT_lname'); |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * Gets the attendee's full address as an array so client code can decide hwo to display it |
|
| 294 | + * |
|
| 295 | + * @return array numerically indexed, with each part of the address that is known. |
|
| 296 | + * Eg, if the user only responded to state and country, |
|
| 297 | + * it would be array(0=>'Alabama',1=>'USA') |
|
| 298 | + * @return array |
|
| 299 | + */ |
|
| 300 | + public function full_address_as_array() |
|
| 301 | + { |
|
| 302 | + $full_address_array = array(); |
|
| 303 | + $initial_address_fields = array('ATT_address', 'ATT_address2', 'ATT_city',); |
|
| 304 | + foreach ($initial_address_fields as $address_field_name) { |
|
| 305 | + $address_fields_value = $this->get($address_field_name); |
|
| 306 | + if (! empty($address_fields_value)) { |
|
| 307 | + $full_address_array[] = $address_fields_value; |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | + //now handle state and country |
|
| 311 | + $state_obj = $this->state_obj(); |
|
| 312 | + if (! empty($state_obj)) { |
|
| 313 | + $full_address_array[] = $state_obj->name(); |
|
| 314 | + } |
|
| 315 | + $country_obj = $this->country_obj(); |
|
| 316 | + if (! empty($country_obj)) { |
|
| 317 | + $full_address_array[] = $country_obj->name(); |
|
| 318 | + } |
|
| 319 | + //lastly get the xip |
|
| 320 | + $zip_value = $this->zip(); |
|
| 321 | + if (! empty($zip_value)) { |
|
| 322 | + $full_address_array[] = $zip_value; |
|
| 323 | + } |
|
| 324 | + return $full_address_array; |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * get Attendee Address |
|
| 330 | + * |
|
| 331 | + * @return string |
|
| 332 | + */ |
|
| 333 | + public function address() |
|
| 334 | + { |
|
| 335 | + return $this->get('ATT_address'); |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + |
|
| 339 | + /** |
|
| 340 | + * get Attendee Address2 |
|
| 341 | + * |
|
| 342 | + * @return string |
|
| 343 | + */ |
|
| 344 | + public function address2() |
|
| 345 | + { |
|
| 346 | + return $this->get('ATT_address2'); |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * get Attendee City |
|
| 352 | + * |
|
| 353 | + * @return string |
|
| 354 | + */ |
|
| 355 | + public function city() |
|
| 356 | + { |
|
| 357 | + return $this->get('ATT_city'); |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + |
|
| 361 | + /** |
|
| 362 | + * get Attendee State ID |
|
| 363 | + * |
|
| 364 | + * @return string |
|
| 365 | + */ |
|
| 366 | + public function state_ID() |
|
| 367 | + { |
|
| 368 | + return $this->get('STA_ID'); |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * @return string |
|
| 374 | + */ |
|
| 375 | + public function state_abbrev() |
|
| 376 | + { |
|
| 377 | + return $this->state_obj() instanceof EE_State ? $this->state_obj()->abbrev() : ''; |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + |
|
| 381 | + /** |
|
| 382 | + * Gets the state set to this attendee |
|
| 383 | + * |
|
| 384 | + * @return EE_State |
|
| 385 | + */ |
|
| 386 | + public function state_obj() |
|
| 387 | + { |
|
| 388 | + return $this->get_first_related('State'); |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + |
|
| 392 | + /** |
|
| 393 | + * Returns the state's name, otherwise 'Unknown' |
|
| 394 | + * |
|
| 395 | + * @return string |
|
| 396 | + */ |
|
| 397 | + public function state_name() |
|
| 398 | + { |
|
| 399 | + if ($this->state_obj()) { |
|
| 400 | + return $this->state_obj()->name(); |
|
| 401 | + } else { |
|
| 402 | + return ''; |
|
| 403 | + } |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + |
|
| 407 | + /** |
|
| 408 | + * either displays the state abbreviation or the state name, as determined |
|
| 409 | + * by the "FHEE__EEI_Address__state__use_abbreviation" filter. |
|
| 410 | + * defaults to abbreviation |
|
| 411 | + * |
|
| 412 | + * @return string |
|
| 413 | + */ |
|
| 414 | + public function state() |
|
| 415 | + { |
|
| 416 | + if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) { |
|
| 417 | + return $this->state_abbrev(); |
|
| 418 | + } else { |
|
| 419 | + return $this->state_name(); |
|
| 420 | + } |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + |
|
| 424 | + /** |
|
| 425 | + * get Attendee Country ISO Code |
|
| 426 | + * |
|
| 427 | + * @return string |
|
| 428 | + */ |
|
| 429 | + public function country_ID() |
|
| 430 | + { |
|
| 431 | + return $this->get('CNT_ISO'); |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + |
|
| 435 | + /** |
|
| 436 | + * Gets country set for this attendee |
|
| 437 | + * |
|
| 438 | + * @return EE_Country |
|
| 439 | + */ |
|
| 440 | + public function country_obj() |
|
| 441 | + { |
|
| 442 | + return $this->get_first_related('Country'); |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + |
|
| 446 | + /** |
|
| 447 | + * Returns the country's name if known, otherwise 'Unknown' |
|
| 448 | + * |
|
| 449 | + * @return string |
|
| 450 | + */ |
|
| 451 | + public function country_name() |
|
| 452 | + { |
|
| 453 | + if ($this->country_obj()) { |
|
| 454 | + return $this->country_obj()->name(); |
|
| 455 | + } else { |
|
| 456 | + return ''; |
|
| 457 | + } |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + |
|
| 461 | + /** |
|
| 462 | + * either displays the country ISO2 code or the country name, as determined |
|
| 463 | + * by the "FHEE__EEI_Address__country__use_abbreviation" filter. |
|
| 464 | + * defaults to abbreviation |
|
| 465 | + * |
|
| 466 | + * @return string |
|
| 467 | + */ |
|
| 468 | + public function country() |
|
| 469 | + { |
|
| 470 | + if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) { |
|
| 471 | + return $this->country_ID(); |
|
| 472 | + } else { |
|
| 473 | + return $this->country_name(); |
|
| 474 | + } |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + |
|
| 478 | + /** |
|
| 479 | + * get Attendee Zip/Postal Code |
|
| 480 | + * |
|
| 481 | + * @return string |
|
| 482 | + */ |
|
| 483 | + public function zip() |
|
| 484 | + { |
|
| 485 | + return $this->get('ATT_zip'); |
|
| 486 | + } |
|
| 487 | + |
|
| 488 | + |
|
| 489 | + /** |
|
| 490 | + * get Attendee Email Address |
|
| 491 | + * |
|
| 492 | + * @return string |
|
| 493 | + */ |
|
| 494 | + public function email() |
|
| 495 | + { |
|
| 496 | + return $this->get('ATT_email'); |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + |
|
| 500 | + /** |
|
| 501 | + * get Attendee Phone # |
|
| 502 | + * |
|
| 503 | + * @return string |
|
| 504 | + */ |
|
| 505 | + public function phone() |
|
| 506 | + { |
|
| 507 | + return $this->get('ATT_phone'); |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + |
|
| 511 | + /** |
|
| 512 | + * get deleted |
|
| 513 | + * |
|
| 514 | + * @return bool |
|
| 515 | + */ |
|
| 516 | + public function deleted() |
|
| 517 | + { |
|
| 518 | + return $this->get('ATT_deleted'); |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + |
|
| 522 | + /** |
|
| 523 | + * Gets registrations of this attendee |
|
| 524 | + * |
|
| 525 | + * @param array $query_params |
|
| 526 | + * @return EE_Registration[] |
|
| 527 | + */ |
|
| 528 | + public function get_registrations($query_params = array()) |
|
| 529 | + { |
|
| 530 | + return $this->get_many_related('Registration', $query_params); |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + |
|
| 534 | + /** |
|
| 535 | + * Gets the most recent registration of this attendee |
|
| 536 | + * |
|
| 537 | + * @return EE_Registration |
|
| 538 | + */ |
|
| 539 | + public function get_most_recent_registration() |
|
| 540 | + { |
|
| 541 | + return $this->get_first_related('Registration', |
|
| 542 | + array('order_by' => array('REG_date' => 'DESC'))); //null, 'REG_date', 'DESC', '=', 'OBJECT_K'); |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + |
|
| 546 | + /** |
|
| 547 | + * Gets the most recent registration for this attend at this event |
|
| 548 | + * |
|
| 549 | + * @param int $event_id |
|
| 550 | + * @return EE_Registration |
|
| 551 | + */ |
|
| 552 | + public function get_most_recent_registration_for_event($event_id) |
|
| 553 | + { |
|
| 554 | + return $this->get_first_related('Registration', |
|
| 555 | + array(array('EVT_ID' => $event_id), 'order_by' => array('REG_date' => 'DESC')));//, '=', 'OBJECT_K' ); |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + |
|
| 559 | + /** |
|
| 560 | + * returns any events attached to this attendee ($_Event property); |
|
| 561 | + * |
|
| 562 | + * @return array |
|
| 563 | + */ |
|
| 564 | + public function events() |
|
| 565 | + { |
|
| 566 | + return $this->get_many_related('Event'); |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + |
|
| 570 | + /** |
|
| 571 | + * Gets the billing info array where keys match espresso_reg_page_billing_inputs(), |
|
| 572 | + * and keys are their cleaned values. @see EE_Attendee::save_and_clean_billing_info_for_payment_method() which was |
|
| 573 | + * used to save the billing info |
|
| 574 | + * |
|
| 575 | + * @param EE_Payment_Method $payment_method the _gateway_name property on the gateway class |
|
| 576 | + * @return EE_Form_Section_Proper|null |
|
| 577 | + */ |
|
| 578 | + public function billing_info_for_payment_method($payment_method) |
|
| 579 | + { |
|
| 580 | + $pm_type = $payment_method->type_obj(); |
|
| 581 | + if (! $pm_type instanceof EE_PMT_Base) { |
|
| 582 | + return null; |
|
| 583 | + } |
|
| 584 | + $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true); |
|
| 585 | + if (! $billing_info) { |
|
| 586 | + return null; |
|
| 587 | + } |
|
| 588 | + $billing_form = $pm_type->billing_form(); |
|
| 589 | + if ($billing_form instanceof EE_Form_Section_Proper) { |
|
| 590 | + $billing_form->receive_form_submission(array($billing_form->name() => $billing_info), false); |
|
| 591 | + } |
|
| 592 | + return $billing_form; |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + |
|
| 596 | + /** |
|
| 597 | + * Gets the postmeta key that holds this attendee's billing info for the |
|
| 598 | + * specified payment method |
|
| 599 | + * |
|
| 600 | + * @param EE_Payment_Method $payment_method |
|
| 601 | + * @return string |
|
| 602 | + */ |
|
| 603 | + public function get_billing_info_postmeta_name($payment_method) |
|
| 604 | + { |
|
| 605 | + if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
| 606 | + return 'billing_info_' . $payment_method->type_obj()->system_name(); |
|
| 607 | + } else { |
|
| 608 | + return null; |
|
| 609 | + } |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + |
|
| 613 | + /** |
|
| 614 | + * Saves the billing info to the attendee. @see EE_Attendee::billing_info_for_payment_method() which is used to |
|
| 615 | + * retrieve it |
|
| 616 | + * |
|
| 617 | + * @param EE_Billing_Attendee_Info_Form $billing_form |
|
| 618 | + * @param EE_Payment_Method $payment_method |
|
| 619 | + * @return boolean |
|
| 620 | + */ |
|
| 621 | + public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method) |
|
| 622 | + { |
|
| 623 | + if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
| 624 | + EE_Error::add_error(__('Cannot save billing info because there is none.', 'event_espresso')); |
|
| 625 | + return false; |
|
| 626 | + } |
|
| 627 | + $billing_form->clean_sensitive_data(); |
|
| 628 | + return update_post_meta($this->ID(), $this->get_billing_info_postmeta_name($payment_method), |
|
| 629 | + $billing_form->input_values(true)); |
|
| 630 | + } |
|
| 631 | + |
|
| 632 | + |
|
| 633 | + /** |
|
| 634 | + * Return the link to the admin details for the object. |
|
| 635 | + * |
|
| 636 | + * @return string |
|
| 637 | + */ |
|
| 638 | + public function get_admin_details_link() |
|
| 639 | + { |
|
| 640 | + return $this->get_admin_edit_link(); |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + |
|
| 644 | + /** |
|
| 645 | + * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
| 646 | + * |
|
| 647 | + * @return string |
|
| 648 | + */ |
|
| 649 | + public function get_admin_edit_link() |
|
| 650 | + { |
|
| 651 | + EE_Registry::instance()->load_helper('URL'); |
|
| 652 | + return EEH_URL::add_query_args_and_nonce( |
|
| 653 | + array( |
|
| 654 | + 'page' => 'espresso_registrations', |
|
| 655 | + 'action' => 'edit_attendee', |
|
| 656 | + 'post' => $this->ID(), |
|
| 657 | + ), |
|
| 658 | + admin_url('admin.php') |
|
| 659 | + ); |
|
| 660 | + } |
|
| 661 | + |
|
| 662 | + |
|
| 663 | + /** |
|
| 664 | + * Returns the link to a settings page for the object. |
|
| 665 | + * |
|
| 666 | + * @return string |
|
| 667 | + */ |
|
| 668 | + public function get_admin_settings_link() |
|
| 669 | + { |
|
| 670 | + return $this->get_admin_edit_link(); |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + |
|
| 674 | + /** |
|
| 675 | + * Returns the link to the "overview" for the object (typically the "list table" view). |
|
| 676 | + * |
|
| 677 | + * @return string |
|
| 678 | + */ |
|
| 679 | + public function get_admin_overview_link() |
|
| 680 | + { |
|
| 681 | + EE_Registry::instance()->load_helper('URL'); |
|
| 682 | + return EEH_URL::add_query_args_and_nonce( |
|
| 683 | + array( |
|
| 684 | + 'page' => 'espresso_registrations', |
|
| 685 | + 'action' => 'contact_list', |
|
| 686 | + ), |
|
| 687 | + admin_url('admin.php') |
|
| 688 | + ); |
|
| 689 | + } |
|
| 690 | 690 | |
| 691 | 691 | |
| 692 | 692 | } |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | 2 | exit('No direct script access allowed'); |
| 3 | 3 | } |
| 4 | 4 | /** |
@@ -33,16 +33,16 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = array()) |
| 35 | 35 | { |
| 36 | - if (! isset($fieldValues['ATT_full_name'])) { |
|
| 37 | - $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : ''; |
|
| 36 | + if ( ! isset($fieldValues['ATT_full_name'])) { |
|
| 37 | + $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'].' ' : ''; |
|
| 38 | 38 | $lname = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : ''; |
| 39 | - $fieldValues['ATT_full_name'] = $fname . $lname; |
|
| 39 | + $fieldValues['ATT_full_name'] = $fname.$lname; |
|
| 40 | 40 | } |
| 41 | - if (! isset($fieldValues['ATT_slug'])) { |
|
| 41 | + if ( ! isset($fieldValues['ATT_slug'])) { |
|
| 42 | 42 | // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20)); |
| 43 | 43 | $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']); |
| 44 | 44 | } |
| 45 | - if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
| 45 | + if ( ! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
| 46 | 46 | $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50); |
| 47 | 47 | } |
| 48 | 48 | parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
@@ -303,22 +303,22 @@ discard block |
||
| 303 | 303 | $initial_address_fields = array('ATT_address', 'ATT_address2', 'ATT_city',); |
| 304 | 304 | foreach ($initial_address_fields as $address_field_name) { |
| 305 | 305 | $address_fields_value = $this->get($address_field_name); |
| 306 | - if (! empty($address_fields_value)) { |
|
| 306 | + if ( ! empty($address_fields_value)) { |
|
| 307 | 307 | $full_address_array[] = $address_fields_value; |
| 308 | 308 | } |
| 309 | 309 | } |
| 310 | 310 | //now handle state and country |
| 311 | 311 | $state_obj = $this->state_obj(); |
| 312 | - if (! empty($state_obj)) { |
|
| 312 | + if ( ! empty($state_obj)) { |
|
| 313 | 313 | $full_address_array[] = $state_obj->name(); |
| 314 | 314 | } |
| 315 | 315 | $country_obj = $this->country_obj(); |
| 316 | - if (! empty($country_obj)) { |
|
| 316 | + if ( ! empty($country_obj)) { |
|
| 317 | 317 | $full_address_array[] = $country_obj->name(); |
| 318 | 318 | } |
| 319 | 319 | //lastly get the xip |
| 320 | 320 | $zip_value = $this->zip(); |
| 321 | - if (! empty($zip_value)) { |
|
| 321 | + if ( ! empty($zip_value)) { |
|
| 322 | 322 | $full_address_array[] = $zip_value; |
| 323 | 323 | } |
| 324 | 324 | return $full_address_array; |
@@ -552,7 +552,7 @@ discard block |
||
| 552 | 552 | public function get_most_recent_registration_for_event($event_id) |
| 553 | 553 | { |
| 554 | 554 | return $this->get_first_related('Registration', |
| 555 | - array(array('EVT_ID' => $event_id), 'order_by' => array('REG_date' => 'DESC')));//, '=', 'OBJECT_K' ); |
|
| 555 | + array(array('EVT_ID' => $event_id), 'order_by' => array('REG_date' => 'DESC'))); //, '=', 'OBJECT_K' ); |
|
| 556 | 556 | } |
| 557 | 557 | |
| 558 | 558 | |
@@ -578,11 +578,11 @@ discard block |
||
| 578 | 578 | public function billing_info_for_payment_method($payment_method) |
| 579 | 579 | { |
| 580 | 580 | $pm_type = $payment_method->type_obj(); |
| 581 | - if (! $pm_type instanceof EE_PMT_Base) { |
|
| 581 | + if ( ! $pm_type instanceof EE_PMT_Base) { |
|
| 582 | 582 | return null; |
| 583 | 583 | } |
| 584 | 584 | $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true); |
| 585 | - if (! $billing_info) { |
|
| 585 | + if ( ! $billing_info) { |
|
| 586 | 586 | return null; |
| 587 | 587 | } |
| 588 | 588 | $billing_form = $pm_type->billing_form(); |
@@ -603,7 +603,7 @@ discard block |
||
| 603 | 603 | public function get_billing_info_postmeta_name($payment_method) |
| 604 | 604 | { |
| 605 | 605 | if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
| 606 | - return 'billing_info_' . $payment_method->type_obj()->system_name(); |
|
| 606 | + return 'billing_info_'.$payment_method->type_obj()->system_name(); |
|
| 607 | 607 | } else { |
| 608 | 608 | return null; |
| 609 | 609 | } |
@@ -620,7 +620,7 @@ discard block |
||
| 620 | 620 | */ |
| 621 | 621 | public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method) |
| 622 | 622 | { |
| 623 | - if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
| 623 | + if ( ! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
| 624 | 624 | EE_Error::add_error(__('Cannot save billing info because there is none.', 'event_espresso')); |
| 625 | 625 | return false; |
| 626 | 626 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | |
@@ -23,2223 +23,2223 @@ discard block |
||
| 23 | 23 | class Registrations_Admin_Page extends EE_Admin_Page_CPT |
| 24 | 24 | { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var EE_Registration |
|
| 28 | - */ |
|
| 29 | - private $_registration; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var EE_Event |
|
| 33 | - */ |
|
| 34 | - private $_reg_event; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var EE_Session |
|
| 38 | - */ |
|
| 39 | - private $_session; |
|
| 40 | - |
|
| 41 | - private static $_reg_status; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Form for displaying the custom questions for this registration. |
|
| 45 | - * This gets used a few times throughout the request so its best to cache it |
|
| 46 | - * |
|
| 47 | - * @var EE_Registration_Custom_Questions_Form |
|
| 48 | - */ |
|
| 49 | - protected $_reg_custom_questions_form = null; |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * constructor |
|
| 54 | - * |
|
| 55 | - * @Constructor |
|
| 56 | - * @access public |
|
| 57 | - * @param bool $routing |
|
| 58 | - * @return Registrations_Admin_Page |
|
| 59 | - */ |
|
| 60 | - public function __construct($routing = true) |
|
| 61 | - { |
|
| 62 | - parent::__construct($routing); |
|
| 63 | - add_action('wp_loaded', array($this, 'wp_loaded')); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - |
|
| 67 | - public function wp_loaded() |
|
| 68 | - { |
|
| 69 | - // when adding a new registration... |
|
| 70 | - if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') { |
|
| 71 | - EE_System::do_not_cache(); |
|
| 72 | - if (! isset($this->_req_data['processing_registration']) |
|
| 73 | - || absint($this->_req_data['processing_registration']) !== 1 |
|
| 74 | - ) { |
|
| 75 | - // and it's NOT the attendee information reg step |
|
| 76 | - // force cookie expiration by setting time to last week |
|
| 77 | - setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/'); |
|
| 78 | - // and update the global |
|
| 79 | - $_COOKIE['ee_registration_added'] = 0; |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - |
|
| 85 | - protected function _init_page_props() |
|
| 86 | - { |
|
| 87 | - $this->page_slug = REG_PG_SLUG; |
|
| 88 | - $this->_admin_base_url = REG_ADMIN_URL; |
|
| 89 | - $this->_admin_base_path = REG_ADMIN; |
|
| 90 | - $this->page_label = esc_html__('Registrations', 'event_espresso'); |
|
| 91 | - $this->_cpt_routes = array( |
|
| 92 | - 'add_new_attendee' => 'espresso_attendees', |
|
| 93 | - 'edit_attendee' => 'espresso_attendees', |
|
| 94 | - 'insert_attendee' => 'espresso_attendees', |
|
| 95 | - 'update_attendee' => 'espresso_attendees', |
|
| 96 | - ); |
|
| 97 | - $this->_cpt_model_names = array( |
|
| 98 | - 'add_new_attendee' => 'EEM_Attendee', |
|
| 99 | - 'edit_attendee' => 'EEM_Attendee', |
|
| 100 | - ); |
|
| 101 | - $this->_cpt_edit_routes = array( |
|
| 102 | - 'espresso_attendees' => 'edit_attendee', |
|
| 103 | - ); |
|
| 104 | - $this->_pagenow_map = array( |
|
| 105 | - 'add_new_attendee' => 'post-new.php', |
|
| 106 | - 'edit_attendee' => 'post.php', |
|
| 107 | - 'trash' => 'post.php', |
|
| 108 | - ); |
|
| 109 | - add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10); |
|
| 110 | - //add filters so that the comment urls don't take users to a confusing 404 page |
|
| 111 | - add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - |
|
| 115 | - public function clear_comment_link($link, $comment, $args) |
|
| 116 | - { |
|
| 117 | - //gotta make sure this only happens on this route |
|
| 118 | - $post_type = get_post_type($comment->comment_post_ID); |
|
| 119 | - if ($post_type === 'espresso_attendees') { |
|
| 120 | - return '#commentsdiv'; |
|
| 121 | - } |
|
| 122 | - return $link; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - protected function _ajax_hooks() |
|
| 127 | - { |
|
| 128 | - //todo: all hooks for registrations ajax goes in here |
|
| 129 | - add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status')); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - |
|
| 133 | - protected function _define_page_props() |
|
| 134 | - { |
|
| 135 | - $this->_admin_page_title = $this->page_label; |
|
| 136 | - $this->_labels = array( |
|
| 137 | - 'buttons' => array( |
|
| 138 | - 'add-registrant' => esc_html__('Add New Registration', 'event_espresso'), |
|
| 139 | - 'add-attendee' => esc_html__('Add Contact', 'event_espresso'), |
|
| 140 | - 'edit' => esc_html__('Edit Contact', 'event_espresso'), |
|
| 141 | - 'report' => esc_html__("Event Registrations CSV Report", "event_espresso"), |
|
| 142 | - 'report_all' => esc_html__('All Registrations CSV Report', 'event_espresso'), |
|
| 143 | - 'report_filtered' => esc_html__('Filtered CSV Report', 'event_espresso'), |
|
| 144 | - 'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'), |
|
| 145 | - 'contact_list_export' => esc_html__("Export Data", "event_espresso"), |
|
| 146 | - ), |
|
| 147 | - 'publishbox' => array( |
|
| 148 | - 'add_new_attendee' => esc_html__("Add Contact Record", 'event_espresso'), |
|
| 149 | - 'edit_attendee' => esc_html__("Update Contact Record", 'event_espresso'), |
|
| 150 | - ), |
|
| 151 | - 'hide_add_button_on_cpt_route' => array( |
|
| 152 | - 'edit_attendee' => true, |
|
| 153 | - ), |
|
| 154 | - ); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * grab url requests and route them |
|
| 160 | - * |
|
| 161 | - * @access private |
|
| 162 | - * @return void |
|
| 163 | - */ |
|
| 164 | - public function _set_page_routes() |
|
| 165 | - { |
|
| 166 | - $this->_get_registration_status_array(); |
|
| 167 | - $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
|
| 168 | - ? $this->_req_data['_REG_ID'] : 0; |
|
| 169 | - $reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID']) |
|
| 170 | - ? $this->_req_data['reg_status_change_form']['REG_ID'] |
|
| 171 | - : $reg_id; |
|
| 172 | - $att_id = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID']) |
|
| 173 | - ? $this->_req_data['ATT_ID'] : 0; |
|
| 174 | - $att_id = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post']) |
|
| 175 | - ? $this->_req_data['post'] |
|
| 176 | - : $att_id; |
|
| 177 | - $this->_page_routes = array( |
|
| 178 | - 'default' => array( |
|
| 179 | - 'func' => '_registrations_overview_list_table', |
|
| 180 | - 'capability' => 'ee_read_registrations', |
|
| 181 | - ), |
|
| 182 | - 'view_registration' => array( |
|
| 183 | - 'func' => '_registration_details', |
|
| 184 | - 'capability' => 'ee_read_registration', |
|
| 185 | - 'obj_id' => $reg_id, |
|
| 186 | - ), |
|
| 187 | - 'edit_registration' => array( |
|
| 188 | - 'func' => '_update_attendee_registration_form', |
|
| 189 | - 'noheader' => true, |
|
| 190 | - 'headers_sent_route' => 'view_registration', |
|
| 191 | - 'capability' => 'ee_edit_registration', |
|
| 192 | - 'obj_id' => $reg_id, |
|
| 193 | - '_REG_ID' => $reg_id, |
|
| 194 | - ), |
|
| 195 | - 'trash_registrations' => array( |
|
| 196 | - 'func' => '_trash_or_restore_registrations', |
|
| 197 | - 'args' => array('trash' => true), |
|
| 198 | - 'noheader' => true, |
|
| 199 | - 'capability' => 'ee_delete_registrations', |
|
| 200 | - ), |
|
| 201 | - 'restore_registrations' => array( |
|
| 202 | - 'func' => '_trash_or_restore_registrations', |
|
| 203 | - 'args' => array('trash' => false), |
|
| 204 | - 'noheader' => true, |
|
| 205 | - 'capability' => 'ee_delete_registrations', |
|
| 206 | - ), |
|
| 207 | - 'delete_registrations' => array( |
|
| 208 | - 'func' => '_delete_registrations', |
|
| 209 | - 'noheader' => true, |
|
| 210 | - 'capability' => 'ee_delete_registrations', |
|
| 211 | - ), |
|
| 212 | - 'new_registration' => array( |
|
| 213 | - 'func' => 'new_registration', |
|
| 214 | - 'capability' => 'ee_edit_registrations', |
|
| 215 | - ), |
|
| 216 | - 'process_reg_step' => array( |
|
| 217 | - 'func' => 'process_reg_step', |
|
| 218 | - 'noheader' => true, |
|
| 219 | - 'capability' => 'ee_edit_registrations', |
|
| 220 | - ), |
|
| 221 | - 'redirect_to_txn' => array( |
|
| 222 | - 'func' => 'redirect_to_txn', |
|
| 223 | - 'noheader' => true, |
|
| 224 | - 'capability' => 'ee_edit_registrations', |
|
| 225 | - ), |
|
| 226 | - 'change_reg_status' => array( |
|
| 227 | - 'func' => '_change_reg_status', |
|
| 228 | - 'noheader' => true, |
|
| 229 | - 'capability' => 'ee_edit_registration', |
|
| 230 | - 'obj_id' => $reg_id, |
|
| 231 | - ), |
|
| 232 | - 'approve_registration' => array( |
|
| 233 | - 'func' => 'approve_registration', |
|
| 234 | - 'noheader' => true, |
|
| 235 | - 'capability' => 'ee_edit_registration', |
|
| 236 | - 'obj_id' => $reg_id, |
|
| 237 | - ), |
|
| 238 | - 'approve_and_notify_registration' => array( |
|
| 239 | - 'func' => 'approve_registration', |
|
| 240 | - 'noheader' => true, |
|
| 241 | - 'args' => array(true), |
|
| 242 | - 'capability' => 'ee_edit_registration', |
|
| 243 | - 'obj_id' => $reg_id, |
|
| 244 | - ), |
|
| 245 | - 'approve_registrations' => array( |
|
| 246 | - 'func' => 'bulk_action_on_registrations', |
|
| 247 | - 'noheader' => true, |
|
| 248 | - 'capability' => 'ee_edit_registrations', |
|
| 249 | - 'args' => array('approve') |
|
| 250 | - ), |
|
| 251 | - 'approve_and_notify_registrations' => array( |
|
| 252 | - 'func' => 'bulk_action_on_registrations', |
|
| 253 | - 'noheader' => true, |
|
| 254 | - 'capability' => 'ee_edit_registrations', |
|
| 255 | - 'args' => array('approve', true) |
|
| 256 | - ), |
|
| 257 | - 'decline_registration' => array( |
|
| 258 | - 'func' => 'decline_registration', |
|
| 259 | - 'noheader' => true, |
|
| 260 | - 'capability' => 'ee_edit_registration', |
|
| 261 | - 'obj_id' => $reg_id, |
|
| 262 | - ), |
|
| 263 | - 'decline_and_notify_registration' => array( |
|
| 264 | - 'func' => 'decline_registration', |
|
| 265 | - 'noheader' => true, |
|
| 266 | - 'args' => array(true), |
|
| 267 | - 'capability' => 'ee_edit_registration', |
|
| 268 | - 'obj_id' => $reg_id, |
|
| 269 | - ), |
|
| 270 | - 'decline_registrations' => array( |
|
| 271 | - 'func' => 'bulk_action_on_registrations', |
|
| 272 | - 'noheader' => true, |
|
| 273 | - 'capability' => 'ee_edit_registrations', |
|
| 274 | - 'args' => array('decline') |
|
| 275 | - ), |
|
| 276 | - 'decline_and_notify_registrations' => array( |
|
| 277 | - 'func' => 'bulk_action_on_registrations', |
|
| 278 | - 'noheader' => true, |
|
| 279 | - 'capability' => 'ee_edit_registrations', |
|
| 280 | - 'args' => array('decline', true) |
|
| 281 | - ), |
|
| 282 | - 'pending_registration' => array( |
|
| 283 | - 'func' => 'pending_registration', |
|
| 284 | - 'noheader' => true, |
|
| 285 | - 'capability' => 'ee_edit_registration', |
|
| 286 | - 'obj_id' => $reg_id, |
|
| 287 | - ), |
|
| 288 | - 'pending_and_notify_registration' => array( |
|
| 289 | - 'func' => 'pending_registration', |
|
| 290 | - 'noheader' => true, |
|
| 291 | - 'args' => array(true), |
|
| 292 | - 'capability' => 'ee_edit_registration', |
|
| 293 | - 'obj_id' => $reg_id, |
|
| 294 | - ), |
|
| 295 | - 'pending_registrations' => array( |
|
| 296 | - 'func' => 'bulk_action_on_registrations', |
|
| 297 | - 'noheader' => true, |
|
| 298 | - 'capability' => 'ee_edit_registrations', |
|
| 299 | - 'args' => array('pending') |
|
| 300 | - ), |
|
| 301 | - 'pending_and_notify_registrations' => array( |
|
| 302 | - 'func' => 'bulk_action_on_registrations', |
|
| 303 | - 'noheader' => true, |
|
| 304 | - 'capability' => 'ee_edit_registrations', |
|
| 305 | - 'args' => array('pending', true) |
|
| 306 | - ), |
|
| 307 | - 'no_approve_registration' => array( |
|
| 308 | - 'func' => 'not_approve_registration', |
|
| 309 | - 'noheader' => true, |
|
| 310 | - 'capability' => 'ee_edit_registration', |
|
| 311 | - 'obj_id' => $reg_id, |
|
| 312 | - ), |
|
| 313 | - 'no_approve_and_notify_registration' => array( |
|
| 314 | - 'func' => 'not_approve_registration', |
|
| 315 | - 'noheader' => true, |
|
| 316 | - 'args' => array(true), |
|
| 317 | - 'capability' => 'ee_edit_registration', |
|
| 318 | - 'obj_id' => $reg_id, |
|
| 319 | - ), |
|
| 320 | - 'no_approve_registrations' => array( |
|
| 321 | - 'func' => 'bulk_action_on_registrations', |
|
| 322 | - 'noheader' => true, |
|
| 323 | - 'capability' => 'ee_edit_registrations', |
|
| 324 | - 'args' => array('not_approve') |
|
| 325 | - ), |
|
| 326 | - 'no_approve_and_notify_registrations' => array( |
|
| 327 | - 'func' => 'bulk_action_on_registrations', |
|
| 328 | - 'noheader' => true, |
|
| 329 | - 'capability' => 'ee_edit_registrations', |
|
| 330 | - 'args' => array('not_approve', true) |
|
| 331 | - ), |
|
| 332 | - 'cancel_registration' => array( |
|
| 333 | - 'func' => 'cancel_registration', |
|
| 334 | - 'noheader' => true, |
|
| 335 | - 'capability' => 'ee_edit_registration', |
|
| 336 | - 'obj_id' => $reg_id, |
|
| 337 | - ), |
|
| 338 | - 'cancel_and_notify_registration' => array( |
|
| 339 | - 'func' => 'cancel_registration', |
|
| 340 | - 'noheader' => true, |
|
| 341 | - 'args' => array(true), |
|
| 342 | - 'capability' => 'ee_edit_registration', |
|
| 343 | - 'obj_id' => $reg_id, |
|
| 344 | - ), |
|
| 345 | - 'cancel_registrations' => array( |
|
| 346 | - 'func' => 'bulk_action_on_registrations', |
|
| 347 | - 'noheader' => true, |
|
| 348 | - 'capability' => 'ee_edit_registrations', |
|
| 349 | - 'args' => array('cancel') |
|
| 350 | - ), |
|
| 351 | - 'cancel_and_notify_registrations' => array( |
|
| 352 | - 'func' => 'bulk_action_on_registrations', |
|
| 353 | - 'noheader' => true, |
|
| 354 | - 'capability' => 'ee_edit_registrations', |
|
| 355 | - 'args' => array('cancel', true) |
|
| 356 | - ), |
|
| 357 | - 'wait_list_registration' => array( |
|
| 358 | - 'func' => 'wait_list_registration', |
|
| 359 | - 'noheader' => true, |
|
| 360 | - 'capability' => 'ee_edit_registration', |
|
| 361 | - 'obj_id' => $reg_id, |
|
| 362 | - ), |
|
| 363 | - 'contact_list' => array( |
|
| 364 | - 'func' => '_attendee_contact_list_table', |
|
| 365 | - 'capability' => 'ee_read_contacts', |
|
| 366 | - ), |
|
| 367 | - 'add_new_attendee' => array( |
|
| 368 | - 'func' => '_create_new_cpt_item', |
|
| 369 | - 'args' => array( |
|
| 370 | - 'new_attendee' => true, |
|
| 371 | - 'capability' => 'ee_edit_contacts', |
|
| 372 | - ), |
|
| 373 | - ), |
|
| 374 | - 'edit_attendee' => array( |
|
| 375 | - 'func' => '_edit_cpt_item', |
|
| 376 | - 'capability' => 'ee_edit_contacts', |
|
| 377 | - 'obj_id' => $att_id, |
|
| 378 | - ), |
|
| 379 | - 'duplicate_attendee' => array( |
|
| 380 | - 'func' => '_duplicate_attendee', |
|
| 381 | - 'noheader' => true, |
|
| 382 | - 'capability' => 'ee_edit_contacts', |
|
| 383 | - 'obj_id' => $att_id, |
|
| 384 | - ), |
|
| 385 | - 'insert_attendee' => array( |
|
| 386 | - 'func' => '_insert_or_update_attendee', |
|
| 387 | - 'args' => array( |
|
| 388 | - 'new_attendee' => true, |
|
| 389 | - ), |
|
| 390 | - 'noheader' => true, |
|
| 391 | - 'capability' => 'ee_edit_contacts', |
|
| 392 | - ), |
|
| 393 | - 'update_attendee' => array( |
|
| 394 | - 'func' => '_insert_or_update_attendee', |
|
| 395 | - 'args' => array( |
|
| 396 | - 'new_attendee' => false, |
|
| 397 | - ), |
|
| 398 | - 'noheader' => true, |
|
| 399 | - 'capability' => 'ee_edit_contacts', |
|
| 400 | - 'obj_id' => $att_id, |
|
| 401 | - ), |
|
| 402 | - 'trash_attendees' => array( |
|
| 403 | - 'func' => '_trash_or_restore_attendees', |
|
| 404 | - 'args' => array( |
|
| 405 | - 'trash' => 'true' |
|
| 406 | - ), |
|
| 407 | - 'noheader' => true, |
|
| 408 | - 'capability' => 'ee_delete_contacts' |
|
| 409 | - ), |
|
| 410 | - 'trash_attendee' => array( |
|
| 411 | - 'func' => '_trash_or_restore_attendees', |
|
| 412 | - 'args' => array( |
|
| 413 | - 'trash' => true, |
|
| 414 | - ), |
|
| 415 | - 'noheader' => true, |
|
| 416 | - 'capability' => 'ee_delete_contacts', |
|
| 417 | - 'obj_id' => $att_id, |
|
| 418 | - ), |
|
| 419 | - 'restore_attendees' => array( |
|
| 420 | - 'func' => '_trash_or_restore_attendees', |
|
| 421 | - 'args' => array( |
|
| 422 | - 'trash' => false, |
|
| 423 | - ), |
|
| 424 | - 'noheader' => true, |
|
| 425 | - 'capability' => 'ee_delete_contacts', |
|
| 426 | - 'obj_id' => $att_id, |
|
| 427 | - ), |
|
| 428 | - 'resend_registration' => array( |
|
| 429 | - 'func' => '_resend_registration', |
|
| 430 | - 'noheader' => true, |
|
| 431 | - 'capability' => 'ee_send_message', |
|
| 432 | - ), |
|
| 433 | - 'registrations_report' => array( |
|
| 434 | - 'func' => '_registrations_report', |
|
| 435 | - 'noheader' => true, |
|
| 436 | - 'capability' => 'ee_read_registrations', |
|
| 437 | - ), |
|
| 438 | - 'contact_list_export' => array( |
|
| 439 | - 'func' => '_contact_list_export', |
|
| 440 | - 'noheader' => true, |
|
| 441 | - 'capability' => 'export', |
|
| 442 | - ), |
|
| 443 | - 'contact_list_report' => array( |
|
| 444 | - 'func' => '_contact_list_report', |
|
| 445 | - 'noheader' => true, |
|
| 446 | - 'capability' => 'ee_read_contacts', |
|
| 447 | - ), |
|
| 448 | - ); |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - |
|
| 452 | - protected function _set_page_config() |
|
| 453 | - { |
|
| 454 | - $this->_page_config = array( |
|
| 455 | - 'default' => array( |
|
| 456 | - 'nav' => array( |
|
| 457 | - 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 458 | - 'order' => 5, |
|
| 459 | - ), |
|
| 460 | - 'help_tabs' => array( |
|
| 461 | - 'registrations_overview_help_tab' => array( |
|
| 462 | - 'title' => esc_html__('Registrations Overview', 'event_espresso'), |
|
| 463 | - 'filename' => 'registrations_overview', |
|
| 464 | - ), |
|
| 465 | - 'registrations_overview_table_column_headings_help_tab' => array( |
|
| 466 | - 'title' => esc_html__('Registrations Table Column Headings', 'event_espresso'), |
|
| 467 | - 'filename' => 'registrations_overview_table_column_headings', |
|
| 468 | - ), |
|
| 469 | - 'registrations_overview_filters_help_tab' => array( |
|
| 470 | - 'title' => esc_html__('Registration Filters', 'event_espresso'), |
|
| 471 | - 'filename' => 'registrations_overview_filters', |
|
| 472 | - ), |
|
| 473 | - 'registrations_overview_views_help_tab' => array( |
|
| 474 | - 'title' => esc_html__('Registration Views', 'event_espresso'), |
|
| 475 | - 'filename' => 'registrations_overview_views', |
|
| 476 | - ), |
|
| 477 | - 'registrations_regoverview_other_help_tab' => array( |
|
| 478 | - 'title' => esc_html__('Registrations Other', 'event_espresso'), |
|
| 479 | - 'filename' => 'registrations_overview_other', |
|
| 480 | - ), |
|
| 481 | - ), |
|
| 482 | - 'help_tour' => array('Registration_Overview_Help_Tour'), |
|
| 483 | - 'qtips' => array('Registration_List_Table_Tips'), |
|
| 484 | - 'list_table' => 'EE_Registrations_List_Table', |
|
| 485 | - 'require_nonce' => false, |
|
| 486 | - ), |
|
| 487 | - 'view_registration' => array( |
|
| 488 | - 'nav' => array( |
|
| 489 | - 'label' => esc_html__('REG Details', 'event_espresso'), |
|
| 490 | - 'order' => 15, |
|
| 491 | - 'url' => isset($this->_req_data['_REG_ID']) |
|
| 492 | - ? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url) |
|
| 493 | - : $this->_admin_base_url, |
|
| 494 | - 'persistent' => false, |
|
| 495 | - ), |
|
| 496 | - 'help_tabs' => array( |
|
| 497 | - 'registrations_details_help_tab' => array( |
|
| 498 | - 'title' => esc_html__('Registration Details', 'event_espresso'), |
|
| 499 | - 'filename' => 'registrations_details', |
|
| 500 | - ), |
|
| 501 | - 'registrations_details_table_help_tab' => array( |
|
| 502 | - 'title' => esc_html__('Registration Details Table', 'event_espresso'), |
|
| 503 | - 'filename' => 'registrations_details_table', |
|
| 504 | - ), |
|
| 505 | - 'registrations_details_form_answers_help_tab' => array( |
|
| 506 | - 'title' => esc_html__('Registration Form Answers', 'event_espresso'), |
|
| 507 | - 'filename' => 'registrations_details_form_answers', |
|
| 508 | - ), |
|
| 509 | - 'registrations_details_registrant_details_help_tab' => array( |
|
| 510 | - 'title' => esc_html__('Contact Details', 'event_espresso'), |
|
| 511 | - 'filename' => 'registrations_details_registrant_details', |
|
| 512 | - ), |
|
| 513 | - ), |
|
| 514 | - 'help_tour' => array('Registration_Details_Help_Tour'), |
|
| 515 | - 'metaboxes' => array_merge( |
|
| 516 | - $this->_default_espresso_metaboxes, |
|
| 517 | - array('_registration_details_metaboxes') |
|
| 518 | - ), |
|
| 519 | - 'require_nonce' => false, |
|
| 520 | - ), |
|
| 521 | - 'new_registration' => array( |
|
| 522 | - 'nav' => array( |
|
| 523 | - 'label' => esc_html__('Add New Registration', 'event_espresso'), |
|
| 524 | - 'url' => '#', |
|
| 525 | - 'order' => 15, |
|
| 526 | - 'persistent' => false, |
|
| 527 | - ), |
|
| 528 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 529 | - 'labels' => array( |
|
| 530 | - 'publishbox' => esc_html__('Save Registration', 'event_espresso'), |
|
| 531 | - ), |
|
| 532 | - 'require_nonce' => false, |
|
| 533 | - ), |
|
| 534 | - 'add_new_attendee' => array( |
|
| 535 | - 'nav' => array( |
|
| 536 | - 'label' => esc_html__('Add Contact', 'event_espresso'), |
|
| 537 | - 'order' => 15, |
|
| 538 | - 'persistent' => false, |
|
| 539 | - ), |
|
| 540 | - 'metaboxes' => array_merge( |
|
| 541 | - $this->_default_espresso_metaboxes, |
|
| 542 | - array('_publish_post_box', 'attendee_editor_metaboxes') |
|
| 543 | - ), |
|
| 544 | - 'require_nonce' => false, |
|
| 545 | - ), |
|
| 546 | - 'edit_attendee' => array( |
|
| 547 | - 'nav' => array( |
|
| 548 | - 'label' => esc_html__('Edit Contact', 'event_espresso'), |
|
| 549 | - 'order' => 15, |
|
| 550 | - 'persistent' => false, |
|
| 551 | - 'url' => isset($this->_req_data['ATT_ID']) |
|
| 552 | - ? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url) |
|
| 553 | - : $this->_admin_base_url, |
|
| 554 | - ), |
|
| 555 | - 'metaboxes' => array('attendee_editor_metaboxes'), |
|
| 556 | - 'require_nonce' => false, |
|
| 557 | - ), |
|
| 558 | - 'contact_list' => array( |
|
| 559 | - 'nav' => array( |
|
| 560 | - 'label' => esc_html__('Contact List', 'event_espresso'), |
|
| 561 | - 'order' => 20, |
|
| 562 | - ), |
|
| 563 | - 'list_table' => 'EE_Attendee_Contact_List_Table', |
|
| 564 | - 'help_tabs' => array( |
|
| 565 | - 'registrations_contact_list_help_tab' => array( |
|
| 566 | - 'title' => esc_html__('Registrations Contact List', 'event_espresso'), |
|
| 567 | - 'filename' => 'registrations_contact_list', |
|
| 568 | - ), |
|
| 569 | - 'registrations_contact-list_table_column_headings_help_tab' => array( |
|
| 570 | - 'title' => esc_html__('Contact List Table Column Headings', 'event_espresso'), |
|
| 571 | - 'filename' => 'registrations_contact_list_table_column_headings', |
|
| 572 | - ), |
|
| 573 | - 'registrations_contact_list_views_help_tab' => array( |
|
| 574 | - 'title' => esc_html__('Contact List Views', 'event_espresso'), |
|
| 575 | - 'filename' => 'registrations_contact_list_views', |
|
| 576 | - ), |
|
| 577 | - 'registrations_contact_list_other_help_tab' => array( |
|
| 578 | - 'title' => esc_html__('Contact List Other', 'event_espresso'), |
|
| 579 | - 'filename' => 'registrations_contact_list_other', |
|
| 580 | - ), |
|
| 581 | - ), |
|
| 582 | - 'help_tour' => array('Contact_List_Help_Tour'), |
|
| 583 | - 'metaboxes' => array(), |
|
| 584 | - 'require_nonce' => false, |
|
| 585 | - ), |
|
| 586 | - //override default cpt routes |
|
| 587 | - 'create_new' => '', |
|
| 588 | - 'edit' => '', |
|
| 589 | - ); |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - |
|
| 593 | - /** |
|
| 594 | - * The below methods aren't used by this class currently |
|
| 595 | - */ |
|
| 596 | - protected function _add_screen_options() |
|
| 597 | - { |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - |
|
| 601 | - protected function _add_feature_pointers() |
|
| 602 | - { |
|
| 603 | - } |
|
| 604 | - |
|
| 605 | - |
|
| 606 | - public function admin_init() |
|
| 607 | - { |
|
| 608 | - EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__( |
|
| 609 | - 'click "Update Registration Questions" to save your changes', |
|
| 610 | - 'event_espresso' |
|
| 611 | - ); |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - |
|
| 615 | - public function admin_notices() |
|
| 616 | - { |
|
| 617 | - } |
|
| 618 | - |
|
| 619 | - |
|
| 620 | - public function admin_footer_scripts() |
|
| 621 | - { |
|
| 622 | - } |
|
| 623 | - |
|
| 624 | - |
|
| 625 | - /** |
|
| 626 | - * get list of registration statuses |
|
| 627 | - * |
|
| 628 | - * @access private |
|
| 629 | - * @return void |
|
| 630 | - */ |
|
| 631 | - private function _get_registration_status_array() |
|
| 632 | - { |
|
| 633 | - self::$_reg_status = EEM_Registration::reg_status_array(array(), true); |
|
| 634 | - } |
|
| 635 | - |
|
| 636 | - |
|
| 637 | - protected function _add_screen_options_default() |
|
| 638 | - { |
|
| 639 | - $this->_per_page_screen_option(); |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - |
|
| 643 | - protected function _add_screen_options_contact_list() |
|
| 644 | - { |
|
| 645 | - $page_title = $this->_admin_page_title; |
|
| 646 | - $this->_admin_page_title = esc_html__("Contacts", 'event_espresso'); |
|
| 647 | - $this->_per_page_screen_option(); |
|
| 648 | - $this->_admin_page_title = $page_title; |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - |
|
| 652 | - public function load_scripts_styles() |
|
| 653 | - { |
|
| 654 | - //style |
|
| 655 | - wp_register_style( |
|
| 656 | - 'espresso_reg', |
|
| 657 | - REG_ASSETS_URL . 'espresso_registrations_admin.css', |
|
| 658 | - array('ee-admin-css'), |
|
| 659 | - EVENT_ESPRESSO_VERSION |
|
| 660 | - ); |
|
| 661 | - wp_enqueue_style('espresso_reg'); |
|
| 662 | - //script |
|
| 663 | - wp_register_script( |
|
| 664 | - 'espresso_reg', |
|
| 665 | - REG_ASSETS_URL . 'espresso_registrations_admin.js', |
|
| 666 | - array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'), |
|
| 667 | - EVENT_ESPRESSO_VERSION, |
|
| 668 | - true |
|
| 669 | - ); |
|
| 670 | - wp_enqueue_script('espresso_reg'); |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - |
|
| 674 | - public function load_scripts_styles_edit_attendee() |
|
| 675 | - { |
|
| 676 | - //stuff to only show up on our attendee edit details page. |
|
| 677 | - $attendee_details_translations = array( |
|
| 678 | - 'att_publish_text' => sprintf( |
|
| 679 | - esc_html__('Created on: <b>%1$s</b>', 'event_espresso'), |
|
| 680 | - $this->_cpt_model_obj->get_datetime('ATT_created') |
|
| 681 | - ), |
|
| 682 | - ); |
|
| 683 | - wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations); |
|
| 684 | - wp_enqueue_script('jquery-validate'); |
|
| 685 | - } |
|
| 686 | - |
|
| 687 | - |
|
| 688 | - public function load_scripts_styles_view_registration() |
|
| 689 | - { |
|
| 690 | - //styles |
|
| 691 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 692 | - //scripts |
|
| 693 | - $this->_get_reg_custom_questions_form($this->_registration->ID()); |
|
| 694 | - $this->_reg_custom_questions_form->wp_enqueue_scripts(true); |
|
| 695 | - } |
|
| 696 | - |
|
| 697 | - |
|
| 698 | - public function load_scripts_styles_contact_list() |
|
| 699 | - { |
|
| 700 | - wp_deregister_style('espresso_reg'); |
|
| 701 | - wp_register_style( |
|
| 702 | - 'espresso_att', |
|
| 703 | - REG_ASSETS_URL . 'espresso_attendees_admin.css', |
|
| 704 | - array('ee-admin-css'), |
|
| 705 | - EVENT_ESPRESSO_VERSION |
|
| 706 | - ); |
|
| 707 | - wp_enqueue_style('espresso_att'); |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - |
|
| 711 | - public function load_scripts_styles_new_registration() |
|
| 712 | - { |
|
| 713 | - wp_register_script( |
|
| 714 | - 'ee-spco-for-admin', |
|
| 715 | - REG_ASSETS_URL . 'spco_for_admin.js', |
|
| 716 | - array('underscore', 'jquery'), |
|
| 717 | - EVENT_ESPRESSO_VERSION, |
|
| 718 | - true |
|
| 719 | - ); |
|
| 720 | - wp_enqueue_script('ee-spco-for-admin'); |
|
| 721 | - add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
| 722 | - EE_Form_Section_Proper::wp_enqueue_scripts(); |
|
| 723 | - EED_Ticket_Selector::load_tckt_slctr_assets(); |
|
| 724 | - EE_Datepicker_Input::enqueue_styles_and_scripts(); |
|
| 725 | - } |
|
| 726 | - |
|
| 727 | - |
|
| 728 | - public function AHEE__EE_Admin_Page__route_admin_request_resend_registration() |
|
| 729 | - { |
|
| 730 | - add_filter('FHEE_load_EE_messages', '__return_true'); |
|
| 731 | - } |
|
| 732 | - |
|
| 733 | - |
|
| 734 | - public function AHEE__EE_Admin_Page__route_admin_request_approve_registration() |
|
| 735 | - { |
|
| 736 | - add_filter('FHEE_load_EE_messages', '__return_true'); |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - |
|
| 740 | - protected function _set_list_table_views_default() |
|
| 741 | - { |
|
| 742 | - //for notification related bulk actions we need to make sure only active messengers have an option. |
|
| 743 | - EED_Messages::set_autoloaders(); |
|
| 744 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 745 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 746 | - $active_mts = $message_resource_manager->list_of_active_message_types(); |
|
| 747 | - //key= bulk_action_slug, value= message type. |
|
| 748 | - $match_array = array( |
|
| 749 | - 'approve_registrations' => 'registration', |
|
| 750 | - 'decline_registrations' => 'declined_registration', |
|
| 751 | - 'pending_registrations' => 'pending_approval', |
|
| 752 | - 'no_approve_registrations' => 'not_approved_registration', |
|
| 753 | - 'cancel_registrations' => 'cancelled_registration', |
|
| 754 | - ); |
|
| 755 | - $can_send = EE_Registry::instance()->CAP->current_user_can( |
|
| 756 | - 'ee_send_message', |
|
| 757 | - 'batch_send_messages' |
|
| 758 | - ); |
|
| 759 | - /** setup reg status bulk actions **/ |
|
| 760 | - $def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso'); |
|
| 761 | - if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) { |
|
| 762 | - $def_reg_status_actions['approve_and_notify_registrations'] = esc_html__( |
|
| 763 | - 'Approve and Notify Registrations', |
|
| 764 | - 'event_espresso' |
|
| 765 | - ); |
|
| 766 | - } |
|
| 767 | - $def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso'); |
|
| 768 | - if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) { |
|
| 769 | - $def_reg_status_actions['decline_and_notify_registrations'] = esc_html__( |
|
| 770 | - 'Decline and Notify Registrations', |
|
| 771 | - 'event_espresso' |
|
| 772 | - ); |
|
| 773 | - } |
|
| 774 | - $def_reg_status_actions['pending_registrations'] = esc_html__( |
|
| 775 | - 'Set Registrations to Pending Payment', |
|
| 776 | - 'event_espresso' |
|
| 777 | - ); |
|
| 778 | - if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) { |
|
| 779 | - $def_reg_status_actions['pending_and_notify_registrations'] = esc_html__( |
|
| 780 | - 'Set Registrations to Pending Payment and Notify', |
|
| 781 | - 'event_espresso' |
|
| 782 | - ); |
|
| 783 | - } |
|
| 784 | - $def_reg_status_actions['no_approve_registrations'] = esc_html__( |
|
| 785 | - 'Set Registrations to Not Approved', |
|
| 786 | - 'event_espresso' |
|
| 787 | - ); |
|
| 788 | - if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) { |
|
| 789 | - $def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__( |
|
| 790 | - 'Set Registrations to Not Approved and Notify', |
|
| 791 | - 'event_espresso' |
|
| 792 | - ); |
|
| 793 | - } |
|
| 794 | - $def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso'); |
|
| 795 | - if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) { |
|
| 796 | - $def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__( |
|
| 797 | - 'Cancel Registrations and Notify', |
|
| 798 | - 'event_espresso' |
|
| 799 | - ); |
|
| 800 | - } |
|
| 801 | - $def_reg_status_actions = apply_filters( |
|
| 802 | - 'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array', |
|
| 803 | - $def_reg_status_actions, |
|
| 804 | - $active_mts |
|
| 805 | - ); |
|
| 806 | - |
|
| 807 | - $this->_views = array( |
|
| 808 | - 'all' => array( |
|
| 809 | - 'slug' => 'all', |
|
| 810 | - 'label' => esc_html__('View All Registrations', 'event_espresso'), |
|
| 811 | - 'count' => 0, |
|
| 812 | - 'bulk_action' => array_merge($def_reg_status_actions, array( |
|
| 813 | - 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
| 814 | - )), |
|
| 815 | - ), |
|
| 816 | - 'month' => array( |
|
| 817 | - 'slug' => 'month', |
|
| 818 | - 'label' => esc_html__('This Month', 'event_espresso'), |
|
| 819 | - 'count' => 0, |
|
| 820 | - 'bulk_action' => array_merge($def_reg_status_actions, array( |
|
| 821 | - 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
| 822 | - )), |
|
| 823 | - ), |
|
| 824 | - 'today' => array( |
|
| 825 | - 'slug' => 'today', |
|
| 826 | - 'label' => sprintf( |
|
| 827 | - esc_html__('Today - %s', 'event_espresso'), |
|
| 828 | - date('M d, Y', current_time('timestamp')) |
|
| 829 | - ), |
|
| 830 | - 'count' => 0, |
|
| 831 | - 'bulk_action' => array_merge($def_reg_status_actions, array( |
|
| 832 | - 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
| 833 | - )), |
|
| 834 | - ), |
|
| 835 | - ); |
|
| 836 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 837 | - 'ee_delete_registrations', |
|
| 838 | - 'espresso_registrations_delete_registration' |
|
| 839 | - )) { |
|
| 840 | - $this->_views['incomplete'] = array( |
|
| 841 | - 'slug' => 'incomplete', |
|
| 842 | - 'label' => esc_html__('Incomplete', 'event_espresso'), |
|
| 843 | - 'count' => 0, |
|
| 844 | - 'bulk_action' => array( |
|
| 845 | - 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
| 846 | - ), |
|
| 847 | - ); |
|
| 848 | - $this->_views['trash'] = array( |
|
| 849 | - 'slug' => 'trash', |
|
| 850 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 851 | - 'count' => 0, |
|
| 852 | - 'bulk_action' => array( |
|
| 853 | - 'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'), |
|
| 854 | - 'delete_registrations' => esc_html__('Delete Registrations Permanently', 'event_espresso'), |
|
| 855 | - ), |
|
| 856 | - ); |
|
| 857 | - } |
|
| 858 | - } |
|
| 859 | - |
|
| 860 | - |
|
| 861 | - protected function _set_list_table_views_contact_list() |
|
| 862 | - { |
|
| 863 | - $this->_views = array( |
|
| 864 | - 'in_use' => array( |
|
| 865 | - 'slug' => 'in_use', |
|
| 866 | - 'label' => esc_html__('In Use', 'event_espresso'), |
|
| 867 | - 'count' => 0, |
|
| 868 | - 'bulk_action' => array( |
|
| 869 | - 'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 870 | - ), |
|
| 871 | - ), |
|
| 872 | - ); |
|
| 873 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts', |
|
| 874 | - 'espresso_registrations_trash_attendees') |
|
| 875 | - ) { |
|
| 876 | - $this->_views['trash'] = array( |
|
| 877 | - 'slug' => 'trash', |
|
| 878 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 879 | - 'count' => 0, |
|
| 880 | - 'bulk_action' => array( |
|
| 881 | - 'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'), |
|
| 882 | - ), |
|
| 883 | - ); |
|
| 884 | - } |
|
| 885 | - } |
|
| 886 | - |
|
| 887 | - |
|
| 888 | - protected function _registration_legend_items() |
|
| 889 | - { |
|
| 890 | - $fc_items = array( |
|
| 891 | - 'star-icon' => array( |
|
| 892 | - 'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8', |
|
| 893 | - 'desc' => esc_html__('This is the Primary Registrant', 'event_espresso'), |
|
| 894 | - ), |
|
| 895 | - 'view_details' => array( |
|
| 896 | - 'class' => 'dashicons dashicons-clipboard', |
|
| 897 | - 'desc' => esc_html__('View Registration Details', 'event_espresso'), |
|
| 898 | - ), |
|
| 899 | - 'edit_attendee' => array( |
|
| 900 | - 'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16', |
|
| 901 | - 'desc' => esc_html__('Edit Contact Details', 'event_espresso'), |
|
| 902 | - ), |
|
| 903 | - 'view_transaction' => array( |
|
| 904 | - 'class' => 'dashicons dashicons-cart', |
|
| 905 | - 'desc' => esc_html__('View Transaction Details', 'event_espresso'), |
|
| 906 | - ), |
|
| 907 | - 'view_invoice' => array( |
|
| 908 | - 'class' => 'dashicons dashicons-media-spreadsheet', |
|
| 909 | - 'desc' => esc_html__('View Transaction Invoice', 'event_espresso'), |
|
| 910 | - ), |
|
| 911 | - ); |
|
| 912 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 913 | - 'ee_send_message', |
|
| 914 | - 'espresso_registrations_resend_registration' |
|
| 915 | - )) { |
|
| 916 | - $fc_items['resend_registration'] = array( |
|
| 917 | - 'class' => 'dashicons dashicons-email-alt', |
|
| 918 | - 'desc' => esc_html__('Resend Registration Details', 'event_espresso'), |
|
| 919 | - ); |
|
| 920 | - } else { |
|
| 921 | - $fc_items['blank'] = array('class' => 'blank', 'desc' => ''); |
|
| 922 | - } |
|
| 923 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 924 | - 'ee_read_global_messages', |
|
| 925 | - 'view_filtered_messages' |
|
| 926 | - )) { |
|
| 927 | - $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 928 | - if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) { |
|
| 929 | - $fc_items['view_related_messages'] = array( |
|
| 930 | - 'class' => $related_for_icon['css_class'], |
|
| 931 | - 'desc' => $related_for_icon['label'], |
|
| 932 | - ); |
|
| 933 | - } |
|
| 934 | - } |
|
| 935 | - $sc_items = array( |
|
| 936 | - 'approved_status' => array( |
|
| 937 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
| 938 | - 'desc' => EEH_Template::pretty_status( |
|
| 939 | - EEM_Registration::status_id_approved, |
|
| 940 | - false, |
|
| 941 | - 'sentence' |
|
| 942 | - ), |
|
| 943 | - ), |
|
| 944 | - 'pending_status' => array( |
|
| 945 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
| 946 | - 'desc' => EEH_Template::pretty_status( |
|
| 947 | - EEM_Registration::status_id_pending_payment, |
|
| 948 | - false, |
|
| 949 | - 'sentence' |
|
| 950 | - ), |
|
| 951 | - ), |
|
| 952 | - 'wait_list' => array( |
|
| 953 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
| 954 | - 'desc' => EEH_Template::pretty_status( |
|
| 955 | - EEM_Registration::status_id_wait_list, |
|
| 956 | - false, |
|
| 957 | - 'sentence' |
|
| 958 | - ), |
|
| 959 | - ), |
|
| 960 | - 'incomplete_status' => array( |
|
| 961 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete, |
|
| 962 | - 'desc' => EEH_Template::pretty_status( |
|
| 963 | - EEM_Registration::status_id_incomplete, |
|
| 964 | - false, |
|
| 965 | - 'sentence' |
|
| 966 | - ), |
|
| 967 | - ), |
|
| 968 | - 'not_approved' => array( |
|
| 969 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
| 970 | - 'desc' => EEH_Template::pretty_status( |
|
| 971 | - EEM_Registration::status_id_not_approved, |
|
| 972 | - false, |
|
| 973 | - 'sentence' |
|
| 974 | - ), |
|
| 975 | - ), |
|
| 976 | - 'declined_status' => array( |
|
| 977 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
| 978 | - 'desc' => EEH_Template::pretty_status( |
|
| 979 | - EEM_Registration::status_id_declined, |
|
| 980 | - false, |
|
| 981 | - 'sentence' |
|
| 982 | - ), |
|
| 983 | - ), |
|
| 984 | - 'cancelled_status' => array( |
|
| 985 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
| 986 | - 'desc' => EEH_Template::pretty_status( |
|
| 987 | - EEM_Registration::status_id_cancelled, |
|
| 988 | - false, |
|
| 989 | - 'sentence' |
|
| 990 | - ), |
|
| 991 | - ), |
|
| 992 | - ); |
|
| 993 | - return array_merge($fc_items, $sc_items); |
|
| 994 | - } |
|
| 995 | - |
|
| 996 | - |
|
| 997 | - |
|
| 998 | - /*************************************** REGISTRATION OVERVIEW **************************************/ |
|
| 999 | - /** |
|
| 1000 | - * @throws \EE_Error |
|
| 1001 | - */ |
|
| 1002 | - protected function _registrations_overview_list_table() |
|
| 1003 | - { |
|
| 1004 | - $this->_template_args['admin_page_header'] = ''; |
|
| 1005 | - $EVT_ID = ! empty($this->_req_data['event_id']) |
|
| 1006 | - ? absint($this->_req_data['event_id']) |
|
| 1007 | - : 0; |
|
| 1008 | - if ($EVT_ID) { |
|
| 1009 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 1010 | - 'ee_edit_registrations', |
|
| 1011 | - 'espresso_registrations_new_registration', |
|
| 1012 | - $EVT_ID |
|
| 1013 | - )) { |
|
| 1014 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 1015 | - 'new_registration', |
|
| 1016 | - 'add-registrant', |
|
| 1017 | - array('event_id' => $EVT_ID), |
|
| 1018 | - 'add-new-h2' |
|
| 1019 | - ); |
|
| 1020 | - } |
|
| 1021 | - $event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 1022 | - if ($event instanceof EE_Event) { |
|
| 1023 | - $this->_template_args['admin_page_header'] = sprintf( |
|
| 1024 | - esc_html__( |
|
| 1025 | - '%s Viewing registrations for the event: %s%s', |
|
| 1026 | - 'event_espresso' |
|
| 1027 | - ), |
|
| 1028 | - '<h3 style="line-height:1.5em;">', |
|
| 1029 | - '<br /><a href="' |
|
| 1030 | - . EE_Admin_Page::add_query_args_and_nonce( |
|
| 1031 | - array( |
|
| 1032 | - 'action' => 'edit', |
|
| 1033 | - 'post' => $event->ID(), |
|
| 1034 | - ), |
|
| 1035 | - EVENTS_ADMIN_URL |
|
| 1036 | - ) |
|
| 1037 | - . '"> ' |
|
| 1038 | - . $event->get('EVT_name') |
|
| 1039 | - . ' </a> ', |
|
| 1040 | - '</h3>' |
|
| 1041 | - ); |
|
| 1042 | - } |
|
| 1043 | - $DTT_ID = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0; |
|
| 1044 | - $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID); |
|
| 1045 | - if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') { |
|
| 1046 | - $this->_template_args['admin_page_header'] = substr( |
|
| 1047 | - $this->_template_args['admin_page_header'], |
|
| 1048 | - 0, |
|
| 1049 | - -5 |
|
| 1050 | - ); |
|
| 1051 | - $this->_template_args['admin_page_header'] .= ' <span class="drk-grey-text">'; |
|
| 1052 | - $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>'; |
|
| 1053 | - $this->_template_args['admin_page_header'] .= $datetime->name(); |
|
| 1054 | - $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )'; |
|
| 1055 | - $this->_template_args['admin_page_header'] .= '</span></h3>'; |
|
| 1056 | - } |
|
| 1057 | - } |
|
| 1058 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items()); |
|
| 1059 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1060 | - } |
|
| 1061 | - |
|
| 1062 | - |
|
| 1063 | - /** |
|
| 1064 | - * This sets the _registration property for the registration details screen |
|
| 1065 | - * |
|
| 1066 | - * @access private |
|
| 1067 | - * @return bool |
|
| 1068 | - */ |
|
| 1069 | - private function _set_registration_object() |
|
| 1070 | - { |
|
| 1071 | - //get out if we've already set the object |
|
| 1072 | - if (is_object($this->_registration)) { |
|
| 1073 | - return true; |
|
| 1074 | - } |
|
| 1075 | - $REG = EEM_Registration::instance(); |
|
| 1076 | - $REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false; |
|
| 1077 | - if ($this->_registration = $REG->get_one_by_ID($REG_ID)) { |
|
| 1078 | - return true; |
|
| 1079 | - } else { |
|
| 1080 | - $error_msg = sprintf( |
|
| 1081 | - esc_html__( |
|
| 1082 | - 'An error occurred and the details for Registration ID #%s could not be retrieved.', |
|
| 1083 | - 'event_espresso' |
|
| 1084 | - ), |
|
| 1085 | - $REG_ID |
|
| 1086 | - ); |
|
| 1087 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1088 | - $this->_registration = null; |
|
| 1089 | - return false; |
|
| 1090 | - } |
|
| 1091 | - } |
|
| 1092 | - |
|
| 1093 | - |
|
| 1094 | - /** |
|
| 1095 | - * Used to retrieve registrations for the list table. |
|
| 1096 | - * |
|
| 1097 | - * @param int $per_page |
|
| 1098 | - * @param bool $count |
|
| 1099 | - * @param bool $this_month |
|
| 1100 | - * @param bool $today |
|
| 1101 | - * @return EE_Registration[]|int |
|
| 1102 | - * @throws EE_Error |
|
| 1103 | - */ |
|
| 1104 | - public function get_registrations( |
|
| 1105 | - $per_page = 10, |
|
| 1106 | - $count = false, |
|
| 1107 | - $this_month = false, |
|
| 1108 | - $today = false |
|
| 1109 | - ) { |
|
| 1110 | - if ($this_month) { |
|
| 1111 | - $this->_req_data['status'] = 'month'; |
|
| 1112 | - } |
|
| 1113 | - if ($today) { |
|
| 1114 | - $this->_req_data['status'] = 'today'; |
|
| 1115 | - } |
|
| 1116 | - $query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count); |
|
| 1117 | - /** |
|
| 1118 | - * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected |
|
| 1119 | - * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093 |
|
| 1120 | - * @see EEM_Base::get_all() |
|
| 1121 | - */ |
|
| 1122 | - $query_params['group_by'] = ''; |
|
| 1123 | - |
|
| 1124 | - return $count |
|
| 1125 | - ? EEM_Registration::instance()->count($query_params) |
|
| 1126 | - /** @type EE_Registration[] */ |
|
| 1127 | - : EEM_Registration::instance()->get_all($query_params); |
|
| 1128 | - } |
|
| 1129 | - |
|
| 1130 | - |
|
| 1131 | - |
|
| 1132 | - /** |
|
| 1133 | - * Retrieves the query parameters to be used by the Registration model for getting registrations. |
|
| 1134 | - * Note: this listens to values on the request for some of the query parameters. |
|
| 1135 | - * |
|
| 1136 | - * @param array $request |
|
| 1137 | - * @param int $per_page |
|
| 1138 | - * @param bool $count |
|
| 1139 | - * @return array |
|
| 1140 | - */ |
|
| 1141 | - protected function _get_registration_query_parameters( |
|
| 1142 | - $request = array(), |
|
| 1143 | - $per_page = 10, |
|
| 1144 | - $count = false |
|
| 1145 | - ) { |
|
| 1146 | - |
|
| 1147 | - $query_params = array( |
|
| 1148 | - 0 => $this->_get_where_conditions_for_registrations_query( |
|
| 1149 | - $request |
|
| 1150 | - ), |
|
| 1151 | - 'caps' => EEM_Registration::caps_read_admin, |
|
| 1152 | - 'default_where_conditions' => 'this_model_only', |
|
| 1153 | - ); |
|
| 1154 | - if (! $count) { |
|
| 1155 | - $query_params = array_merge( |
|
| 1156 | - $query_params, |
|
| 1157 | - $this->_get_orderby_for_registrations_query(), |
|
| 1158 | - $this->_get_limit($per_page) |
|
| 1159 | - ); |
|
| 1160 | - } |
|
| 1161 | - |
|
| 1162 | - return $query_params; |
|
| 1163 | - } |
|
| 1164 | - |
|
| 1165 | - |
|
| 1166 | - /** |
|
| 1167 | - * This will add EVT_ID to the provided $where array for EE model query parameters. |
|
| 1168 | - * |
|
| 1169 | - * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1170 | - * @return array |
|
| 1171 | - */ |
|
| 1172 | - protected function _add_event_id_to_where_conditions(array $request) |
|
| 1173 | - { |
|
| 1174 | - $where = array(); |
|
| 1175 | - if (! empty($request['event_id'])) { |
|
| 1176 | - $where['EVT_ID'] = absint($request['event_id']); |
|
| 1177 | - } |
|
| 1178 | - return $where; |
|
| 1179 | - } |
|
| 1180 | - |
|
| 1181 | - |
|
| 1182 | - /** |
|
| 1183 | - * Adds category ID if it exists in the request to the where conditions for the registrations query. |
|
| 1184 | - * |
|
| 1185 | - * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1186 | - * @return array |
|
| 1187 | - */ |
|
| 1188 | - protected function _add_category_id_to_where_conditions(array $request) |
|
| 1189 | - { |
|
| 1190 | - $where = array(); |
|
| 1191 | - if (! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) { |
|
| 1192 | - $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']); |
|
| 1193 | - } |
|
| 1194 | - return $where; |
|
| 1195 | - } |
|
| 1196 | - |
|
| 1197 | - |
|
| 1198 | - /** |
|
| 1199 | - * Adds the datetime ID if it exists in the request to the where conditions for the registrations query. |
|
| 1200 | - * |
|
| 1201 | - * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1202 | - * @return array |
|
| 1203 | - */ |
|
| 1204 | - protected function _add_datetime_id_to_where_conditions(array $request) |
|
| 1205 | - { |
|
| 1206 | - $where = array(); |
|
| 1207 | - if (! empty($request['datetime_id'])) { |
|
| 1208 | - $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']); |
|
| 1209 | - } |
|
| 1210 | - if (! empty($request['DTT_ID'])) { |
|
| 1211 | - $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']); |
|
| 1212 | - } |
|
| 1213 | - return $where; |
|
| 1214 | - } |
|
| 1215 | - |
|
| 1216 | - |
|
| 1217 | - /** |
|
| 1218 | - * Adds the correct registration status to the where conditions for the registrations query. |
|
| 1219 | - * |
|
| 1220 | - * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1221 | - * @return array |
|
| 1222 | - */ |
|
| 1223 | - protected function _add_registration_status_to_where_conditions(array $request) |
|
| 1224 | - { |
|
| 1225 | - $where = array(); |
|
| 1226 | - $view = EEH_Array::is_set($request, 'status', ''); |
|
| 1227 | - $registration_status = ! empty($request['_reg_status']) |
|
| 1228 | - ? sanitize_text_field($request['_reg_status']) |
|
| 1229 | - : ''; |
|
| 1230 | - |
|
| 1231 | - /* |
|
| 26 | + /** |
|
| 27 | + * @var EE_Registration |
|
| 28 | + */ |
|
| 29 | + private $_registration; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var EE_Event |
|
| 33 | + */ |
|
| 34 | + private $_reg_event; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var EE_Session |
|
| 38 | + */ |
|
| 39 | + private $_session; |
|
| 40 | + |
|
| 41 | + private static $_reg_status; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Form for displaying the custom questions for this registration. |
|
| 45 | + * This gets used a few times throughout the request so its best to cache it |
|
| 46 | + * |
|
| 47 | + * @var EE_Registration_Custom_Questions_Form |
|
| 48 | + */ |
|
| 49 | + protected $_reg_custom_questions_form = null; |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * constructor |
|
| 54 | + * |
|
| 55 | + * @Constructor |
|
| 56 | + * @access public |
|
| 57 | + * @param bool $routing |
|
| 58 | + * @return Registrations_Admin_Page |
|
| 59 | + */ |
|
| 60 | + public function __construct($routing = true) |
|
| 61 | + { |
|
| 62 | + parent::__construct($routing); |
|
| 63 | + add_action('wp_loaded', array($this, 'wp_loaded')); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + |
|
| 67 | + public function wp_loaded() |
|
| 68 | + { |
|
| 69 | + // when adding a new registration... |
|
| 70 | + if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') { |
|
| 71 | + EE_System::do_not_cache(); |
|
| 72 | + if (! isset($this->_req_data['processing_registration']) |
|
| 73 | + || absint($this->_req_data['processing_registration']) !== 1 |
|
| 74 | + ) { |
|
| 75 | + // and it's NOT the attendee information reg step |
|
| 76 | + // force cookie expiration by setting time to last week |
|
| 77 | + setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/'); |
|
| 78 | + // and update the global |
|
| 79 | + $_COOKIE['ee_registration_added'] = 0; |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + |
|
| 85 | + protected function _init_page_props() |
|
| 86 | + { |
|
| 87 | + $this->page_slug = REG_PG_SLUG; |
|
| 88 | + $this->_admin_base_url = REG_ADMIN_URL; |
|
| 89 | + $this->_admin_base_path = REG_ADMIN; |
|
| 90 | + $this->page_label = esc_html__('Registrations', 'event_espresso'); |
|
| 91 | + $this->_cpt_routes = array( |
|
| 92 | + 'add_new_attendee' => 'espresso_attendees', |
|
| 93 | + 'edit_attendee' => 'espresso_attendees', |
|
| 94 | + 'insert_attendee' => 'espresso_attendees', |
|
| 95 | + 'update_attendee' => 'espresso_attendees', |
|
| 96 | + ); |
|
| 97 | + $this->_cpt_model_names = array( |
|
| 98 | + 'add_new_attendee' => 'EEM_Attendee', |
|
| 99 | + 'edit_attendee' => 'EEM_Attendee', |
|
| 100 | + ); |
|
| 101 | + $this->_cpt_edit_routes = array( |
|
| 102 | + 'espresso_attendees' => 'edit_attendee', |
|
| 103 | + ); |
|
| 104 | + $this->_pagenow_map = array( |
|
| 105 | + 'add_new_attendee' => 'post-new.php', |
|
| 106 | + 'edit_attendee' => 'post.php', |
|
| 107 | + 'trash' => 'post.php', |
|
| 108 | + ); |
|
| 109 | + add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10); |
|
| 110 | + //add filters so that the comment urls don't take users to a confusing 404 page |
|
| 111 | + add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + |
|
| 115 | + public function clear_comment_link($link, $comment, $args) |
|
| 116 | + { |
|
| 117 | + //gotta make sure this only happens on this route |
|
| 118 | + $post_type = get_post_type($comment->comment_post_ID); |
|
| 119 | + if ($post_type === 'espresso_attendees') { |
|
| 120 | + return '#commentsdiv'; |
|
| 121 | + } |
|
| 122 | + return $link; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + protected function _ajax_hooks() |
|
| 127 | + { |
|
| 128 | + //todo: all hooks for registrations ajax goes in here |
|
| 129 | + add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status')); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + |
|
| 133 | + protected function _define_page_props() |
|
| 134 | + { |
|
| 135 | + $this->_admin_page_title = $this->page_label; |
|
| 136 | + $this->_labels = array( |
|
| 137 | + 'buttons' => array( |
|
| 138 | + 'add-registrant' => esc_html__('Add New Registration', 'event_espresso'), |
|
| 139 | + 'add-attendee' => esc_html__('Add Contact', 'event_espresso'), |
|
| 140 | + 'edit' => esc_html__('Edit Contact', 'event_espresso'), |
|
| 141 | + 'report' => esc_html__("Event Registrations CSV Report", "event_espresso"), |
|
| 142 | + 'report_all' => esc_html__('All Registrations CSV Report', 'event_espresso'), |
|
| 143 | + 'report_filtered' => esc_html__('Filtered CSV Report', 'event_espresso'), |
|
| 144 | + 'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'), |
|
| 145 | + 'contact_list_export' => esc_html__("Export Data", "event_espresso"), |
|
| 146 | + ), |
|
| 147 | + 'publishbox' => array( |
|
| 148 | + 'add_new_attendee' => esc_html__("Add Contact Record", 'event_espresso'), |
|
| 149 | + 'edit_attendee' => esc_html__("Update Contact Record", 'event_espresso'), |
|
| 150 | + ), |
|
| 151 | + 'hide_add_button_on_cpt_route' => array( |
|
| 152 | + 'edit_attendee' => true, |
|
| 153 | + ), |
|
| 154 | + ); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * grab url requests and route them |
|
| 160 | + * |
|
| 161 | + * @access private |
|
| 162 | + * @return void |
|
| 163 | + */ |
|
| 164 | + public function _set_page_routes() |
|
| 165 | + { |
|
| 166 | + $this->_get_registration_status_array(); |
|
| 167 | + $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
|
| 168 | + ? $this->_req_data['_REG_ID'] : 0; |
|
| 169 | + $reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID']) |
|
| 170 | + ? $this->_req_data['reg_status_change_form']['REG_ID'] |
|
| 171 | + : $reg_id; |
|
| 172 | + $att_id = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID']) |
|
| 173 | + ? $this->_req_data['ATT_ID'] : 0; |
|
| 174 | + $att_id = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post']) |
|
| 175 | + ? $this->_req_data['post'] |
|
| 176 | + : $att_id; |
|
| 177 | + $this->_page_routes = array( |
|
| 178 | + 'default' => array( |
|
| 179 | + 'func' => '_registrations_overview_list_table', |
|
| 180 | + 'capability' => 'ee_read_registrations', |
|
| 181 | + ), |
|
| 182 | + 'view_registration' => array( |
|
| 183 | + 'func' => '_registration_details', |
|
| 184 | + 'capability' => 'ee_read_registration', |
|
| 185 | + 'obj_id' => $reg_id, |
|
| 186 | + ), |
|
| 187 | + 'edit_registration' => array( |
|
| 188 | + 'func' => '_update_attendee_registration_form', |
|
| 189 | + 'noheader' => true, |
|
| 190 | + 'headers_sent_route' => 'view_registration', |
|
| 191 | + 'capability' => 'ee_edit_registration', |
|
| 192 | + 'obj_id' => $reg_id, |
|
| 193 | + '_REG_ID' => $reg_id, |
|
| 194 | + ), |
|
| 195 | + 'trash_registrations' => array( |
|
| 196 | + 'func' => '_trash_or_restore_registrations', |
|
| 197 | + 'args' => array('trash' => true), |
|
| 198 | + 'noheader' => true, |
|
| 199 | + 'capability' => 'ee_delete_registrations', |
|
| 200 | + ), |
|
| 201 | + 'restore_registrations' => array( |
|
| 202 | + 'func' => '_trash_or_restore_registrations', |
|
| 203 | + 'args' => array('trash' => false), |
|
| 204 | + 'noheader' => true, |
|
| 205 | + 'capability' => 'ee_delete_registrations', |
|
| 206 | + ), |
|
| 207 | + 'delete_registrations' => array( |
|
| 208 | + 'func' => '_delete_registrations', |
|
| 209 | + 'noheader' => true, |
|
| 210 | + 'capability' => 'ee_delete_registrations', |
|
| 211 | + ), |
|
| 212 | + 'new_registration' => array( |
|
| 213 | + 'func' => 'new_registration', |
|
| 214 | + 'capability' => 'ee_edit_registrations', |
|
| 215 | + ), |
|
| 216 | + 'process_reg_step' => array( |
|
| 217 | + 'func' => 'process_reg_step', |
|
| 218 | + 'noheader' => true, |
|
| 219 | + 'capability' => 'ee_edit_registrations', |
|
| 220 | + ), |
|
| 221 | + 'redirect_to_txn' => array( |
|
| 222 | + 'func' => 'redirect_to_txn', |
|
| 223 | + 'noheader' => true, |
|
| 224 | + 'capability' => 'ee_edit_registrations', |
|
| 225 | + ), |
|
| 226 | + 'change_reg_status' => array( |
|
| 227 | + 'func' => '_change_reg_status', |
|
| 228 | + 'noheader' => true, |
|
| 229 | + 'capability' => 'ee_edit_registration', |
|
| 230 | + 'obj_id' => $reg_id, |
|
| 231 | + ), |
|
| 232 | + 'approve_registration' => array( |
|
| 233 | + 'func' => 'approve_registration', |
|
| 234 | + 'noheader' => true, |
|
| 235 | + 'capability' => 'ee_edit_registration', |
|
| 236 | + 'obj_id' => $reg_id, |
|
| 237 | + ), |
|
| 238 | + 'approve_and_notify_registration' => array( |
|
| 239 | + 'func' => 'approve_registration', |
|
| 240 | + 'noheader' => true, |
|
| 241 | + 'args' => array(true), |
|
| 242 | + 'capability' => 'ee_edit_registration', |
|
| 243 | + 'obj_id' => $reg_id, |
|
| 244 | + ), |
|
| 245 | + 'approve_registrations' => array( |
|
| 246 | + 'func' => 'bulk_action_on_registrations', |
|
| 247 | + 'noheader' => true, |
|
| 248 | + 'capability' => 'ee_edit_registrations', |
|
| 249 | + 'args' => array('approve') |
|
| 250 | + ), |
|
| 251 | + 'approve_and_notify_registrations' => array( |
|
| 252 | + 'func' => 'bulk_action_on_registrations', |
|
| 253 | + 'noheader' => true, |
|
| 254 | + 'capability' => 'ee_edit_registrations', |
|
| 255 | + 'args' => array('approve', true) |
|
| 256 | + ), |
|
| 257 | + 'decline_registration' => array( |
|
| 258 | + 'func' => 'decline_registration', |
|
| 259 | + 'noheader' => true, |
|
| 260 | + 'capability' => 'ee_edit_registration', |
|
| 261 | + 'obj_id' => $reg_id, |
|
| 262 | + ), |
|
| 263 | + 'decline_and_notify_registration' => array( |
|
| 264 | + 'func' => 'decline_registration', |
|
| 265 | + 'noheader' => true, |
|
| 266 | + 'args' => array(true), |
|
| 267 | + 'capability' => 'ee_edit_registration', |
|
| 268 | + 'obj_id' => $reg_id, |
|
| 269 | + ), |
|
| 270 | + 'decline_registrations' => array( |
|
| 271 | + 'func' => 'bulk_action_on_registrations', |
|
| 272 | + 'noheader' => true, |
|
| 273 | + 'capability' => 'ee_edit_registrations', |
|
| 274 | + 'args' => array('decline') |
|
| 275 | + ), |
|
| 276 | + 'decline_and_notify_registrations' => array( |
|
| 277 | + 'func' => 'bulk_action_on_registrations', |
|
| 278 | + 'noheader' => true, |
|
| 279 | + 'capability' => 'ee_edit_registrations', |
|
| 280 | + 'args' => array('decline', true) |
|
| 281 | + ), |
|
| 282 | + 'pending_registration' => array( |
|
| 283 | + 'func' => 'pending_registration', |
|
| 284 | + 'noheader' => true, |
|
| 285 | + 'capability' => 'ee_edit_registration', |
|
| 286 | + 'obj_id' => $reg_id, |
|
| 287 | + ), |
|
| 288 | + 'pending_and_notify_registration' => array( |
|
| 289 | + 'func' => 'pending_registration', |
|
| 290 | + 'noheader' => true, |
|
| 291 | + 'args' => array(true), |
|
| 292 | + 'capability' => 'ee_edit_registration', |
|
| 293 | + 'obj_id' => $reg_id, |
|
| 294 | + ), |
|
| 295 | + 'pending_registrations' => array( |
|
| 296 | + 'func' => 'bulk_action_on_registrations', |
|
| 297 | + 'noheader' => true, |
|
| 298 | + 'capability' => 'ee_edit_registrations', |
|
| 299 | + 'args' => array('pending') |
|
| 300 | + ), |
|
| 301 | + 'pending_and_notify_registrations' => array( |
|
| 302 | + 'func' => 'bulk_action_on_registrations', |
|
| 303 | + 'noheader' => true, |
|
| 304 | + 'capability' => 'ee_edit_registrations', |
|
| 305 | + 'args' => array('pending', true) |
|
| 306 | + ), |
|
| 307 | + 'no_approve_registration' => array( |
|
| 308 | + 'func' => 'not_approve_registration', |
|
| 309 | + 'noheader' => true, |
|
| 310 | + 'capability' => 'ee_edit_registration', |
|
| 311 | + 'obj_id' => $reg_id, |
|
| 312 | + ), |
|
| 313 | + 'no_approve_and_notify_registration' => array( |
|
| 314 | + 'func' => 'not_approve_registration', |
|
| 315 | + 'noheader' => true, |
|
| 316 | + 'args' => array(true), |
|
| 317 | + 'capability' => 'ee_edit_registration', |
|
| 318 | + 'obj_id' => $reg_id, |
|
| 319 | + ), |
|
| 320 | + 'no_approve_registrations' => array( |
|
| 321 | + 'func' => 'bulk_action_on_registrations', |
|
| 322 | + 'noheader' => true, |
|
| 323 | + 'capability' => 'ee_edit_registrations', |
|
| 324 | + 'args' => array('not_approve') |
|
| 325 | + ), |
|
| 326 | + 'no_approve_and_notify_registrations' => array( |
|
| 327 | + 'func' => 'bulk_action_on_registrations', |
|
| 328 | + 'noheader' => true, |
|
| 329 | + 'capability' => 'ee_edit_registrations', |
|
| 330 | + 'args' => array('not_approve', true) |
|
| 331 | + ), |
|
| 332 | + 'cancel_registration' => array( |
|
| 333 | + 'func' => 'cancel_registration', |
|
| 334 | + 'noheader' => true, |
|
| 335 | + 'capability' => 'ee_edit_registration', |
|
| 336 | + 'obj_id' => $reg_id, |
|
| 337 | + ), |
|
| 338 | + 'cancel_and_notify_registration' => array( |
|
| 339 | + 'func' => 'cancel_registration', |
|
| 340 | + 'noheader' => true, |
|
| 341 | + 'args' => array(true), |
|
| 342 | + 'capability' => 'ee_edit_registration', |
|
| 343 | + 'obj_id' => $reg_id, |
|
| 344 | + ), |
|
| 345 | + 'cancel_registrations' => array( |
|
| 346 | + 'func' => 'bulk_action_on_registrations', |
|
| 347 | + 'noheader' => true, |
|
| 348 | + 'capability' => 'ee_edit_registrations', |
|
| 349 | + 'args' => array('cancel') |
|
| 350 | + ), |
|
| 351 | + 'cancel_and_notify_registrations' => array( |
|
| 352 | + 'func' => 'bulk_action_on_registrations', |
|
| 353 | + 'noheader' => true, |
|
| 354 | + 'capability' => 'ee_edit_registrations', |
|
| 355 | + 'args' => array('cancel', true) |
|
| 356 | + ), |
|
| 357 | + 'wait_list_registration' => array( |
|
| 358 | + 'func' => 'wait_list_registration', |
|
| 359 | + 'noheader' => true, |
|
| 360 | + 'capability' => 'ee_edit_registration', |
|
| 361 | + 'obj_id' => $reg_id, |
|
| 362 | + ), |
|
| 363 | + 'contact_list' => array( |
|
| 364 | + 'func' => '_attendee_contact_list_table', |
|
| 365 | + 'capability' => 'ee_read_contacts', |
|
| 366 | + ), |
|
| 367 | + 'add_new_attendee' => array( |
|
| 368 | + 'func' => '_create_new_cpt_item', |
|
| 369 | + 'args' => array( |
|
| 370 | + 'new_attendee' => true, |
|
| 371 | + 'capability' => 'ee_edit_contacts', |
|
| 372 | + ), |
|
| 373 | + ), |
|
| 374 | + 'edit_attendee' => array( |
|
| 375 | + 'func' => '_edit_cpt_item', |
|
| 376 | + 'capability' => 'ee_edit_contacts', |
|
| 377 | + 'obj_id' => $att_id, |
|
| 378 | + ), |
|
| 379 | + 'duplicate_attendee' => array( |
|
| 380 | + 'func' => '_duplicate_attendee', |
|
| 381 | + 'noheader' => true, |
|
| 382 | + 'capability' => 'ee_edit_contacts', |
|
| 383 | + 'obj_id' => $att_id, |
|
| 384 | + ), |
|
| 385 | + 'insert_attendee' => array( |
|
| 386 | + 'func' => '_insert_or_update_attendee', |
|
| 387 | + 'args' => array( |
|
| 388 | + 'new_attendee' => true, |
|
| 389 | + ), |
|
| 390 | + 'noheader' => true, |
|
| 391 | + 'capability' => 'ee_edit_contacts', |
|
| 392 | + ), |
|
| 393 | + 'update_attendee' => array( |
|
| 394 | + 'func' => '_insert_or_update_attendee', |
|
| 395 | + 'args' => array( |
|
| 396 | + 'new_attendee' => false, |
|
| 397 | + ), |
|
| 398 | + 'noheader' => true, |
|
| 399 | + 'capability' => 'ee_edit_contacts', |
|
| 400 | + 'obj_id' => $att_id, |
|
| 401 | + ), |
|
| 402 | + 'trash_attendees' => array( |
|
| 403 | + 'func' => '_trash_or_restore_attendees', |
|
| 404 | + 'args' => array( |
|
| 405 | + 'trash' => 'true' |
|
| 406 | + ), |
|
| 407 | + 'noheader' => true, |
|
| 408 | + 'capability' => 'ee_delete_contacts' |
|
| 409 | + ), |
|
| 410 | + 'trash_attendee' => array( |
|
| 411 | + 'func' => '_trash_or_restore_attendees', |
|
| 412 | + 'args' => array( |
|
| 413 | + 'trash' => true, |
|
| 414 | + ), |
|
| 415 | + 'noheader' => true, |
|
| 416 | + 'capability' => 'ee_delete_contacts', |
|
| 417 | + 'obj_id' => $att_id, |
|
| 418 | + ), |
|
| 419 | + 'restore_attendees' => array( |
|
| 420 | + 'func' => '_trash_or_restore_attendees', |
|
| 421 | + 'args' => array( |
|
| 422 | + 'trash' => false, |
|
| 423 | + ), |
|
| 424 | + 'noheader' => true, |
|
| 425 | + 'capability' => 'ee_delete_contacts', |
|
| 426 | + 'obj_id' => $att_id, |
|
| 427 | + ), |
|
| 428 | + 'resend_registration' => array( |
|
| 429 | + 'func' => '_resend_registration', |
|
| 430 | + 'noheader' => true, |
|
| 431 | + 'capability' => 'ee_send_message', |
|
| 432 | + ), |
|
| 433 | + 'registrations_report' => array( |
|
| 434 | + 'func' => '_registrations_report', |
|
| 435 | + 'noheader' => true, |
|
| 436 | + 'capability' => 'ee_read_registrations', |
|
| 437 | + ), |
|
| 438 | + 'contact_list_export' => array( |
|
| 439 | + 'func' => '_contact_list_export', |
|
| 440 | + 'noheader' => true, |
|
| 441 | + 'capability' => 'export', |
|
| 442 | + ), |
|
| 443 | + 'contact_list_report' => array( |
|
| 444 | + 'func' => '_contact_list_report', |
|
| 445 | + 'noheader' => true, |
|
| 446 | + 'capability' => 'ee_read_contacts', |
|
| 447 | + ), |
|
| 448 | + ); |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + |
|
| 452 | + protected function _set_page_config() |
|
| 453 | + { |
|
| 454 | + $this->_page_config = array( |
|
| 455 | + 'default' => array( |
|
| 456 | + 'nav' => array( |
|
| 457 | + 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 458 | + 'order' => 5, |
|
| 459 | + ), |
|
| 460 | + 'help_tabs' => array( |
|
| 461 | + 'registrations_overview_help_tab' => array( |
|
| 462 | + 'title' => esc_html__('Registrations Overview', 'event_espresso'), |
|
| 463 | + 'filename' => 'registrations_overview', |
|
| 464 | + ), |
|
| 465 | + 'registrations_overview_table_column_headings_help_tab' => array( |
|
| 466 | + 'title' => esc_html__('Registrations Table Column Headings', 'event_espresso'), |
|
| 467 | + 'filename' => 'registrations_overview_table_column_headings', |
|
| 468 | + ), |
|
| 469 | + 'registrations_overview_filters_help_tab' => array( |
|
| 470 | + 'title' => esc_html__('Registration Filters', 'event_espresso'), |
|
| 471 | + 'filename' => 'registrations_overview_filters', |
|
| 472 | + ), |
|
| 473 | + 'registrations_overview_views_help_tab' => array( |
|
| 474 | + 'title' => esc_html__('Registration Views', 'event_espresso'), |
|
| 475 | + 'filename' => 'registrations_overview_views', |
|
| 476 | + ), |
|
| 477 | + 'registrations_regoverview_other_help_tab' => array( |
|
| 478 | + 'title' => esc_html__('Registrations Other', 'event_espresso'), |
|
| 479 | + 'filename' => 'registrations_overview_other', |
|
| 480 | + ), |
|
| 481 | + ), |
|
| 482 | + 'help_tour' => array('Registration_Overview_Help_Tour'), |
|
| 483 | + 'qtips' => array('Registration_List_Table_Tips'), |
|
| 484 | + 'list_table' => 'EE_Registrations_List_Table', |
|
| 485 | + 'require_nonce' => false, |
|
| 486 | + ), |
|
| 487 | + 'view_registration' => array( |
|
| 488 | + 'nav' => array( |
|
| 489 | + 'label' => esc_html__('REG Details', 'event_espresso'), |
|
| 490 | + 'order' => 15, |
|
| 491 | + 'url' => isset($this->_req_data['_REG_ID']) |
|
| 492 | + ? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url) |
|
| 493 | + : $this->_admin_base_url, |
|
| 494 | + 'persistent' => false, |
|
| 495 | + ), |
|
| 496 | + 'help_tabs' => array( |
|
| 497 | + 'registrations_details_help_tab' => array( |
|
| 498 | + 'title' => esc_html__('Registration Details', 'event_espresso'), |
|
| 499 | + 'filename' => 'registrations_details', |
|
| 500 | + ), |
|
| 501 | + 'registrations_details_table_help_tab' => array( |
|
| 502 | + 'title' => esc_html__('Registration Details Table', 'event_espresso'), |
|
| 503 | + 'filename' => 'registrations_details_table', |
|
| 504 | + ), |
|
| 505 | + 'registrations_details_form_answers_help_tab' => array( |
|
| 506 | + 'title' => esc_html__('Registration Form Answers', 'event_espresso'), |
|
| 507 | + 'filename' => 'registrations_details_form_answers', |
|
| 508 | + ), |
|
| 509 | + 'registrations_details_registrant_details_help_tab' => array( |
|
| 510 | + 'title' => esc_html__('Contact Details', 'event_espresso'), |
|
| 511 | + 'filename' => 'registrations_details_registrant_details', |
|
| 512 | + ), |
|
| 513 | + ), |
|
| 514 | + 'help_tour' => array('Registration_Details_Help_Tour'), |
|
| 515 | + 'metaboxes' => array_merge( |
|
| 516 | + $this->_default_espresso_metaboxes, |
|
| 517 | + array('_registration_details_metaboxes') |
|
| 518 | + ), |
|
| 519 | + 'require_nonce' => false, |
|
| 520 | + ), |
|
| 521 | + 'new_registration' => array( |
|
| 522 | + 'nav' => array( |
|
| 523 | + 'label' => esc_html__('Add New Registration', 'event_espresso'), |
|
| 524 | + 'url' => '#', |
|
| 525 | + 'order' => 15, |
|
| 526 | + 'persistent' => false, |
|
| 527 | + ), |
|
| 528 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 529 | + 'labels' => array( |
|
| 530 | + 'publishbox' => esc_html__('Save Registration', 'event_espresso'), |
|
| 531 | + ), |
|
| 532 | + 'require_nonce' => false, |
|
| 533 | + ), |
|
| 534 | + 'add_new_attendee' => array( |
|
| 535 | + 'nav' => array( |
|
| 536 | + 'label' => esc_html__('Add Contact', 'event_espresso'), |
|
| 537 | + 'order' => 15, |
|
| 538 | + 'persistent' => false, |
|
| 539 | + ), |
|
| 540 | + 'metaboxes' => array_merge( |
|
| 541 | + $this->_default_espresso_metaboxes, |
|
| 542 | + array('_publish_post_box', 'attendee_editor_metaboxes') |
|
| 543 | + ), |
|
| 544 | + 'require_nonce' => false, |
|
| 545 | + ), |
|
| 546 | + 'edit_attendee' => array( |
|
| 547 | + 'nav' => array( |
|
| 548 | + 'label' => esc_html__('Edit Contact', 'event_espresso'), |
|
| 549 | + 'order' => 15, |
|
| 550 | + 'persistent' => false, |
|
| 551 | + 'url' => isset($this->_req_data['ATT_ID']) |
|
| 552 | + ? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url) |
|
| 553 | + : $this->_admin_base_url, |
|
| 554 | + ), |
|
| 555 | + 'metaboxes' => array('attendee_editor_metaboxes'), |
|
| 556 | + 'require_nonce' => false, |
|
| 557 | + ), |
|
| 558 | + 'contact_list' => array( |
|
| 559 | + 'nav' => array( |
|
| 560 | + 'label' => esc_html__('Contact List', 'event_espresso'), |
|
| 561 | + 'order' => 20, |
|
| 562 | + ), |
|
| 563 | + 'list_table' => 'EE_Attendee_Contact_List_Table', |
|
| 564 | + 'help_tabs' => array( |
|
| 565 | + 'registrations_contact_list_help_tab' => array( |
|
| 566 | + 'title' => esc_html__('Registrations Contact List', 'event_espresso'), |
|
| 567 | + 'filename' => 'registrations_contact_list', |
|
| 568 | + ), |
|
| 569 | + 'registrations_contact-list_table_column_headings_help_tab' => array( |
|
| 570 | + 'title' => esc_html__('Contact List Table Column Headings', 'event_espresso'), |
|
| 571 | + 'filename' => 'registrations_contact_list_table_column_headings', |
|
| 572 | + ), |
|
| 573 | + 'registrations_contact_list_views_help_tab' => array( |
|
| 574 | + 'title' => esc_html__('Contact List Views', 'event_espresso'), |
|
| 575 | + 'filename' => 'registrations_contact_list_views', |
|
| 576 | + ), |
|
| 577 | + 'registrations_contact_list_other_help_tab' => array( |
|
| 578 | + 'title' => esc_html__('Contact List Other', 'event_espresso'), |
|
| 579 | + 'filename' => 'registrations_contact_list_other', |
|
| 580 | + ), |
|
| 581 | + ), |
|
| 582 | + 'help_tour' => array('Contact_List_Help_Tour'), |
|
| 583 | + 'metaboxes' => array(), |
|
| 584 | + 'require_nonce' => false, |
|
| 585 | + ), |
|
| 586 | + //override default cpt routes |
|
| 587 | + 'create_new' => '', |
|
| 588 | + 'edit' => '', |
|
| 589 | + ); |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + |
|
| 593 | + /** |
|
| 594 | + * The below methods aren't used by this class currently |
|
| 595 | + */ |
|
| 596 | + protected function _add_screen_options() |
|
| 597 | + { |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + |
|
| 601 | + protected function _add_feature_pointers() |
|
| 602 | + { |
|
| 603 | + } |
|
| 604 | + |
|
| 605 | + |
|
| 606 | + public function admin_init() |
|
| 607 | + { |
|
| 608 | + EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__( |
|
| 609 | + 'click "Update Registration Questions" to save your changes', |
|
| 610 | + 'event_espresso' |
|
| 611 | + ); |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + |
|
| 615 | + public function admin_notices() |
|
| 616 | + { |
|
| 617 | + } |
|
| 618 | + |
|
| 619 | + |
|
| 620 | + public function admin_footer_scripts() |
|
| 621 | + { |
|
| 622 | + } |
|
| 623 | + |
|
| 624 | + |
|
| 625 | + /** |
|
| 626 | + * get list of registration statuses |
|
| 627 | + * |
|
| 628 | + * @access private |
|
| 629 | + * @return void |
|
| 630 | + */ |
|
| 631 | + private function _get_registration_status_array() |
|
| 632 | + { |
|
| 633 | + self::$_reg_status = EEM_Registration::reg_status_array(array(), true); |
|
| 634 | + } |
|
| 635 | + |
|
| 636 | + |
|
| 637 | + protected function _add_screen_options_default() |
|
| 638 | + { |
|
| 639 | + $this->_per_page_screen_option(); |
|
| 640 | + } |
|
| 641 | + |
|
| 642 | + |
|
| 643 | + protected function _add_screen_options_contact_list() |
|
| 644 | + { |
|
| 645 | + $page_title = $this->_admin_page_title; |
|
| 646 | + $this->_admin_page_title = esc_html__("Contacts", 'event_espresso'); |
|
| 647 | + $this->_per_page_screen_option(); |
|
| 648 | + $this->_admin_page_title = $page_title; |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + |
|
| 652 | + public function load_scripts_styles() |
|
| 653 | + { |
|
| 654 | + //style |
|
| 655 | + wp_register_style( |
|
| 656 | + 'espresso_reg', |
|
| 657 | + REG_ASSETS_URL . 'espresso_registrations_admin.css', |
|
| 658 | + array('ee-admin-css'), |
|
| 659 | + EVENT_ESPRESSO_VERSION |
|
| 660 | + ); |
|
| 661 | + wp_enqueue_style('espresso_reg'); |
|
| 662 | + //script |
|
| 663 | + wp_register_script( |
|
| 664 | + 'espresso_reg', |
|
| 665 | + REG_ASSETS_URL . 'espresso_registrations_admin.js', |
|
| 666 | + array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'), |
|
| 667 | + EVENT_ESPRESSO_VERSION, |
|
| 668 | + true |
|
| 669 | + ); |
|
| 670 | + wp_enqueue_script('espresso_reg'); |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + |
|
| 674 | + public function load_scripts_styles_edit_attendee() |
|
| 675 | + { |
|
| 676 | + //stuff to only show up on our attendee edit details page. |
|
| 677 | + $attendee_details_translations = array( |
|
| 678 | + 'att_publish_text' => sprintf( |
|
| 679 | + esc_html__('Created on: <b>%1$s</b>', 'event_espresso'), |
|
| 680 | + $this->_cpt_model_obj->get_datetime('ATT_created') |
|
| 681 | + ), |
|
| 682 | + ); |
|
| 683 | + wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations); |
|
| 684 | + wp_enqueue_script('jquery-validate'); |
|
| 685 | + } |
|
| 686 | + |
|
| 687 | + |
|
| 688 | + public function load_scripts_styles_view_registration() |
|
| 689 | + { |
|
| 690 | + //styles |
|
| 691 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 692 | + //scripts |
|
| 693 | + $this->_get_reg_custom_questions_form($this->_registration->ID()); |
|
| 694 | + $this->_reg_custom_questions_form->wp_enqueue_scripts(true); |
|
| 695 | + } |
|
| 696 | + |
|
| 697 | + |
|
| 698 | + public function load_scripts_styles_contact_list() |
|
| 699 | + { |
|
| 700 | + wp_deregister_style('espresso_reg'); |
|
| 701 | + wp_register_style( |
|
| 702 | + 'espresso_att', |
|
| 703 | + REG_ASSETS_URL . 'espresso_attendees_admin.css', |
|
| 704 | + array('ee-admin-css'), |
|
| 705 | + EVENT_ESPRESSO_VERSION |
|
| 706 | + ); |
|
| 707 | + wp_enqueue_style('espresso_att'); |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + |
|
| 711 | + public function load_scripts_styles_new_registration() |
|
| 712 | + { |
|
| 713 | + wp_register_script( |
|
| 714 | + 'ee-spco-for-admin', |
|
| 715 | + REG_ASSETS_URL . 'spco_for_admin.js', |
|
| 716 | + array('underscore', 'jquery'), |
|
| 717 | + EVENT_ESPRESSO_VERSION, |
|
| 718 | + true |
|
| 719 | + ); |
|
| 720 | + wp_enqueue_script('ee-spco-for-admin'); |
|
| 721 | + add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
| 722 | + EE_Form_Section_Proper::wp_enqueue_scripts(); |
|
| 723 | + EED_Ticket_Selector::load_tckt_slctr_assets(); |
|
| 724 | + EE_Datepicker_Input::enqueue_styles_and_scripts(); |
|
| 725 | + } |
|
| 726 | + |
|
| 727 | + |
|
| 728 | + public function AHEE__EE_Admin_Page__route_admin_request_resend_registration() |
|
| 729 | + { |
|
| 730 | + add_filter('FHEE_load_EE_messages', '__return_true'); |
|
| 731 | + } |
|
| 732 | + |
|
| 733 | + |
|
| 734 | + public function AHEE__EE_Admin_Page__route_admin_request_approve_registration() |
|
| 735 | + { |
|
| 736 | + add_filter('FHEE_load_EE_messages', '__return_true'); |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + |
|
| 740 | + protected function _set_list_table_views_default() |
|
| 741 | + { |
|
| 742 | + //for notification related bulk actions we need to make sure only active messengers have an option. |
|
| 743 | + EED_Messages::set_autoloaders(); |
|
| 744 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 745 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 746 | + $active_mts = $message_resource_manager->list_of_active_message_types(); |
|
| 747 | + //key= bulk_action_slug, value= message type. |
|
| 748 | + $match_array = array( |
|
| 749 | + 'approve_registrations' => 'registration', |
|
| 750 | + 'decline_registrations' => 'declined_registration', |
|
| 751 | + 'pending_registrations' => 'pending_approval', |
|
| 752 | + 'no_approve_registrations' => 'not_approved_registration', |
|
| 753 | + 'cancel_registrations' => 'cancelled_registration', |
|
| 754 | + ); |
|
| 755 | + $can_send = EE_Registry::instance()->CAP->current_user_can( |
|
| 756 | + 'ee_send_message', |
|
| 757 | + 'batch_send_messages' |
|
| 758 | + ); |
|
| 759 | + /** setup reg status bulk actions **/ |
|
| 760 | + $def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso'); |
|
| 761 | + if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) { |
|
| 762 | + $def_reg_status_actions['approve_and_notify_registrations'] = esc_html__( |
|
| 763 | + 'Approve and Notify Registrations', |
|
| 764 | + 'event_espresso' |
|
| 765 | + ); |
|
| 766 | + } |
|
| 767 | + $def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso'); |
|
| 768 | + if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) { |
|
| 769 | + $def_reg_status_actions['decline_and_notify_registrations'] = esc_html__( |
|
| 770 | + 'Decline and Notify Registrations', |
|
| 771 | + 'event_espresso' |
|
| 772 | + ); |
|
| 773 | + } |
|
| 774 | + $def_reg_status_actions['pending_registrations'] = esc_html__( |
|
| 775 | + 'Set Registrations to Pending Payment', |
|
| 776 | + 'event_espresso' |
|
| 777 | + ); |
|
| 778 | + if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) { |
|
| 779 | + $def_reg_status_actions['pending_and_notify_registrations'] = esc_html__( |
|
| 780 | + 'Set Registrations to Pending Payment and Notify', |
|
| 781 | + 'event_espresso' |
|
| 782 | + ); |
|
| 783 | + } |
|
| 784 | + $def_reg_status_actions['no_approve_registrations'] = esc_html__( |
|
| 785 | + 'Set Registrations to Not Approved', |
|
| 786 | + 'event_espresso' |
|
| 787 | + ); |
|
| 788 | + if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) { |
|
| 789 | + $def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__( |
|
| 790 | + 'Set Registrations to Not Approved and Notify', |
|
| 791 | + 'event_espresso' |
|
| 792 | + ); |
|
| 793 | + } |
|
| 794 | + $def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso'); |
|
| 795 | + if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) { |
|
| 796 | + $def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__( |
|
| 797 | + 'Cancel Registrations and Notify', |
|
| 798 | + 'event_espresso' |
|
| 799 | + ); |
|
| 800 | + } |
|
| 801 | + $def_reg_status_actions = apply_filters( |
|
| 802 | + 'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array', |
|
| 803 | + $def_reg_status_actions, |
|
| 804 | + $active_mts |
|
| 805 | + ); |
|
| 806 | + |
|
| 807 | + $this->_views = array( |
|
| 808 | + 'all' => array( |
|
| 809 | + 'slug' => 'all', |
|
| 810 | + 'label' => esc_html__('View All Registrations', 'event_espresso'), |
|
| 811 | + 'count' => 0, |
|
| 812 | + 'bulk_action' => array_merge($def_reg_status_actions, array( |
|
| 813 | + 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
| 814 | + )), |
|
| 815 | + ), |
|
| 816 | + 'month' => array( |
|
| 817 | + 'slug' => 'month', |
|
| 818 | + 'label' => esc_html__('This Month', 'event_espresso'), |
|
| 819 | + 'count' => 0, |
|
| 820 | + 'bulk_action' => array_merge($def_reg_status_actions, array( |
|
| 821 | + 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
| 822 | + )), |
|
| 823 | + ), |
|
| 824 | + 'today' => array( |
|
| 825 | + 'slug' => 'today', |
|
| 826 | + 'label' => sprintf( |
|
| 827 | + esc_html__('Today - %s', 'event_espresso'), |
|
| 828 | + date('M d, Y', current_time('timestamp')) |
|
| 829 | + ), |
|
| 830 | + 'count' => 0, |
|
| 831 | + 'bulk_action' => array_merge($def_reg_status_actions, array( |
|
| 832 | + 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
| 833 | + )), |
|
| 834 | + ), |
|
| 835 | + ); |
|
| 836 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 837 | + 'ee_delete_registrations', |
|
| 838 | + 'espresso_registrations_delete_registration' |
|
| 839 | + )) { |
|
| 840 | + $this->_views['incomplete'] = array( |
|
| 841 | + 'slug' => 'incomplete', |
|
| 842 | + 'label' => esc_html__('Incomplete', 'event_espresso'), |
|
| 843 | + 'count' => 0, |
|
| 844 | + 'bulk_action' => array( |
|
| 845 | + 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
| 846 | + ), |
|
| 847 | + ); |
|
| 848 | + $this->_views['trash'] = array( |
|
| 849 | + 'slug' => 'trash', |
|
| 850 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 851 | + 'count' => 0, |
|
| 852 | + 'bulk_action' => array( |
|
| 853 | + 'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'), |
|
| 854 | + 'delete_registrations' => esc_html__('Delete Registrations Permanently', 'event_espresso'), |
|
| 855 | + ), |
|
| 856 | + ); |
|
| 857 | + } |
|
| 858 | + } |
|
| 859 | + |
|
| 860 | + |
|
| 861 | + protected function _set_list_table_views_contact_list() |
|
| 862 | + { |
|
| 863 | + $this->_views = array( |
|
| 864 | + 'in_use' => array( |
|
| 865 | + 'slug' => 'in_use', |
|
| 866 | + 'label' => esc_html__('In Use', 'event_espresso'), |
|
| 867 | + 'count' => 0, |
|
| 868 | + 'bulk_action' => array( |
|
| 869 | + 'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 870 | + ), |
|
| 871 | + ), |
|
| 872 | + ); |
|
| 873 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts', |
|
| 874 | + 'espresso_registrations_trash_attendees') |
|
| 875 | + ) { |
|
| 876 | + $this->_views['trash'] = array( |
|
| 877 | + 'slug' => 'trash', |
|
| 878 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 879 | + 'count' => 0, |
|
| 880 | + 'bulk_action' => array( |
|
| 881 | + 'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'), |
|
| 882 | + ), |
|
| 883 | + ); |
|
| 884 | + } |
|
| 885 | + } |
|
| 886 | + |
|
| 887 | + |
|
| 888 | + protected function _registration_legend_items() |
|
| 889 | + { |
|
| 890 | + $fc_items = array( |
|
| 891 | + 'star-icon' => array( |
|
| 892 | + 'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8', |
|
| 893 | + 'desc' => esc_html__('This is the Primary Registrant', 'event_espresso'), |
|
| 894 | + ), |
|
| 895 | + 'view_details' => array( |
|
| 896 | + 'class' => 'dashicons dashicons-clipboard', |
|
| 897 | + 'desc' => esc_html__('View Registration Details', 'event_espresso'), |
|
| 898 | + ), |
|
| 899 | + 'edit_attendee' => array( |
|
| 900 | + 'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16', |
|
| 901 | + 'desc' => esc_html__('Edit Contact Details', 'event_espresso'), |
|
| 902 | + ), |
|
| 903 | + 'view_transaction' => array( |
|
| 904 | + 'class' => 'dashicons dashicons-cart', |
|
| 905 | + 'desc' => esc_html__('View Transaction Details', 'event_espresso'), |
|
| 906 | + ), |
|
| 907 | + 'view_invoice' => array( |
|
| 908 | + 'class' => 'dashicons dashicons-media-spreadsheet', |
|
| 909 | + 'desc' => esc_html__('View Transaction Invoice', 'event_espresso'), |
|
| 910 | + ), |
|
| 911 | + ); |
|
| 912 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 913 | + 'ee_send_message', |
|
| 914 | + 'espresso_registrations_resend_registration' |
|
| 915 | + )) { |
|
| 916 | + $fc_items['resend_registration'] = array( |
|
| 917 | + 'class' => 'dashicons dashicons-email-alt', |
|
| 918 | + 'desc' => esc_html__('Resend Registration Details', 'event_espresso'), |
|
| 919 | + ); |
|
| 920 | + } else { |
|
| 921 | + $fc_items['blank'] = array('class' => 'blank', 'desc' => ''); |
|
| 922 | + } |
|
| 923 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 924 | + 'ee_read_global_messages', |
|
| 925 | + 'view_filtered_messages' |
|
| 926 | + )) { |
|
| 927 | + $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 928 | + if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) { |
|
| 929 | + $fc_items['view_related_messages'] = array( |
|
| 930 | + 'class' => $related_for_icon['css_class'], |
|
| 931 | + 'desc' => $related_for_icon['label'], |
|
| 932 | + ); |
|
| 933 | + } |
|
| 934 | + } |
|
| 935 | + $sc_items = array( |
|
| 936 | + 'approved_status' => array( |
|
| 937 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
| 938 | + 'desc' => EEH_Template::pretty_status( |
|
| 939 | + EEM_Registration::status_id_approved, |
|
| 940 | + false, |
|
| 941 | + 'sentence' |
|
| 942 | + ), |
|
| 943 | + ), |
|
| 944 | + 'pending_status' => array( |
|
| 945 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
| 946 | + 'desc' => EEH_Template::pretty_status( |
|
| 947 | + EEM_Registration::status_id_pending_payment, |
|
| 948 | + false, |
|
| 949 | + 'sentence' |
|
| 950 | + ), |
|
| 951 | + ), |
|
| 952 | + 'wait_list' => array( |
|
| 953 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
| 954 | + 'desc' => EEH_Template::pretty_status( |
|
| 955 | + EEM_Registration::status_id_wait_list, |
|
| 956 | + false, |
|
| 957 | + 'sentence' |
|
| 958 | + ), |
|
| 959 | + ), |
|
| 960 | + 'incomplete_status' => array( |
|
| 961 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete, |
|
| 962 | + 'desc' => EEH_Template::pretty_status( |
|
| 963 | + EEM_Registration::status_id_incomplete, |
|
| 964 | + false, |
|
| 965 | + 'sentence' |
|
| 966 | + ), |
|
| 967 | + ), |
|
| 968 | + 'not_approved' => array( |
|
| 969 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
| 970 | + 'desc' => EEH_Template::pretty_status( |
|
| 971 | + EEM_Registration::status_id_not_approved, |
|
| 972 | + false, |
|
| 973 | + 'sentence' |
|
| 974 | + ), |
|
| 975 | + ), |
|
| 976 | + 'declined_status' => array( |
|
| 977 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
| 978 | + 'desc' => EEH_Template::pretty_status( |
|
| 979 | + EEM_Registration::status_id_declined, |
|
| 980 | + false, |
|
| 981 | + 'sentence' |
|
| 982 | + ), |
|
| 983 | + ), |
|
| 984 | + 'cancelled_status' => array( |
|
| 985 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
| 986 | + 'desc' => EEH_Template::pretty_status( |
|
| 987 | + EEM_Registration::status_id_cancelled, |
|
| 988 | + false, |
|
| 989 | + 'sentence' |
|
| 990 | + ), |
|
| 991 | + ), |
|
| 992 | + ); |
|
| 993 | + return array_merge($fc_items, $sc_items); |
|
| 994 | + } |
|
| 995 | + |
|
| 996 | + |
|
| 997 | + |
|
| 998 | + /*************************************** REGISTRATION OVERVIEW **************************************/ |
|
| 999 | + /** |
|
| 1000 | + * @throws \EE_Error |
|
| 1001 | + */ |
|
| 1002 | + protected function _registrations_overview_list_table() |
|
| 1003 | + { |
|
| 1004 | + $this->_template_args['admin_page_header'] = ''; |
|
| 1005 | + $EVT_ID = ! empty($this->_req_data['event_id']) |
|
| 1006 | + ? absint($this->_req_data['event_id']) |
|
| 1007 | + : 0; |
|
| 1008 | + if ($EVT_ID) { |
|
| 1009 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 1010 | + 'ee_edit_registrations', |
|
| 1011 | + 'espresso_registrations_new_registration', |
|
| 1012 | + $EVT_ID |
|
| 1013 | + )) { |
|
| 1014 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 1015 | + 'new_registration', |
|
| 1016 | + 'add-registrant', |
|
| 1017 | + array('event_id' => $EVT_ID), |
|
| 1018 | + 'add-new-h2' |
|
| 1019 | + ); |
|
| 1020 | + } |
|
| 1021 | + $event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 1022 | + if ($event instanceof EE_Event) { |
|
| 1023 | + $this->_template_args['admin_page_header'] = sprintf( |
|
| 1024 | + esc_html__( |
|
| 1025 | + '%s Viewing registrations for the event: %s%s', |
|
| 1026 | + 'event_espresso' |
|
| 1027 | + ), |
|
| 1028 | + '<h3 style="line-height:1.5em;">', |
|
| 1029 | + '<br /><a href="' |
|
| 1030 | + . EE_Admin_Page::add_query_args_and_nonce( |
|
| 1031 | + array( |
|
| 1032 | + 'action' => 'edit', |
|
| 1033 | + 'post' => $event->ID(), |
|
| 1034 | + ), |
|
| 1035 | + EVENTS_ADMIN_URL |
|
| 1036 | + ) |
|
| 1037 | + . '"> ' |
|
| 1038 | + . $event->get('EVT_name') |
|
| 1039 | + . ' </a> ', |
|
| 1040 | + '</h3>' |
|
| 1041 | + ); |
|
| 1042 | + } |
|
| 1043 | + $DTT_ID = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0; |
|
| 1044 | + $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID); |
|
| 1045 | + if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') { |
|
| 1046 | + $this->_template_args['admin_page_header'] = substr( |
|
| 1047 | + $this->_template_args['admin_page_header'], |
|
| 1048 | + 0, |
|
| 1049 | + -5 |
|
| 1050 | + ); |
|
| 1051 | + $this->_template_args['admin_page_header'] .= ' <span class="drk-grey-text">'; |
|
| 1052 | + $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>'; |
|
| 1053 | + $this->_template_args['admin_page_header'] .= $datetime->name(); |
|
| 1054 | + $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )'; |
|
| 1055 | + $this->_template_args['admin_page_header'] .= '</span></h3>'; |
|
| 1056 | + } |
|
| 1057 | + } |
|
| 1058 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items()); |
|
| 1059 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1060 | + } |
|
| 1061 | + |
|
| 1062 | + |
|
| 1063 | + /** |
|
| 1064 | + * This sets the _registration property for the registration details screen |
|
| 1065 | + * |
|
| 1066 | + * @access private |
|
| 1067 | + * @return bool |
|
| 1068 | + */ |
|
| 1069 | + private function _set_registration_object() |
|
| 1070 | + { |
|
| 1071 | + //get out if we've already set the object |
|
| 1072 | + if (is_object($this->_registration)) { |
|
| 1073 | + return true; |
|
| 1074 | + } |
|
| 1075 | + $REG = EEM_Registration::instance(); |
|
| 1076 | + $REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false; |
|
| 1077 | + if ($this->_registration = $REG->get_one_by_ID($REG_ID)) { |
|
| 1078 | + return true; |
|
| 1079 | + } else { |
|
| 1080 | + $error_msg = sprintf( |
|
| 1081 | + esc_html__( |
|
| 1082 | + 'An error occurred and the details for Registration ID #%s could not be retrieved.', |
|
| 1083 | + 'event_espresso' |
|
| 1084 | + ), |
|
| 1085 | + $REG_ID |
|
| 1086 | + ); |
|
| 1087 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1088 | + $this->_registration = null; |
|
| 1089 | + return false; |
|
| 1090 | + } |
|
| 1091 | + } |
|
| 1092 | + |
|
| 1093 | + |
|
| 1094 | + /** |
|
| 1095 | + * Used to retrieve registrations for the list table. |
|
| 1096 | + * |
|
| 1097 | + * @param int $per_page |
|
| 1098 | + * @param bool $count |
|
| 1099 | + * @param bool $this_month |
|
| 1100 | + * @param bool $today |
|
| 1101 | + * @return EE_Registration[]|int |
|
| 1102 | + * @throws EE_Error |
|
| 1103 | + */ |
|
| 1104 | + public function get_registrations( |
|
| 1105 | + $per_page = 10, |
|
| 1106 | + $count = false, |
|
| 1107 | + $this_month = false, |
|
| 1108 | + $today = false |
|
| 1109 | + ) { |
|
| 1110 | + if ($this_month) { |
|
| 1111 | + $this->_req_data['status'] = 'month'; |
|
| 1112 | + } |
|
| 1113 | + if ($today) { |
|
| 1114 | + $this->_req_data['status'] = 'today'; |
|
| 1115 | + } |
|
| 1116 | + $query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count); |
|
| 1117 | + /** |
|
| 1118 | + * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected |
|
| 1119 | + * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093 |
|
| 1120 | + * @see EEM_Base::get_all() |
|
| 1121 | + */ |
|
| 1122 | + $query_params['group_by'] = ''; |
|
| 1123 | + |
|
| 1124 | + return $count |
|
| 1125 | + ? EEM_Registration::instance()->count($query_params) |
|
| 1126 | + /** @type EE_Registration[] */ |
|
| 1127 | + : EEM_Registration::instance()->get_all($query_params); |
|
| 1128 | + } |
|
| 1129 | + |
|
| 1130 | + |
|
| 1131 | + |
|
| 1132 | + /** |
|
| 1133 | + * Retrieves the query parameters to be used by the Registration model for getting registrations. |
|
| 1134 | + * Note: this listens to values on the request for some of the query parameters. |
|
| 1135 | + * |
|
| 1136 | + * @param array $request |
|
| 1137 | + * @param int $per_page |
|
| 1138 | + * @param bool $count |
|
| 1139 | + * @return array |
|
| 1140 | + */ |
|
| 1141 | + protected function _get_registration_query_parameters( |
|
| 1142 | + $request = array(), |
|
| 1143 | + $per_page = 10, |
|
| 1144 | + $count = false |
|
| 1145 | + ) { |
|
| 1146 | + |
|
| 1147 | + $query_params = array( |
|
| 1148 | + 0 => $this->_get_where_conditions_for_registrations_query( |
|
| 1149 | + $request |
|
| 1150 | + ), |
|
| 1151 | + 'caps' => EEM_Registration::caps_read_admin, |
|
| 1152 | + 'default_where_conditions' => 'this_model_only', |
|
| 1153 | + ); |
|
| 1154 | + if (! $count) { |
|
| 1155 | + $query_params = array_merge( |
|
| 1156 | + $query_params, |
|
| 1157 | + $this->_get_orderby_for_registrations_query(), |
|
| 1158 | + $this->_get_limit($per_page) |
|
| 1159 | + ); |
|
| 1160 | + } |
|
| 1161 | + |
|
| 1162 | + return $query_params; |
|
| 1163 | + } |
|
| 1164 | + |
|
| 1165 | + |
|
| 1166 | + /** |
|
| 1167 | + * This will add EVT_ID to the provided $where array for EE model query parameters. |
|
| 1168 | + * |
|
| 1169 | + * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1170 | + * @return array |
|
| 1171 | + */ |
|
| 1172 | + protected function _add_event_id_to_where_conditions(array $request) |
|
| 1173 | + { |
|
| 1174 | + $where = array(); |
|
| 1175 | + if (! empty($request['event_id'])) { |
|
| 1176 | + $where['EVT_ID'] = absint($request['event_id']); |
|
| 1177 | + } |
|
| 1178 | + return $where; |
|
| 1179 | + } |
|
| 1180 | + |
|
| 1181 | + |
|
| 1182 | + /** |
|
| 1183 | + * Adds category ID if it exists in the request to the where conditions for the registrations query. |
|
| 1184 | + * |
|
| 1185 | + * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1186 | + * @return array |
|
| 1187 | + */ |
|
| 1188 | + protected function _add_category_id_to_where_conditions(array $request) |
|
| 1189 | + { |
|
| 1190 | + $where = array(); |
|
| 1191 | + if (! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) { |
|
| 1192 | + $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']); |
|
| 1193 | + } |
|
| 1194 | + return $where; |
|
| 1195 | + } |
|
| 1196 | + |
|
| 1197 | + |
|
| 1198 | + /** |
|
| 1199 | + * Adds the datetime ID if it exists in the request to the where conditions for the registrations query. |
|
| 1200 | + * |
|
| 1201 | + * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1202 | + * @return array |
|
| 1203 | + */ |
|
| 1204 | + protected function _add_datetime_id_to_where_conditions(array $request) |
|
| 1205 | + { |
|
| 1206 | + $where = array(); |
|
| 1207 | + if (! empty($request['datetime_id'])) { |
|
| 1208 | + $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']); |
|
| 1209 | + } |
|
| 1210 | + if (! empty($request['DTT_ID'])) { |
|
| 1211 | + $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']); |
|
| 1212 | + } |
|
| 1213 | + return $where; |
|
| 1214 | + } |
|
| 1215 | + |
|
| 1216 | + |
|
| 1217 | + /** |
|
| 1218 | + * Adds the correct registration status to the where conditions for the registrations query. |
|
| 1219 | + * |
|
| 1220 | + * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1221 | + * @return array |
|
| 1222 | + */ |
|
| 1223 | + protected function _add_registration_status_to_where_conditions(array $request) |
|
| 1224 | + { |
|
| 1225 | + $where = array(); |
|
| 1226 | + $view = EEH_Array::is_set($request, 'status', ''); |
|
| 1227 | + $registration_status = ! empty($request['_reg_status']) |
|
| 1228 | + ? sanitize_text_field($request['_reg_status']) |
|
| 1229 | + : ''; |
|
| 1230 | + |
|
| 1231 | + /* |
|
| 1232 | 1232 | * If filtering by registration status, then we show registrations matching that status. |
| 1233 | 1233 | * If not filtering by specified status, then we show all registrations excluding incomplete registrations |
| 1234 | 1234 | * UNLESS viewing trashed registrations. |
| 1235 | 1235 | */ |
| 1236 | - if (! empty($registration_status)) { |
|
| 1237 | - $where['STS_ID'] = $registration_status; |
|
| 1238 | - } else { |
|
| 1239 | - //make sure we exclude incomplete registrations, but only if not trashed. |
|
| 1240 | - if ($view === 'trash') { |
|
| 1241 | - $where['REG_deleted'] = true; |
|
| 1242 | - } elseif ($view === 'incomplete') { |
|
| 1243 | - $where['STS_ID'] = EEM_Registration::status_id_incomplete; |
|
| 1244 | - } else { |
|
| 1245 | - $where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
| 1246 | - } |
|
| 1247 | - } |
|
| 1248 | - return $where; |
|
| 1249 | - } |
|
| 1250 | - |
|
| 1251 | - |
|
| 1252 | - /** |
|
| 1253 | - * Adds any provided date restraints to the where conditions for the registrations query. |
|
| 1254 | - * |
|
| 1255 | - * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1256 | - * @return array |
|
| 1257 | - * @throws EE_Error |
|
| 1258 | - */ |
|
| 1259 | - protected function _add_date_to_where_conditions(array $request) |
|
| 1260 | - { |
|
| 1261 | - $where = array(); |
|
| 1262 | - $view = EEH_Array::is_set($request, 'status', ''); |
|
| 1263 | - $month_range = ! empty($request['month_range']) |
|
| 1264 | - ? sanitize_text_field($request['month_range']) |
|
| 1265 | - : ''; |
|
| 1266 | - $retrieve_for_today = $view === 'today'; |
|
| 1267 | - $retrieve_for_this_month = $view === 'month'; |
|
| 1268 | - |
|
| 1269 | - if ($retrieve_for_today) { |
|
| 1270 | - $now = date('Y-m-d', current_time('timestamp')); |
|
| 1271 | - $where['REG_date'] = array( |
|
| 1272 | - 'BETWEEN', |
|
| 1273 | - array( |
|
| 1274 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1275 | - 'REG_date', |
|
| 1276 | - $now . ' 00:00:00', |
|
| 1277 | - 'Y-m-d H:i:s' |
|
| 1278 | - ), |
|
| 1279 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1280 | - 'REG_date', |
|
| 1281 | - $now . ' 23:59:59', |
|
| 1282 | - 'Y-m-d H:i:s' |
|
| 1283 | - ), |
|
| 1284 | - ), |
|
| 1285 | - ); |
|
| 1286 | - } elseif ($retrieve_for_this_month) { |
|
| 1287 | - $current_year_and_month = date('Y-m', current_time('timestamp')); |
|
| 1288 | - $days_this_month = date('t', current_time('timestamp')); |
|
| 1289 | - $where['REG_date'] = array( |
|
| 1290 | - 'BETWEEN', |
|
| 1291 | - array( |
|
| 1292 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1293 | - 'REG_date', |
|
| 1294 | - $current_year_and_month . '-01 00:00:00', |
|
| 1295 | - 'Y-m-d H:i:s' |
|
| 1296 | - ), |
|
| 1297 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1298 | - 'REG_date', |
|
| 1299 | - $current_year_and_month . '-' . $days_this_month . ' 23:59:59', |
|
| 1300 | - 'Y-m-d H:i:s' |
|
| 1301 | - ), |
|
| 1302 | - ), |
|
| 1303 | - ); |
|
| 1304 | - } elseif ($month_range) { |
|
| 1305 | - $pieces = explode(' ', $month_range, 3); |
|
| 1306 | - $month_requested = ! empty($pieces[0]) |
|
| 1307 | - ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) |
|
| 1308 | - : ''; |
|
| 1309 | - $year_requested = ! empty($pieces[1]) |
|
| 1310 | - ? $pieces[1] |
|
| 1311 | - : ''; |
|
| 1312 | - //if there is not a month or year then we can't go further |
|
| 1313 | - if ($month_requested && $year_requested) { |
|
| 1314 | - $days_in_month = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01')); |
|
| 1315 | - $where['REG_date'] = array( |
|
| 1316 | - 'BETWEEN', |
|
| 1317 | - array( |
|
| 1318 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1319 | - 'REG_date', |
|
| 1320 | - $year_requested . '-' . $month_requested . '-01 00:00:00', |
|
| 1321 | - 'Y-m-d H:i:s' |
|
| 1322 | - ), |
|
| 1323 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1324 | - 'REG_date', |
|
| 1325 | - $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59', |
|
| 1326 | - 'Y-m-d H:i:s' |
|
| 1327 | - ), |
|
| 1328 | - ), |
|
| 1329 | - ); |
|
| 1330 | - } |
|
| 1331 | - } |
|
| 1332 | - return $where; |
|
| 1333 | - } |
|
| 1334 | - |
|
| 1335 | - |
|
| 1336 | - /** |
|
| 1337 | - * Adds any provided search restraints to the where conditions for the registrations query |
|
| 1338 | - * |
|
| 1339 | - * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1340 | - * @return array |
|
| 1341 | - */ |
|
| 1342 | - protected function _add_search_to_where_conditions(array $request) |
|
| 1343 | - { |
|
| 1344 | - $where = array(); |
|
| 1345 | - if (! empty($request['s'])) { |
|
| 1346 | - $search_string = '%' . sanitize_text_field($request['s']) . '%'; |
|
| 1347 | - $where['OR*search_conditions'] = array( |
|
| 1348 | - 'Event.EVT_name' => array('LIKE', $search_string), |
|
| 1349 | - 'Event.EVT_desc' => array('LIKE', $search_string), |
|
| 1350 | - 'Event.EVT_short_desc' => array('LIKE', $search_string), |
|
| 1351 | - 'Attendee.ATT_full_name' => array('LIKE', $search_string), |
|
| 1352 | - 'Attendee.ATT_fname' => array('LIKE', $search_string), |
|
| 1353 | - 'Attendee.ATT_lname' => array('LIKE', $search_string), |
|
| 1354 | - 'Attendee.ATT_short_bio' => array('LIKE', $search_string), |
|
| 1355 | - 'Attendee.ATT_email' => array('LIKE', $search_string), |
|
| 1356 | - 'Attendee.ATT_address' => array('LIKE', $search_string), |
|
| 1357 | - 'Attendee.ATT_address2' => array('LIKE', $search_string), |
|
| 1358 | - 'Attendee.ATT_city' => array('LIKE', $search_string), |
|
| 1359 | - 'REG_final_price' => array('LIKE', $search_string), |
|
| 1360 | - 'REG_code' => array('LIKE', $search_string), |
|
| 1361 | - 'REG_count' => array('LIKE', $search_string), |
|
| 1362 | - 'REG_group_size' => array('LIKE', $search_string), |
|
| 1363 | - 'Ticket.TKT_name' => array('LIKE', $search_string), |
|
| 1364 | - 'Ticket.TKT_description' => array('LIKE', $search_string), |
|
| 1365 | - 'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string), |
|
| 1366 | - ); |
|
| 1367 | - } |
|
| 1368 | - return $where; |
|
| 1369 | - } |
|
| 1370 | - |
|
| 1371 | - |
|
| 1372 | - /** |
|
| 1373 | - * Sets up the where conditions for the registrations query. |
|
| 1374 | - * |
|
| 1375 | - * @param array $request |
|
| 1376 | - * @return array |
|
| 1377 | - * @throws EE_Error |
|
| 1378 | - */ |
|
| 1379 | - protected function _get_where_conditions_for_registrations_query($request) |
|
| 1380 | - { |
|
| 1381 | - return apply_filters( |
|
| 1382 | - 'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query', |
|
| 1383 | - array_merge( |
|
| 1384 | - $this->_add_event_id_to_where_conditions($request), |
|
| 1385 | - $this->_add_category_id_to_where_conditions($request), |
|
| 1386 | - $this->_add_datetime_id_to_where_conditions($request), |
|
| 1387 | - $this->_add_registration_status_to_where_conditions($request), |
|
| 1388 | - $this->_add_date_to_where_conditions($request), |
|
| 1389 | - $this->_add_search_to_where_conditions($request) |
|
| 1390 | - ), |
|
| 1391 | - $request |
|
| 1392 | - ); |
|
| 1393 | - } |
|
| 1394 | - |
|
| 1395 | - |
|
| 1396 | - /** |
|
| 1397 | - * Sets up the orderby for the registrations query. |
|
| 1398 | - * |
|
| 1399 | - * @return array |
|
| 1400 | - */ |
|
| 1401 | - protected function _get_orderby_for_registrations_query() |
|
| 1402 | - { |
|
| 1403 | - $orderby_field = ! empty($this->_req_data['orderby']) |
|
| 1404 | - ? sanitize_text_field($this->_req_data['orderby']) |
|
| 1405 | - : ''; |
|
| 1406 | - switch ($orderby_field) { |
|
| 1407 | - case '_REG_ID': |
|
| 1408 | - $orderby_field = 'REG_ID'; |
|
| 1409 | - break; |
|
| 1410 | - case '_Reg_status': |
|
| 1411 | - $orderby_field = 'STS_ID'; |
|
| 1412 | - break; |
|
| 1413 | - case 'ATT_fname': |
|
| 1414 | - $orderby_field = array('Attendee.ATT_fname', 'Attendee.ATT_lname'); |
|
| 1415 | - break; |
|
| 1416 | - case 'ATT_lname': |
|
| 1417 | - $orderby_field = array('Attendee.ATT_lname', 'Attendee.ATT_fname'); |
|
| 1418 | - break; |
|
| 1419 | - case 'event_name': |
|
| 1420 | - $orderby_field = 'Event.EVT_name'; |
|
| 1421 | - break; |
|
| 1422 | - case 'DTT_EVT_start': |
|
| 1423 | - $orderby_field = 'Event.Datetime.DTT_EVT_start'; |
|
| 1424 | - break; |
|
| 1425 | - default: //'REG_date' |
|
| 1426 | - $orderby_field = 'REG_date'; |
|
| 1427 | - } |
|
| 1428 | - |
|
| 1429 | - //order |
|
| 1430 | - $order = ! empty($this->_req_data['order']) |
|
| 1431 | - ? sanitize_text_field($this->_req_data['order']) |
|
| 1432 | - : 'DESC'; |
|
| 1433 | - |
|
| 1434 | - //mutate orderby_field |
|
| 1435 | - $orderby_field = array_combine( |
|
| 1436 | - (array) $orderby_field, |
|
| 1437 | - array_fill(0, count($orderby_field), $order) |
|
| 1438 | - ); |
|
| 1439 | - //because there are many registrations with the same date, define |
|
| 1440 | - //a secondary way to order them, otherwise MySQL seems to be a bit random |
|
| 1441 | - if (empty($order['REG_ID'])) { |
|
| 1442 | - $orderby_field['REG_ID'] = $order; |
|
| 1443 | - } |
|
| 1444 | - return array('order_by' => $orderby_field); |
|
| 1445 | - } |
|
| 1446 | - |
|
| 1447 | - |
|
| 1448 | - /** |
|
| 1449 | - * Sets up the limit for the registrations query. |
|
| 1450 | - * |
|
| 1451 | - * @param $per_page |
|
| 1452 | - * @return array |
|
| 1453 | - */ |
|
| 1454 | - protected function _get_limit($per_page) |
|
| 1455 | - { |
|
| 1456 | - $current_page = ! empty($this->_req_data['paged']) |
|
| 1457 | - ? absint($this->_req_data['paged']) |
|
| 1458 | - : 1; |
|
| 1459 | - $per_page = ! empty($this->_req_data['perpage']) |
|
| 1460 | - ? $this->_req_data['perpage'] |
|
| 1461 | - : $per_page; |
|
| 1462 | - |
|
| 1463 | - //-1 means return all results so get out if that's set. |
|
| 1464 | - if ((int)$per_page === -1) { |
|
| 1465 | - return array(); |
|
| 1466 | - } |
|
| 1467 | - $per_page = absint($per_page); |
|
| 1468 | - $offset = ($current_page - 1) * $per_page; |
|
| 1469 | - return array('limit' => array($offset, $per_page)); |
|
| 1470 | - } |
|
| 1471 | - |
|
| 1472 | - |
|
| 1473 | - public function get_registration_status_array() |
|
| 1474 | - { |
|
| 1475 | - return self::$_reg_status; |
|
| 1476 | - } |
|
| 1477 | - |
|
| 1478 | - |
|
| 1479 | - |
|
| 1480 | - |
|
| 1481 | - /*************************************** REGISTRATION DETAILS ***************************************/ |
|
| 1482 | - /** |
|
| 1483 | - * generates HTML for the View Registration Details Admin page |
|
| 1484 | - * |
|
| 1485 | - * @access protected |
|
| 1486 | - * @return void |
|
| 1487 | - * @throws DomainException |
|
| 1488 | - * @throws EE_Error |
|
| 1489 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 1490 | - */ |
|
| 1491 | - protected function _registration_details() |
|
| 1492 | - { |
|
| 1493 | - $this->_template_args = array(); |
|
| 1494 | - $this->_set_registration_object(); |
|
| 1495 | - if (is_object($this->_registration)) { |
|
| 1496 | - $transaction = $this->_registration->transaction() |
|
| 1497 | - ? $this->_registration->transaction() |
|
| 1498 | - : EE_Transaction::new_instance(); |
|
| 1499 | - $this->_session = $transaction->session_data(); |
|
| 1500 | - $event_id = $this->_registration->event_ID(); |
|
| 1501 | - $this->_template_args['reg_nmbr']['value'] = $this->_registration->ID(); |
|
| 1502 | - $this->_template_args['reg_nmbr']['label'] = esc_html__('Registration Number', 'event_espresso'); |
|
| 1503 | - $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date'); |
|
| 1504 | - $this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso'); |
|
| 1505 | - $this->_template_args['grand_total'] = $transaction->total(); |
|
| 1506 | - $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 1507 | - // link back to overview |
|
| 1508 | - $this->_template_args['reg_overview_url'] = REG_ADMIN_URL; |
|
| 1509 | - $this->_template_args['registration'] = $this->_registration; |
|
| 1510 | - $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1511 | - array( |
|
| 1512 | - 'action' => 'default', |
|
| 1513 | - 'event_id' => $event_id, |
|
| 1514 | - ), |
|
| 1515 | - REG_ADMIN_URL |
|
| 1516 | - ); |
|
| 1517 | - $this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1518 | - array( |
|
| 1519 | - 'action' => 'default', |
|
| 1520 | - 'EVT_ID' => $event_id, |
|
| 1521 | - 'page' => 'espresso_transactions', |
|
| 1522 | - ), |
|
| 1523 | - admin_url('admin.php') |
|
| 1524 | - ); |
|
| 1525 | - $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1526 | - array( |
|
| 1527 | - 'page' => 'espresso_events', |
|
| 1528 | - 'action' => 'edit', |
|
| 1529 | - 'post' => $event_id, |
|
| 1530 | - ), |
|
| 1531 | - admin_url('admin.php') |
|
| 1532 | - ); |
|
| 1533 | - //next and previous links |
|
| 1534 | - $next_reg = $this->_registration->next( |
|
| 1535 | - null, |
|
| 1536 | - array(), |
|
| 1537 | - 'REG_ID' |
|
| 1538 | - ); |
|
| 1539 | - $this->_template_args['next_registration'] = $next_reg |
|
| 1540 | - ? $this->_next_link( |
|
| 1541 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 1542 | - array( |
|
| 1543 | - 'action' => 'view_registration', |
|
| 1544 | - '_REG_ID' => $next_reg['REG_ID'], |
|
| 1545 | - ), |
|
| 1546 | - REG_ADMIN_URL |
|
| 1547 | - ), |
|
| 1548 | - 'dashicons dashicons-arrow-right ee-icon-size-22' |
|
| 1549 | - ) |
|
| 1550 | - : ''; |
|
| 1551 | - $previous_reg = $this->_registration->previous( |
|
| 1552 | - null, |
|
| 1553 | - array(), |
|
| 1554 | - 'REG_ID' |
|
| 1555 | - ); |
|
| 1556 | - $this->_template_args['previous_registration'] = $previous_reg |
|
| 1557 | - ? $this->_previous_link( |
|
| 1558 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 1559 | - array( |
|
| 1560 | - 'action' => 'view_registration', |
|
| 1561 | - '_REG_ID' => $previous_reg['REG_ID'], |
|
| 1562 | - ), |
|
| 1563 | - REG_ADMIN_URL |
|
| 1564 | - ), |
|
| 1565 | - 'dashicons dashicons-arrow-left ee-icon-size-22' |
|
| 1566 | - ) |
|
| 1567 | - : ''; |
|
| 1568 | - // grab header |
|
| 1569 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php'; |
|
| 1570 | - $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
| 1571 | - $this->_template_args['admin_page_header'] = EEH_Template::display_template( |
|
| 1572 | - $template_path, |
|
| 1573 | - $this->_template_args, |
|
| 1574 | - true |
|
| 1575 | - ); |
|
| 1576 | - } else { |
|
| 1577 | - $this->_template_args['admin_page_header'] = $this->display_espresso_notices(); |
|
| 1578 | - } |
|
| 1579 | - // the details template wrapper |
|
| 1580 | - $this->display_admin_page_with_sidebar(); |
|
| 1581 | - } |
|
| 1582 | - |
|
| 1583 | - |
|
| 1584 | - protected function _registration_details_metaboxes() |
|
| 1585 | - { |
|
| 1586 | - do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this); |
|
| 1587 | - $this->_set_registration_object(); |
|
| 1588 | - $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null; |
|
| 1589 | - add_meta_box('edit-reg-status-mbox', esc_html__('Registration Status', 'event_espresso'), |
|
| 1590 | - array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high'); |
|
| 1591 | - add_meta_box('edit-reg-details-mbox', esc_html__('Registration Details', 'event_espresso'), |
|
| 1592 | - array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high'); |
|
| 1593 | - if ($attendee instanceof EE_Attendee |
|
| 1594 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 1595 | - 'ee_edit_registration', |
|
| 1596 | - 'edit-reg-questions-mbox', |
|
| 1597 | - $this->_registration->ID() |
|
| 1598 | - ) |
|
| 1599 | - ) { |
|
| 1600 | - add_meta_box( |
|
| 1601 | - 'edit-reg-questions-mbox', |
|
| 1602 | - esc_html__('Registration Form Answers', 'event_espresso'), |
|
| 1603 | - array($this, '_reg_questions_meta_box'), |
|
| 1604 | - $this->wp_page_slug, |
|
| 1605 | - 'normal', |
|
| 1606 | - 'high' |
|
| 1607 | - ); |
|
| 1608 | - } |
|
| 1609 | - add_meta_box( |
|
| 1610 | - 'edit-reg-registrant-mbox', |
|
| 1611 | - esc_html__('Contact Details', 'event_espresso'), |
|
| 1612 | - array($this, '_reg_registrant_side_meta_box'), |
|
| 1613 | - $this->wp_page_slug, |
|
| 1614 | - 'side', |
|
| 1615 | - 'high' |
|
| 1616 | - ); |
|
| 1617 | - if ($this->_registration->group_size() > 1) { |
|
| 1618 | - add_meta_box( |
|
| 1619 | - 'edit-reg-attendees-mbox', |
|
| 1620 | - esc_html__('Other Registrations in this Transaction', 'event_espresso'), |
|
| 1621 | - array($this, '_reg_attendees_meta_box'), |
|
| 1622 | - $this->wp_page_slug, |
|
| 1623 | - 'normal', |
|
| 1624 | - 'high' |
|
| 1625 | - ); |
|
| 1626 | - } |
|
| 1627 | - } |
|
| 1628 | - |
|
| 1629 | - |
|
| 1630 | - /** |
|
| 1631 | - * set_reg_status_buttons_metabox |
|
| 1632 | - * |
|
| 1633 | - * @access protected |
|
| 1634 | - * @return string |
|
| 1635 | - * @throws \EE_Error |
|
| 1636 | - */ |
|
| 1637 | - public function set_reg_status_buttons_metabox() |
|
| 1638 | - { |
|
| 1639 | - $this->_set_registration_object(); |
|
| 1640 | - $change_reg_status_form = $this->_generate_reg_status_change_form(); |
|
| 1641 | - echo $change_reg_status_form->form_open( |
|
| 1642 | - self::add_query_args_and_nonce( |
|
| 1643 | - array( |
|
| 1644 | - 'action' => 'change_reg_status', |
|
| 1645 | - ), |
|
| 1646 | - REG_ADMIN_URL |
|
| 1647 | - ) |
|
| 1648 | - ); |
|
| 1649 | - echo $change_reg_status_form->get_html(); |
|
| 1650 | - echo $change_reg_status_form->form_close(); |
|
| 1651 | - } |
|
| 1652 | - |
|
| 1653 | - |
|
| 1654 | - |
|
| 1655 | - /** |
|
| 1656 | - * @return EE_Form_Section_Proper |
|
| 1657 | - * @throws EE_Error |
|
| 1658 | - */ |
|
| 1659 | - protected function _generate_reg_status_change_form() |
|
| 1660 | - { |
|
| 1661 | - return new EE_Form_Section_Proper(array( |
|
| 1662 | - 'name' => 'reg_status_change_form', |
|
| 1663 | - 'html_id' => 'reg-status-change-form', |
|
| 1664 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 1665 | - 'subsections' => array( |
|
| 1666 | - 'return' => new EE_Hidden_Input(array( |
|
| 1667 | - 'name' => 'return', |
|
| 1668 | - 'default' => 'view_registration', |
|
| 1669 | - )), |
|
| 1670 | - 'REG_ID' => new EE_Hidden_Input(array( |
|
| 1671 | - 'name' => 'REG_ID', |
|
| 1672 | - 'default' => $this->_registration->ID(), |
|
| 1673 | - )), |
|
| 1674 | - 'current_status' => new EE_Form_Section_HTML( |
|
| 1675 | - EEH_HTML::tr( |
|
| 1676 | - EEH_HTML::th( |
|
| 1677 | - EEH_HTML::label( |
|
| 1678 | - EEH_HTML::strong(esc_html__('Current Registration Status', 'event_espresso') |
|
| 1679 | - ) |
|
| 1680 | - ) |
|
| 1681 | - ) |
|
| 1682 | - . EEH_HTML::td( |
|
| 1683 | - EEH_HTML::strong( |
|
| 1684 | - $this->_registration->pretty_status(), |
|
| 1685 | - '', |
|
| 1686 | - 'status-' . $this->_registration->status_ID(), |
|
| 1687 | - 'line-height: 1em; font-size: 1.5em; font-weight: bold;' |
|
| 1688 | - ) |
|
| 1689 | - ) |
|
| 1690 | - ) |
|
| 1691 | - ), |
|
| 1692 | - 'reg_status' => new EE_Select_Input( |
|
| 1693 | - $this->_get_reg_statuses(), |
|
| 1694 | - array( |
|
| 1695 | - 'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'), |
|
| 1696 | - 'default' => $this->_registration->status_ID(), |
|
| 1697 | - ) |
|
| 1698 | - ), |
|
| 1699 | - 'send_notifications' => new EE_Yes_No_Input( |
|
| 1700 | - array( |
|
| 1701 | - 'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'), |
|
| 1702 | - 'default' => false, |
|
| 1703 | - 'html_help_text' => esc_html__( |
|
| 1704 | - 'If set to "Yes", then the related messages will be sent to the registrant.', |
|
| 1705 | - 'event_espresso' |
|
| 1706 | - ), |
|
| 1707 | - ) |
|
| 1708 | - ), |
|
| 1709 | - 'submit' => new EE_Submit_Input( |
|
| 1710 | - array( |
|
| 1711 | - 'html_class' => 'button-primary', |
|
| 1712 | - 'html_label_text' => ' ', |
|
| 1713 | - 'default' => esc_html__('Update Registration Status', 'event_espresso'), |
|
| 1714 | - ) |
|
| 1715 | - ), |
|
| 1716 | - ), |
|
| 1717 | - )); |
|
| 1718 | - } |
|
| 1719 | - |
|
| 1720 | - |
|
| 1721 | - /** |
|
| 1722 | - * Returns an array of all the buttons for the various statuses and switch status actions |
|
| 1723 | - * |
|
| 1724 | - * @return array |
|
| 1725 | - * @throws EE_Error |
|
| 1726 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 1727 | - */ |
|
| 1728 | - protected function _get_reg_statuses() |
|
| 1729 | - { |
|
| 1730 | - $reg_status_array = EEM_Registration::instance()->reg_status_array(); |
|
| 1731 | - unset ($reg_status_array[EEM_Registration::status_id_incomplete]); |
|
| 1732 | - // get current reg status |
|
| 1733 | - $current_status = $this->_registration->status_ID(); |
|
| 1734 | - // is registration for free event? This will determine whether to display the pending payment option |
|
| 1735 | - if ( |
|
| 1736 | - $current_status !== EEM_Registration::status_id_pending_payment |
|
| 1737 | - && $this->_registration->transaction()->is_free() |
|
| 1738 | - ) { |
|
| 1739 | - unset($reg_status_array[EEM_Registration::status_id_pending_payment]); |
|
| 1740 | - } |
|
| 1741 | - return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence'); |
|
| 1742 | - } |
|
| 1743 | - |
|
| 1744 | - |
|
| 1745 | - |
|
| 1746 | - /** |
|
| 1747 | - * This method is used when using _REG_ID from request which may or may not be an array of reg_ids. |
|
| 1748 | - * |
|
| 1749 | - * @param bool $status REG status given for changing registrations to. |
|
| 1750 | - * @param bool $notify Whether to send messages notifications or not. |
|
| 1751 | - * @return array (array with reg_id(s) updated and whether update was successful. |
|
| 1752 | - * @throws \EE_Error |
|
| 1753 | - */ |
|
| 1754 | - protected function _set_registration_status_from_request($status = false, $notify = false) |
|
| 1755 | - { |
|
| 1756 | - if (isset($this->_req_data['reg_status_change_form'])) { |
|
| 1757 | - $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID']) |
|
| 1758 | - ? (array)$this->_req_data['reg_status_change_form']['REG_ID'] : array(); |
|
| 1759 | - } else { |
|
| 1760 | - $REG_IDs = isset($this->_req_data['_REG_ID']) ? (array)$this->_req_data['_REG_ID'] : array(); |
|
| 1761 | - } |
|
| 1762 | - $success = $this->_set_registration_status($REG_IDs, $status); |
|
| 1763 | - //notify? |
|
| 1764 | - if ($success |
|
| 1765 | - && $notify |
|
| 1766 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 1767 | - 'ee_send_message', |
|
| 1768 | - 'espresso_registrations_resend_registration' |
|
| 1769 | - ) |
|
| 1770 | - ) { |
|
| 1771 | - $this->_process_resend_registration(); |
|
| 1772 | - } |
|
| 1773 | - return $success; |
|
| 1774 | - } |
|
| 1775 | - |
|
| 1776 | - |
|
| 1777 | - |
|
| 1778 | - /** |
|
| 1779 | - * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an |
|
| 1780 | - * array). Note, this method does NOT take care of possible notifications. That is required by calling code. |
|
| 1781 | - * |
|
| 1782 | - * @param array $REG_IDs |
|
| 1783 | - * @param bool $status |
|
| 1784 | - * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as |
|
| 1785 | - * @throws \RuntimeException |
|
| 1786 | - * @throws \EE_Error |
|
| 1787 | - * the array of updated registrations). |
|
| 1788 | - * @throws EE_Error |
|
| 1789 | - * @throws RuntimeException |
|
| 1790 | - */ |
|
| 1791 | - protected function _set_registration_status($REG_IDs = array(), $status = false) |
|
| 1792 | - { |
|
| 1793 | - $success = false; |
|
| 1794 | - // typecast $REG_IDs |
|
| 1795 | - $REG_IDs = (array)$REG_IDs; |
|
| 1796 | - if ( ! empty($REG_IDs)) { |
|
| 1797 | - $success = true; |
|
| 1798 | - // set default status if none is passed |
|
| 1799 | - $status = $status ? $status : EEM_Registration::status_id_pending_payment; |
|
| 1800 | - // sanitize $REG_IDs |
|
| 1801 | - $REG_IDs = array_filter($REG_IDs, 'absint'); |
|
| 1802 | - //loop through REG_ID's and change status |
|
| 1803 | - foreach ($REG_IDs as $REG_ID) { |
|
| 1804 | - $registration = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
| 1805 | - if ($registration instanceof EE_Registration) { |
|
| 1806 | - $registration->set_status($status); |
|
| 1807 | - $result = $registration->save(); |
|
| 1808 | - // verifying explicit fails because update *may* just return 0 for 0 rows affected |
|
| 1809 | - $success = $result !== false ? $success : false; |
|
| 1810 | - } |
|
| 1811 | - } |
|
| 1812 | - } |
|
| 1813 | - //reset _req_data['_REG_ID'] for any potential future messages notifications |
|
| 1814 | - $this->_req_data['_REG_ID'] = $REG_IDs; |
|
| 1815 | - //return $success and processed registrations |
|
| 1816 | - return array('REG_ID' => $REG_IDs, 'success' => $success); |
|
| 1817 | - } |
|
| 1818 | - |
|
| 1819 | - |
|
| 1820 | - /** |
|
| 1821 | - * Common logic for setting up success message and redirecting to appropriate route |
|
| 1822 | - * |
|
| 1823 | - * @param string $STS_ID status id for the registration changed to |
|
| 1824 | - * @param bool $notify indicates whether the _set_registration_status_from_request does notifications or not. |
|
| 1825 | - * @return void |
|
| 1826 | - */ |
|
| 1827 | - protected function _reg_status_change_return($STS_ID, $notify = false) |
|
| 1828 | - { |
|
| 1829 | - $result = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify) |
|
| 1830 | - : array('success' => false); |
|
| 1831 | - $success = isset($result['success']) && $result['success']; |
|
| 1832 | - //setup success message |
|
| 1833 | - if ($success) { |
|
| 1834 | - if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) { |
|
| 1835 | - $msg = sprintf(esc_html__('Registration status has been set to %s', 'event_espresso'), |
|
| 1836 | - EEH_Template::pretty_status($STS_ID, false, 'lower')); |
|
| 1837 | - } else { |
|
| 1838 | - $msg = sprintf(esc_html__('Registrations have been set to %s.', 'event_espresso'), |
|
| 1839 | - EEH_Template::pretty_status($STS_ID, false, 'lower')); |
|
| 1840 | - } |
|
| 1841 | - EE_Error::add_success($msg); |
|
| 1842 | - } else { |
|
| 1843 | - EE_Error::add_error( |
|
| 1844 | - esc_html__( |
|
| 1845 | - 'Something went wrong, and the status was not changed', |
|
| 1846 | - 'event_espresso' |
|
| 1847 | - ), __FILE__, __LINE__, __FUNCTION__ |
|
| 1848 | - ); |
|
| 1849 | - } |
|
| 1850 | - if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') { |
|
| 1851 | - $route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID'])); |
|
| 1852 | - } else { |
|
| 1853 | - $route = array('action' => 'default'); |
|
| 1854 | - } |
|
| 1855 | - //unset nonces |
|
| 1856 | - foreach ($this->_req_data as $ref => $value) { |
|
| 1857 | - if (strpos($ref, 'nonce') !== false) { |
|
| 1858 | - unset($this->_req_data[$ref]); |
|
| 1859 | - continue; |
|
| 1860 | - } |
|
| 1861 | - $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value); |
|
| 1862 | - $this->_req_data[$ref] = $value; |
|
| 1863 | - } |
|
| 1864 | - //merge request vars so that the reloaded list table contains any existing filter query params |
|
| 1865 | - $route = array_merge($this->_req_data, $route); |
|
| 1866 | - $this->_redirect_after_action($success, '', '', $route, true); |
|
| 1867 | - } |
|
| 1868 | - |
|
| 1869 | - |
|
| 1870 | - /** |
|
| 1871 | - * incoming reg status change from reg details page. |
|
| 1872 | - * |
|
| 1873 | - * @return void |
|
| 1874 | - */ |
|
| 1875 | - protected function _change_reg_status() |
|
| 1876 | - { |
|
| 1877 | - $this->_req_data['return'] = 'view_registration'; |
|
| 1878 | - //set notify based on whether the send notifications toggle is set or not |
|
| 1879 | - $notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']); |
|
| 1880 | - //$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] ); |
|
| 1881 | - $this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status']) |
|
| 1882 | - ? $this->_req_data['reg_status_change_form']['reg_status'] : ''; |
|
| 1883 | - switch ($this->_req_data['reg_status_change_form']['reg_status']) { |
|
| 1884 | - case EEM_Registration::status_id_approved : |
|
| 1885 | - case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') : |
|
| 1886 | - $this->approve_registration($notify); |
|
| 1887 | - break; |
|
| 1888 | - case EEM_Registration::status_id_pending_payment : |
|
| 1889 | - case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') : |
|
| 1890 | - $this->pending_registration($notify); |
|
| 1891 | - break; |
|
| 1892 | - case EEM_Registration::status_id_not_approved : |
|
| 1893 | - case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') : |
|
| 1894 | - $this->not_approve_registration($notify); |
|
| 1895 | - break; |
|
| 1896 | - case EEM_Registration::status_id_declined : |
|
| 1897 | - case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') : |
|
| 1898 | - $this->decline_registration($notify); |
|
| 1899 | - break; |
|
| 1900 | - case EEM_Registration::status_id_cancelled : |
|
| 1901 | - case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') : |
|
| 1902 | - $this->cancel_registration($notify); |
|
| 1903 | - break; |
|
| 1904 | - case EEM_Registration::status_id_wait_list : |
|
| 1905 | - case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') : |
|
| 1906 | - $this->wait_list_registration($notify); |
|
| 1907 | - break; |
|
| 1908 | - case EEM_Registration::status_id_incomplete : |
|
| 1909 | - default : |
|
| 1910 | - $result['success'] = false; |
|
| 1911 | - unset($this->_req_data['return']); |
|
| 1912 | - $this->_reg_status_change_return('', false); |
|
| 1913 | - break; |
|
| 1914 | - } |
|
| 1915 | - } |
|
| 1916 | - |
|
| 1917 | - |
|
| 1918 | - /** |
|
| 1919 | - * Callback for bulk action routes. |
|
| 1920 | - * Note: although we could just register the singular route callbacks for each bulk action route as well, this |
|
| 1921 | - * method was chosen so there is one central place all the registration status bulk actions are going through. |
|
| 1922 | - * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to |
|
| 1923 | - * when an action is happening on just a single registration). |
|
| 1924 | - * @param $action |
|
| 1925 | - * @param bool $notify |
|
| 1926 | - */ |
|
| 1927 | - protected function bulk_action_on_registrations($action, $notify = false) { |
|
| 1928 | - do_action( |
|
| 1929 | - 'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution', |
|
| 1930 | - $this, |
|
| 1931 | - $action, |
|
| 1932 | - $notify |
|
| 1933 | - ); |
|
| 1934 | - $method = $action . '_registration'; |
|
| 1935 | - if (method_exists($this, $method)) { |
|
| 1936 | - $this->$method($notify); |
|
| 1937 | - } |
|
| 1938 | - } |
|
| 1939 | - |
|
| 1940 | - |
|
| 1941 | - /** |
|
| 1942 | - * approve_registration |
|
| 1943 | - * |
|
| 1944 | - * @access protected |
|
| 1945 | - * @param bool $notify whether or not to notify the registrant about their approval. |
|
| 1946 | - * @return void |
|
| 1947 | - */ |
|
| 1948 | - protected function approve_registration($notify = false) |
|
| 1949 | - { |
|
| 1950 | - $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify); |
|
| 1951 | - } |
|
| 1952 | - |
|
| 1953 | - |
|
| 1954 | - /** |
|
| 1955 | - * decline_registration |
|
| 1956 | - * |
|
| 1957 | - * @access protected |
|
| 1958 | - * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1959 | - * @return void |
|
| 1960 | - */ |
|
| 1961 | - protected function decline_registration($notify = false) |
|
| 1962 | - { |
|
| 1963 | - $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify); |
|
| 1964 | - } |
|
| 1965 | - |
|
| 1966 | - |
|
| 1967 | - /** |
|
| 1968 | - * cancel_registration |
|
| 1969 | - * |
|
| 1970 | - * @access protected |
|
| 1971 | - * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1972 | - * @return void |
|
| 1973 | - */ |
|
| 1974 | - protected function cancel_registration($notify = false) |
|
| 1975 | - { |
|
| 1976 | - $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify); |
|
| 1977 | - } |
|
| 1978 | - |
|
| 1979 | - |
|
| 1980 | - /** |
|
| 1981 | - * not_approve_registration |
|
| 1982 | - * |
|
| 1983 | - * @access protected |
|
| 1984 | - * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1985 | - * @return void |
|
| 1986 | - */ |
|
| 1987 | - protected function not_approve_registration($notify = false) |
|
| 1988 | - { |
|
| 1989 | - $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify); |
|
| 1990 | - } |
|
| 1991 | - |
|
| 1992 | - |
|
| 1993 | - /** |
|
| 1994 | - * decline_registration |
|
| 1995 | - * |
|
| 1996 | - * @access protected |
|
| 1997 | - * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1998 | - * @return void |
|
| 1999 | - */ |
|
| 2000 | - protected function pending_registration($notify = false) |
|
| 2001 | - { |
|
| 2002 | - $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify); |
|
| 2003 | - } |
|
| 2004 | - |
|
| 2005 | - |
|
| 2006 | - /** |
|
| 2007 | - * waitlist_registration |
|
| 2008 | - * |
|
| 2009 | - * @access protected |
|
| 2010 | - * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 2011 | - * @return void |
|
| 2012 | - */ |
|
| 2013 | - protected function wait_list_registration($notify = false) |
|
| 2014 | - { |
|
| 2015 | - $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify); |
|
| 2016 | - } |
|
| 2017 | - |
|
| 2018 | - |
|
| 2019 | - /** |
|
| 2020 | - * generates HTML for the Registration main meta box |
|
| 2021 | - * |
|
| 2022 | - * @access public |
|
| 2023 | - * @return void |
|
| 2024 | - * @throws DomainException |
|
| 2025 | - * @throws EE_Error |
|
| 2026 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 2027 | - */ |
|
| 2028 | - public function _reg_details_meta_box() |
|
| 2029 | - { |
|
| 2030 | - EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 2031 | - EEH_Autoloader::register_line_item_filter_autoloaders(); |
|
| 2032 | - EE_Registry::instance()->load_helper('Line_Item'); |
|
| 2033 | - $transaction = $this->_registration->transaction() ? $this->_registration->transaction() |
|
| 2034 | - : EE_Transaction::new_instance(); |
|
| 2035 | - $this->_session = $transaction->session_data(); |
|
| 2036 | - $filters = new EE_Line_Item_Filter_Collection(); |
|
| 2037 | - //$filters->add( new EE_Non_Zero_Line_Item_Filter() ); |
|
| 2038 | - $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration)); |
|
| 2039 | - $line_item_filter_processor = new EE_Line_Item_Filter_Processor($filters, |
|
| 2040 | - $transaction->total_line_item()); |
|
| 2041 | - $filtered_line_item_tree = $line_item_filter_processor->process(); |
|
| 2042 | - $line_item_display = new EE_Line_Item_Display('reg_admin_table', |
|
| 2043 | - 'EE_Admin_Table_Registration_Line_Item_Display_Strategy'); |
|
| 2044 | - $this->_template_args['line_item_table'] = $line_item_display->display_line_item( |
|
| 2045 | - $filtered_line_item_tree, |
|
| 2046 | - array('EE_Registration' => $this->_registration) |
|
| 2047 | - ); |
|
| 2048 | - $attendee = $this->_registration->attendee(); |
|
| 2049 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 2050 | - 'ee_read_transaction', |
|
| 2051 | - 'espresso_transactions_view_transaction' |
|
| 2052 | - )) { |
|
| 2053 | - $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link( |
|
| 2054 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 2055 | - array( |
|
| 2056 | - 'action' => 'view_transaction', |
|
| 2057 | - 'TXN_ID' => $transaction->ID(), |
|
| 2058 | - ), |
|
| 2059 | - TXN_ADMIN_URL |
|
| 2060 | - ), |
|
| 2061 | - esc_html__(' View Transaction', 'event_espresso'), |
|
| 2062 | - 'button secondary-button right', |
|
| 2063 | - 'dashicons dashicons-cart' |
|
| 2064 | - ); |
|
| 2065 | - } else { |
|
| 2066 | - $this->_template_args['view_transaction_button'] = ''; |
|
| 2067 | - } |
|
| 2068 | - if ($attendee instanceof EE_Attendee |
|
| 2069 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 2070 | - 'ee_send_message', |
|
| 2071 | - 'espresso_registrations_resend_registration' |
|
| 2072 | - ) |
|
| 2073 | - ) { |
|
| 2074 | - $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link( |
|
| 2075 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 2076 | - array( |
|
| 2077 | - 'action' => 'resend_registration', |
|
| 2078 | - '_REG_ID' => $this->_registration->ID(), |
|
| 2079 | - 'redirect_to' => 'view_registration', |
|
| 2080 | - ), |
|
| 2081 | - REG_ADMIN_URL |
|
| 2082 | - ), |
|
| 2083 | - esc_html__(' Resend Registration', 'event_espresso'), |
|
| 2084 | - 'button secondary-button right', |
|
| 2085 | - 'dashicons dashicons-email-alt' |
|
| 2086 | - ); |
|
| 2087 | - } else { |
|
| 2088 | - $this->_template_args['resend_registration_button'] = ''; |
|
| 2089 | - } |
|
| 2090 | - $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 2091 | - $payment = $transaction->get_first_related('Payment'); |
|
| 2092 | - $payment = ! $payment instanceof EE_Payment |
|
| 2093 | - ? EE_Payment::new_instance() |
|
| 2094 | - : $payment; |
|
| 2095 | - $payment_method = $payment->get_first_related('Payment_Method'); |
|
| 2096 | - $payment_method = ! $payment_method instanceof EE_Payment_Method |
|
| 2097 | - ? EE_Payment_Method::new_instance() |
|
| 2098 | - : $payment_method; |
|
| 2099 | - $reg_details = array( |
|
| 2100 | - 'payment_method' => $payment_method->name(), |
|
| 2101 | - 'response_msg' => $payment->gateway_response(), |
|
| 2102 | - 'registration_id' => $this->_registration->get('REG_code'), |
|
| 2103 | - 'registration_session' => $this->_registration->session_ID(), |
|
| 2104 | - 'ip_address' => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '', |
|
| 2105 | - 'user_agent' => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '', |
|
| 2106 | - ); |
|
| 2107 | - if (isset($reg_details['registration_id'])) { |
|
| 2108 | - $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id']; |
|
| 2109 | - $this->_template_args['reg_details']['registration_id']['label'] = esc_html__( |
|
| 2110 | - 'Registration ID', |
|
| 2111 | - 'event_espresso' |
|
| 2112 | - ); |
|
| 2113 | - $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text'; |
|
| 2114 | - } |
|
| 2115 | - if (isset($reg_details['payment_method'])) { |
|
| 2116 | - $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method']; |
|
| 2117 | - $this->_template_args['reg_details']['payment_method']['label'] = esc_html__( |
|
| 2118 | - 'Most Recent Payment Method', |
|
| 2119 | - 'event_espresso' |
|
| 2120 | - ); |
|
| 2121 | - $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text'; |
|
| 2122 | - $this->_template_args['reg_details']['response_msg']['value'] = $reg_details['response_msg']; |
|
| 2123 | - $this->_template_args['reg_details']['response_msg']['label'] = esc_html__( |
|
| 2124 | - 'Payment method response', |
|
| 2125 | - 'event_espresso' |
|
| 2126 | - ); |
|
| 2127 | - $this->_template_args['reg_details']['response_msg']['class'] = 'regular-text'; |
|
| 2128 | - } |
|
| 2129 | - $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session']; |
|
| 2130 | - $this->_template_args['reg_details']['registration_session']['label'] = esc_html__( |
|
| 2131 | - 'Registration Session', |
|
| 2132 | - 'event_espresso' |
|
| 2133 | - ); |
|
| 2134 | - $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text'; |
|
| 2135 | - $this->_template_args['reg_details']['ip_address']['value'] = $reg_details['ip_address']; |
|
| 2136 | - $this->_template_args['reg_details']['ip_address']['label'] = esc_html__( |
|
| 2137 | - 'Registration placed from IP', |
|
| 2138 | - 'event_espresso' |
|
| 2139 | - ); |
|
| 2140 | - $this->_template_args['reg_details']['ip_address']['class'] = 'regular-text'; |
|
| 2141 | - $this->_template_args['reg_details']['user_agent']['value'] = $reg_details['user_agent']; |
|
| 2142 | - $this->_template_args['reg_details']['user_agent']['label'] = esc_html__('Registrant User Agent', |
|
| 2143 | - 'event_espresso'); |
|
| 2144 | - $this->_template_args['reg_details']['user_agent']['class'] = 'large-text'; |
|
| 2145 | - $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2146 | - array( |
|
| 2147 | - 'action' => 'default', |
|
| 2148 | - 'event_id' => $this->_registration->event_ID(), |
|
| 2149 | - ), |
|
| 2150 | - REG_ADMIN_URL |
|
| 2151 | - ); |
|
| 2152 | - $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
| 2153 | - $this->_template_args['event_id'] = $this->_registration->event_ID(); |
|
| 2154 | - $template_path = |
|
| 2155 | - REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php'; |
|
| 2156 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2157 | - } |
|
| 2158 | - |
|
| 2159 | - |
|
| 2160 | - /** |
|
| 2161 | - * generates HTML for the Registration Questions meta box. |
|
| 2162 | - * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters), |
|
| 2163 | - * otherwise uses new forms system |
|
| 2164 | - * |
|
| 2165 | - * @access public |
|
| 2166 | - * @return void |
|
| 2167 | - * @throws DomainException |
|
| 2168 | - * @throws EE_Error |
|
| 2169 | - */ |
|
| 2170 | - public function _reg_questions_meta_box() |
|
| 2171 | - { |
|
| 2172 | - //allow someone to override this method entirely |
|
| 2173 | - if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this, |
|
| 2174 | - $this->_registration)) { |
|
| 2175 | - $form = $this->_get_reg_custom_questions_form( |
|
| 2176 | - $this->_registration->ID() |
|
| 2177 | - ); |
|
| 2178 | - $this->_template_args['att_questions'] = count($form->subforms()) > 0 |
|
| 2179 | - ? $form->get_html_and_js() |
|
| 2180 | - : ''; |
|
| 2181 | - $this->_template_args['reg_questions_form_action'] = 'edit_registration'; |
|
| 2182 | - $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
| 2183 | - $template_path = |
|
| 2184 | - REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php'; |
|
| 2185 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2186 | - } |
|
| 2187 | - } |
|
| 2188 | - |
|
| 2189 | - |
|
| 2190 | - /** |
|
| 2191 | - * form_before_question_group |
|
| 2192 | - * |
|
| 2193 | - * @deprecated as of 4.8.32.rc.000 |
|
| 2194 | - * @access public |
|
| 2195 | - * @param string $output |
|
| 2196 | - * @return string |
|
| 2197 | - */ |
|
| 2198 | - public function form_before_question_group($output) |
|
| 2199 | - { |
|
| 2200 | - EE_Error::doing_it_wrong( |
|
| 2201 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 2202 | - esc_html__( |
|
| 2203 | - 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
|
| 2204 | - 'event_espresso' |
|
| 2205 | - ), |
|
| 2206 | - '4.8.32.rc.000' |
|
| 2207 | - ); |
|
| 2208 | - return ' |
|
| 1236 | + if (! empty($registration_status)) { |
|
| 1237 | + $where['STS_ID'] = $registration_status; |
|
| 1238 | + } else { |
|
| 1239 | + //make sure we exclude incomplete registrations, but only if not trashed. |
|
| 1240 | + if ($view === 'trash') { |
|
| 1241 | + $where['REG_deleted'] = true; |
|
| 1242 | + } elseif ($view === 'incomplete') { |
|
| 1243 | + $where['STS_ID'] = EEM_Registration::status_id_incomplete; |
|
| 1244 | + } else { |
|
| 1245 | + $where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
| 1246 | + } |
|
| 1247 | + } |
|
| 1248 | + return $where; |
|
| 1249 | + } |
|
| 1250 | + |
|
| 1251 | + |
|
| 1252 | + /** |
|
| 1253 | + * Adds any provided date restraints to the where conditions for the registrations query. |
|
| 1254 | + * |
|
| 1255 | + * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1256 | + * @return array |
|
| 1257 | + * @throws EE_Error |
|
| 1258 | + */ |
|
| 1259 | + protected function _add_date_to_where_conditions(array $request) |
|
| 1260 | + { |
|
| 1261 | + $where = array(); |
|
| 1262 | + $view = EEH_Array::is_set($request, 'status', ''); |
|
| 1263 | + $month_range = ! empty($request['month_range']) |
|
| 1264 | + ? sanitize_text_field($request['month_range']) |
|
| 1265 | + : ''; |
|
| 1266 | + $retrieve_for_today = $view === 'today'; |
|
| 1267 | + $retrieve_for_this_month = $view === 'month'; |
|
| 1268 | + |
|
| 1269 | + if ($retrieve_for_today) { |
|
| 1270 | + $now = date('Y-m-d', current_time('timestamp')); |
|
| 1271 | + $where['REG_date'] = array( |
|
| 1272 | + 'BETWEEN', |
|
| 1273 | + array( |
|
| 1274 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1275 | + 'REG_date', |
|
| 1276 | + $now . ' 00:00:00', |
|
| 1277 | + 'Y-m-d H:i:s' |
|
| 1278 | + ), |
|
| 1279 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1280 | + 'REG_date', |
|
| 1281 | + $now . ' 23:59:59', |
|
| 1282 | + 'Y-m-d H:i:s' |
|
| 1283 | + ), |
|
| 1284 | + ), |
|
| 1285 | + ); |
|
| 1286 | + } elseif ($retrieve_for_this_month) { |
|
| 1287 | + $current_year_and_month = date('Y-m', current_time('timestamp')); |
|
| 1288 | + $days_this_month = date('t', current_time('timestamp')); |
|
| 1289 | + $where['REG_date'] = array( |
|
| 1290 | + 'BETWEEN', |
|
| 1291 | + array( |
|
| 1292 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1293 | + 'REG_date', |
|
| 1294 | + $current_year_and_month . '-01 00:00:00', |
|
| 1295 | + 'Y-m-d H:i:s' |
|
| 1296 | + ), |
|
| 1297 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1298 | + 'REG_date', |
|
| 1299 | + $current_year_and_month . '-' . $days_this_month . ' 23:59:59', |
|
| 1300 | + 'Y-m-d H:i:s' |
|
| 1301 | + ), |
|
| 1302 | + ), |
|
| 1303 | + ); |
|
| 1304 | + } elseif ($month_range) { |
|
| 1305 | + $pieces = explode(' ', $month_range, 3); |
|
| 1306 | + $month_requested = ! empty($pieces[0]) |
|
| 1307 | + ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) |
|
| 1308 | + : ''; |
|
| 1309 | + $year_requested = ! empty($pieces[1]) |
|
| 1310 | + ? $pieces[1] |
|
| 1311 | + : ''; |
|
| 1312 | + //if there is not a month or year then we can't go further |
|
| 1313 | + if ($month_requested && $year_requested) { |
|
| 1314 | + $days_in_month = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01')); |
|
| 1315 | + $where['REG_date'] = array( |
|
| 1316 | + 'BETWEEN', |
|
| 1317 | + array( |
|
| 1318 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1319 | + 'REG_date', |
|
| 1320 | + $year_requested . '-' . $month_requested . '-01 00:00:00', |
|
| 1321 | + 'Y-m-d H:i:s' |
|
| 1322 | + ), |
|
| 1323 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1324 | + 'REG_date', |
|
| 1325 | + $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59', |
|
| 1326 | + 'Y-m-d H:i:s' |
|
| 1327 | + ), |
|
| 1328 | + ), |
|
| 1329 | + ); |
|
| 1330 | + } |
|
| 1331 | + } |
|
| 1332 | + return $where; |
|
| 1333 | + } |
|
| 1334 | + |
|
| 1335 | + |
|
| 1336 | + /** |
|
| 1337 | + * Adds any provided search restraints to the where conditions for the registrations query |
|
| 1338 | + * |
|
| 1339 | + * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1340 | + * @return array |
|
| 1341 | + */ |
|
| 1342 | + protected function _add_search_to_where_conditions(array $request) |
|
| 1343 | + { |
|
| 1344 | + $where = array(); |
|
| 1345 | + if (! empty($request['s'])) { |
|
| 1346 | + $search_string = '%' . sanitize_text_field($request['s']) . '%'; |
|
| 1347 | + $where['OR*search_conditions'] = array( |
|
| 1348 | + 'Event.EVT_name' => array('LIKE', $search_string), |
|
| 1349 | + 'Event.EVT_desc' => array('LIKE', $search_string), |
|
| 1350 | + 'Event.EVT_short_desc' => array('LIKE', $search_string), |
|
| 1351 | + 'Attendee.ATT_full_name' => array('LIKE', $search_string), |
|
| 1352 | + 'Attendee.ATT_fname' => array('LIKE', $search_string), |
|
| 1353 | + 'Attendee.ATT_lname' => array('LIKE', $search_string), |
|
| 1354 | + 'Attendee.ATT_short_bio' => array('LIKE', $search_string), |
|
| 1355 | + 'Attendee.ATT_email' => array('LIKE', $search_string), |
|
| 1356 | + 'Attendee.ATT_address' => array('LIKE', $search_string), |
|
| 1357 | + 'Attendee.ATT_address2' => array('LIKE', $search_string), |
|
| 1358 | + 'Attendee.ATT_city' => array('LIKE', $search_string), |
|
| 1359 | + 'REG_final_price' => array('LIKE', $search_string), |
|
| 1360 | + 'REG_code' => array('LIKE', $search_string), |
|
| 1361 | + 'REG_count' => array('LIKE', $search_string), |
|
| 1362 | + 'REG_group_size' => array('LIKE', $search_string), |
|
| 1363 | + 'Ticket.TKT_name' => array('LIKE', $search_string), |
|
| 1364 | + 'Ticket.TKT_description' => array('LIKE', $search_string), |
|
| 1365 | + 'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string), |
|
| 1366 | + ); |
|
| 1367 | + } |
|
| 1368 | + return $where; |
|
| 1369 | + } |
|
| 1370 | + |
|
| 1371 | + |
|
| 1372 | + /** |
|
| 1373 | + * Sets up the where conditions for the registrations query. |
|
| 1374 | + * |
|
| 1375 | + * @param array $request |
|
| 1376 | + * @return array |
|
| 1377 | + * @throws EE_Error |
|
| 1378 | + */ |
|
| 1379 | + protected function _get_where_conditions_for_registrations_query($request) |
|
| 1380 | + { |
|
| 1381 | + return apply_filters( |
|
| 1382 | + 'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query', |
|
| 1383 | + array_merge( |
|
| 1384 | + $this->_add_event_id_to_where_conditions($request), |
|
| 1385 | + $this->_add_category_id_to_where_conditions($request), |
|
| 1386 | + $this->_add_datetime_id_to_where_conditions($request), |
|
| 1387 | + $this->_add_registration_status_to_where_conditions($request), |
|
| 1388 | + $this->_add_date_to_where_conditions($request), |
|
| 1389 | + $this->_add_search_to_where_conditions($request) |
|
| 1390 | + ), |
|
| 1391 | + $request |
|
| 1392 | + ); |
|
| 1393 | + } |
|
| 1394 | + |
|
| 1395 | + |
|
| 1396 | + /** |
|
| 1397 | + * Sets up the orderby for the registrations query. |
|
| 1398 | + * |
|
| 1399 | + * @return array |
|
| 1400 | + */ |
|
| 1401 | + protected function _get_orderby_for_registrations_query() |
|
| 1402 | + { |
|
| 1403 | + $orderby_field = ! empty($this->_req_data['orderby']) |
|
| 1404 | + ? sanitize_text_field($this->_req_data['orderby']) |
|
| 1405 | + : ''; |
|
| 1406 | + switch ($orderby_field) { |
|
| 1407 | + case '_REG_ID': |
|
| 1408 | + $orderby_field = 'REG_ID'; |
|
| 1409 | + break; |
|
| 1410 | + case '_Reg_status': |
|
| 1411 | + $orderby_field = 'STS_ID'; |
|
| 1412 | + break; |
|
| 1413 | + case 'ATT_fname': |
|
| 1414 | + $orderby_field = array('Attendee.ATT_fname', 'Attendee.ATT_lname'); |
|
| 1415 | + break; |
|
| 1416 | + case 'ATT_lname': |
|
| 1417 | + $orderby_field = array('Attendee.ATT_lname', 'Attendee.ATT_fname'); |
|
| 1418 | + break; |
|
| 1419 | + case 'event_name': |
|
| 1420 | + $orderby_field = 'Event.EVT_name'; |
|
| 1421 | + break; |
|
| 1422 | + case 'DTT_EVT_start': |
|
| 1423 | + $orderby_field = 'Event.Datetime.DTT_EVT_start'; |
|
| 1424 | + break; |
|
| 1425 | + default: //'REG_date' |
|
| 1426 | + $orderby_field = 'REG_date'; |
|
| 1427 | + } |
|
| 1428 | + |
|
| 1429 | + //order |
|
| 1430 | + $order = ! empty($this->_req_data['order']) |
|
| 1431 | + ? sanitize_text_field($this->_req_data['order']) |
|
| 1432 | + : 'DESC'; |
|
| 1433 | + |
|
| 1434 | + //mutate orderby_field |
|
| 1435 | + $orderby_field = array_combine( |
|
| 1436 | + (array) $orderby_field, |
|
| 1437 | + array_fill(0, count($orderby_field), $order) |
|
| 1438 | + ); |
|
| 1439 | + //because there are many registrations with the same date, define |
|
| 1440 | + //a secondary way to order them, otherwise MySQL seems to be a bit random |
|
| 1441 | + if (empty($order['REG_ID'])) { |
|
| 1442 | + $orderby_field['REG_ID'] = $order; |
|
| 1443 | + } |
|
| 1444 | + return array('order_by' => $orderby_field); |
|
| 1445 | + } |
|
| 1446 | + |
|
| 1447 | + |
|
| 1448 | + /** |
|
| 1449 | + * Sets up the limit for the registrations query. |
|
| 1450 | + * |
|
| 1451 | + * @param $per_page |
|
| 1452 | + * @return array |
|
| 1453 | + */ |
|
| 1454 | + protected function _get_limit($per_page) |
|
| 1455 | + { |
|
| 1456 | + $current_page = ! empty($this->_req_data['paged']) |
|
| 1457 | + ? absint($this->_req_data['paged']) |
|
| 1458 | + : 1; |
|
| 1459 | + $per_page = ! empty($this->_req_data['perpage']) |
|
| 1460 | + ? $this->_req_data['perpage'] |
|
| 1461 | + : $per_page; |
|
| 1462 | + |
|
| 1463 | + //-1 means return all results so get out if that's set. |
|
| 1464 | + if ((int)$per_page === -1) { |
|
| 1465 | + return array(); |
|
| 1466 | + } |
|
| 1467 | + $per_page = absint($per_page); |
|
| 1468 | + $offset = ($current_page - 1) * $per_page; |
|
| 1469 | + return array('limit' => array($offset, $per_page)); |
|
| 1470 | + } |
|
| 1471 | + |
|
| 1472 | + |
|
| 1473 | + public function get_registration_status_array() |
|
| 1474 | + { |
|
| 1475 | + return self::$_reg_status; |
|
| 1476 | + } |
|
| 1477 | + |
|
| 1478 | + |
|
| 1479 | + |
|
| 1480 | + |
|
| 1481 | + /*************************************** REGISTRATION DETAILS ***************************************/ |
|
| 1482 | + /** |
|
| 1483 | + * generates HTML for the View Registration Details Admin page |
|
| 1484 | + * |
|
| 1485 | + * @access protected |
|
| 1486 | + * @return void |
|
| 1487 | + * @throws DomainException |
|
| 1488 | + * @throws EE_Error |
|
| 1489 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 1490 | + */ |
|
| 1491 | + protected function _registration_details() |
|
| 1492 | + { |
|
| 1493 | + $this->_template_args = array(); |
|
| 1494 | + $this->_set_registration_object(); |
|
| 1495 | + if (is_object($this->_registration)) { |
|
| 1496 | + $transaction = $this->_registration->transaction() |
|
| 1497 | + ? $this->_registration->transaction() |
|
| 1498 | + : EE_Transaction::new_instance(); |
|
| 1499 | + $this->_session = $transaction->session_data(); |
|
| 1500 | + $event_id = $this->_registration->event_ID(); |
|
| 1501 | + $this->_template_args['reg_nmbr']['value'] = $this->_registration->ID(); |
|
| 1502 | + $this->_template_args['reg_nmbr']['label'] = esc_html__('Registration Number', 'event_espresso'); |
|
| 1503 | + $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date'); |
|
| 1504 | + $this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso'); |
|
| 1505 | + $this->_template_args['grand_total'] = $transaction->total(); |
|
| 1506 | + $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 1507 | + // link back to overview |
|
| 1508 | + $this->_template_args['reg_overview_url'] = REG_ADMIN_URL; |
|
| 1509 | + $this->_template_args['registration'] = $this->_registration; |
|
| 1510 | + $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1511 | + array( |
|
| 1512 | + 'action' => 'default', |
|
| 1513 | + 'event_id' => $event_id, |
|
| 1514 | + ), |
|
| 1515 | + REG_ADMIN_URL |
|
| 1516 | + ); |
|
| 1517 | + $this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1518 | + array( |
|
| 1519 | + 'action' => 'default', |
|
| 1520 | + 'EVT_ID' => $event_id, |
|
| 1521 | + 'page' => 'espresso_transactions', |
|
| 1522 | + ), |
|
| 1523 | + admin_url('admin.php') |
|
| 1524 | + ); |
|
| 1525 | + $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1526 | + array( |
|
| 1527 | + 'page' => 'espresso_events', |
|
| 1528 | + 'action' => 'edit', |
|
| 1529 | + 'post' => $event_id, |
|
| 1530 | + ), |
|
| 1531 | + admin_url('admin.php') |
|
| 1532 | + ); |
|
| 1533 | + //next and previous links |
|
| 1534 | + $next_reg = $this->_registration->next( |
|
| 1535 | + null, |
|
| 1536 | + array(), |
|
| 1537 | + 'REG_ID' |
|
| 1538 | + ); |
|
| 1539 | + $this->_template_args['next_registration'] = $next_reg |
|
| 1540 | + ? $this->_next_link( |
|
| 1541 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 1542 | + array( |
|
| 1543 | + 'action' => 'view_registration', |
|
| 1544 | + '_REG_ID' => $next_reg['REG_ID'], |
|
| 1545 | + ), |
|
| 1546 | + REG_ADMIN_URL |
|
| 1547 | + ), |
|
| 1548 | + 'dashicons dashicons-arrow-right ee-icon-size-22' |
|
| 1549 | + ) |
|
| 1550 | + : ''; |
|
| 1551 | + $previous_reg = $this->_registration->previous( |
|
| 1552 | + null, |
|
| 1553 | + array(), |
|
| 1554 | + 'REG_ID' |
|
| 1555 | + ); |
|
| 1556 | + $this->_template_args['previous_registration'] = $previous_reg |
|
| 1557 | + ? $this->_previous_link( |
|
| 1558 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 1559 | + array( |
|
| 1560 | + 'action' => 'view_registration', |
|
| 1561 | + '_REG_ID' => $previous_reg['REG_ID'], |
|
| 1562 | + ), |
|
| 1563 | + REG_ADMIN_URL |
|
| 1564 | + ), |
|
| 1565 | + 'dashicons dashicons-arrow-left ee-icon-size-22' |
|
| 1566 | + ) |
|
| 1567 | + : ''; |
|
| 1568 | + // grab header |
|
| 1569 | + $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php'; |
|
| 1570 | + $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
| 1571 | + $this->_template_args['admin_page_header'] = EEH_Template::display_template( |
|
| 1572 | + $template_path, |
|
| 1573 | + $this->_template_args, |
|
| 1574 | + true |
|
| 1575 | + ); |
|
| 1576 | + } else { |
|
| 1577 | + $this->_template_args['admin_page_header'] = $this->display_espresso_notices(); |
|
| 1578 | + } |
|
| 1579 | + // the details template wrapper |
|
| 1580 | + $this->display_admin_page_with_sidebar(); |
|
| 1581 | + } |
|
| 1582 | + |
|
| 1583 | + |
|
| 1584 | + protected function _registration_details_metaboxes() |
|
| 1585 | + { |
|
| 1586 | + do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this); |
|
| 1587 | + $this->_set_registration_object(); |
|
| 1588 | + $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null; |
|
| 1589 | + add_meta_box('edit-reg-status-mbox', esc_html__('Registration Status', 'event_espresso'), |
|
| 1590 | + array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high'); |
|
| 1591 | + add_meta_box('edit-reg-details-mbox', esc_html__('Registration Details', 'event_espresso'), |
|
| 1592 | + array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high'); |
|
| 1593 | + if ($attendee instanceof EE_Attendee |
|
| 1594 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 1595 | + 'ee_edit_registration', |
|
| 1596 | + 'edit-reg-questions-mbox', |
|
| 1597 | + $this->_registration->ID() |
|
| 1598 | + ) |
|
| 1599 | + ) { |
|
| 1600 | + add_meta_box( |
|
| 1601 | + 'edit-reg-questions-mbox', |
|
| 1602 | + esc_html__('Registration Form Answers', 'event_espresso'), |
|
| 1603 | + array($this, '_reg_questions_meta_box'), |
|
| 1604 | + $this->wp_page_slug, |
|
| 1605 | + 'normal', |
|
| 1606 | + 'high' |
|
| 1607 | + ); |
|
| 1608 | + } |
|
| 1609 | + add_meta_box( |
|
| 1610 | + 'edit-reg-registrant-mbox', |
|
| 1611 | + esc_html__('Contact Details', 'event_espresso'), |
|
| 1612 | + array($this, '_reg_registrant_side_meta_box'), |
|
| 1613 | + $this->wp_page_slug, |
|
| 1614 | + 'side', |
|
| 1615 | + 'high' |
|
| 1616 | + ); |
|
| 1617 | + if ($this->_registration->group_size() > 1) { |
|
| 1618 | + add_meta_box( |
|
| 1619 | + 'edit-reg-attendees-mbox', |
|
| 1620 | + esc_html__('Other Registrations in this Transaction', 'event_espresso'), |
|
| 1621 | + array($this, '_reg_attendees_meta_box'), |
|
| 1622 | + $this->wp_page_slug, |
|
| 1623 | + 'normal', |
|
| 1624 | + 'high' |
|
| 1625 | + ); |
|
| 1626 | + } |
|
| 1627 | + } |
|
| 1628 | + |
|
| 1629 | + |
|
| 1630 | + /** |
|
| 1631 | + * set_reg_status_buttons_metabox |
|
| 1632 | + * |
|
| 1633 | + * @access protected |
|
| 1634 | + * @return string |
|
| 1635 | + * @throws \EE_Error |
|
| 1636 | + */ |
|
| 1637 | + public function set_reg_status_buttons_metabox() |
|
| 1638 | + { |
|
| 1639 | + $this->_set_registration_object(); |
|
| 1640 | + $change_reg_status_form = $this->_generate_reg_status_change_form(); |
|
| 1641 | + echo $change_reg_status_form->form_open( |
|
| 1642 | + self::add_query_args_and_nonce( |
|
| 1643 | + array( |
|
| 1644 | + 'action' => 'change_reg_status', |
|
| 1645 | + ), |
|
| 1646 | + REG_ADMIN_URL |
|
| 1647 | + ) |
|
| 1648 | + ); |
|
| 1649 | + echo $change_reg_status_form->get_html(); |
|
| 1650 | + echo $change_reg_status_form->form_close(); |
|
| 1651 | + } |
|
| 1652 | + |
|
| 1653 | + |
|
| 1654 | + |
|
| 1655 | + /** |
|
| 1656 | + * @return EE_Form_Section_Proper |
|
| 1657 | + * @throws EE_Error |
|
| 1658 | + */ |
|
| 1659 | + protected function _generate_reg_status_change_form() |
|
| 1660 | + { |
|
| 1661 | + return new EE_Form_Section_Proper(array( |
|
| 1662 | + 'name' => 'reg_status_change_form', |
|
| 1663 | + 'html_id' => 'reg-status-change-form', |
|
| 1664 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 1665 | + 'subsections' => array( |
|
| 1666 | + 'return' => new EE_Hidden_Input(array( |
|
| 1667 | + 'name' => 'return', |
|
| 1668 | + 'default' => 'view_registration', |
|
| 1669 | + )), |
|
| 1670 | + 'REG_ID' => new EE_Hidden_Input(array( |
|
| 1671 | + 'name' => 'REG_ID', |
|
| 1672 | + 'default' => $this->_registration->ID(), |
|
| 1673 | + )), |
|
| 1674 | + 'current_status' => new EE_Form_Section_HTML( |
|
| 1675 | + EEH_HTML::tr( |
|
| 1676 | + EEH_HTML::th( |
|
| 1677 | + EEH_HTML::label( |
|
| 1678 | + EEH_HTML::strong(esc_html__('Current Registration Status', 'event_espresso') |
|
| 1679 | + ) |
|
| 1680 | + ) |
|
| 1681 | + ) |
|
| 1682 | + . EEH_HTML::td( |
|
| 1683 | + EEH_HTML::strong( |
|
| 1684 | + $this->_registration->pretty_status(), |
|
| 1685 | + '', |
|
| 1686 | + 'status-' . $this->_registration->status_ID(), |
|
| 1687 | + 'line-height: 1em; font-size: 1.5em; font-weight: bold;' |
|
| 1688 | + ) |
|
| 1689 | + ) |
|
| 1690 | + ) |
|
| 1691 | + ), |
|
| 1692 | + 'reg_status' => new EE_Select_Input( |
|
| 1693 | + $this->_get_reg_statuses(), |
|
| 1694 | + array( |
|
| 1695 | + 'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'), |
|
| 1696 | + 'default' => $this->_registration->status_ID(), |
|
| 1697 | + ) |
|
| 1698 | + ), |
|
| 1699 | + 'send_notifications' => new EE_Yes_No_Input( |
|
| 1700 | + array( |
|
| 1701 | + 'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'), |
|
| 1702 | + 'default' => false, |
|
| 1703 | + 'html_help_text' => esc_html__( |
|
| 1704 | + 'If set to "Yes", then the related messages will be sent to the registrant.', |
|
| 1705 | + 'event_espresso' |
|
| 1706 | + ), |
|
| 1707 | + ) |
|
| 1708 | + ), |
|
| 1709 | + 'submit' => new EE_Submit_Input( |
|
| 1710 | + array( |
|
| 1711 | + 'html_class' => 'button-primary', |
|
| 1712 | + 'html_label_text' => ' ', |
|
| 1713 | + 'default' => esc_html__('Update Registration Status', 'event_espresso'), |
|
| 1714 | + ) |
|
| 1715 | + ), |
|
| 1716 | + ), |
|
| 1717 | + )); |
|
| 1718 | + } |
|
| 1719 | + |
|
| 1720 | + |
|
| 1721 | + /** |
|
| 1722 | + * Returns an array of all the buttons for the various statuses and switch status actions |
|
| 1723 | + * |
|
| 1724 | + * @return array |
|
| 1725 | + * @throws EE_Error |
|
| 1726 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 1727 | + */ |
|
| 1728 | + protected function _get_reg_statuses() |
|
| 1729 | + { |
|
| 1730 | + $reg_status_array = EEM_Registration::instance()->reg_status_array(); |
|
| 1731 | + unset ($reg_status_array[EEM_Registration::status_id_incomplete]); |
|
| 1732 | + // get current reg status |
|
| 1733 | + $current_status = $this->_registration->status_ID(); |
|
| 1734 | + // is registration for free event? This will determine whether to display the pending payment option |
|
| 1735 | + if ( |
|
| 1736 | + $current_status !== EEM_Registration::status_id_pending_payment |
|
| 1737 | + && $this->_registration->transaction()->is_free() |
|
| 1738 | + ) { |
|
| 1739 | + unset($reg_status_array[EEM_Registration::status_id_pending_payment]); |
|
| 1740 | + } |
|
| 1741 | + return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence'); |
|
| 1742 | + } |
|
| 1743 | + |
|
| 1744 | + |
|
| 1745 | + |
|
| 1746 | + /** |
|
| 1747 | + * This method is used when using _REG_ID from request which may or may not be an array of reg_ids. |
|
| 1748 | + * |
|
| 1749 | + * @param bool $status REG status given for changing registrations to. |
|
| 1750 | + * @param bool $notify Whether to send messages notifications or not. |
|
| 1751 | + * @return array (array with reg_id(s) updated and whether update was successful. |
|
| 1752 | + * @throws \EE_Error |
|
| 1753 | + */ |
|
| 1754 | + protected function _set_registration_status_from_request($status = false, $notify = false) |
|
| 1755 | + { |
|
| 1756 | + if (isset($this->_req_data['reg_status_change_form'])) { |
|
| 1757 | + $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID']) |
|
| 1758 | + ? (array)$this->_req_data['reg_status_change_form']['REG_ID'] : array(); |
|
| 1759 | + } else { |
|
| 1760 | + $REG_IDs = isset($this->_req_data['_REG_ID']) ? (array)$this->_req_data['_REG_ID'] : array(); |
|
| 1761 | + } |
|
| 1762 | + $success = $this->_set_registration_status($REG_IDs, $status); |
|
| 1763 | + //notify? |
|
| 1764 | + if ($success |
|
| 1765 | + && $notify |
|
| 1766 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 1767 | + 'ee_send_message', |
|
| 1768 | + 'espresso_registrations_resend_registration' |
|
| 1769 | + ) |
|
| 1770 | + ) { |
|
| 1771 | + $this->_process_resend_registration(); |
|
| 1772 | + } |
|
| 1773 | + return $success; |
|
| 1774 | + } |
|
| 1775 | + |
|
| 1776 | + |
|
| 1777 | + |
|
| 1778 | + /** |
|
| 1779 | + * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an |
|
| 1780 | + * array). Note, this method does NOT take care of possible notifications. That is required by calling code. |
|
| 1781 | + * |
|
| 1782 | + * @param array $REG_IDs |
|
| 1783 | + * @param bool $status |
|
| 1784 | + * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as |
|
| 1785 | + * @throws \RuntimeException |
|
| 1786 | + * @throws \EE_Error |
|
| 1787 | + * the array of updated registrations). |
|
| 1788 | + * @throws EE_Error |
|
| 1789 | + * @throws RuntimeException |
|
| 1790 | + */ |
|
| 1791 | + protected function _set_registration_status($REG_IDs = array(), $status = false) |
|
| 1792 | + { |
|
| 1793 | + $success = false; |
|
| 1794 | + // typecast $REG_IDs |
|
| 1795 | + $REG_IDs = (array)$REG_IDs; |
|
| 1796 | + if ( ! empty($REG_IDs)) { |
|
| 1797 | + $success = true; |
|
| 1798 | + // set default status if none is passed |
|
| 1799 | + $status = $status ? $status : EEM_Registration::status_id_pending_payment; |
|
| 1800 | + // sanitize $REG_IDs |
|
| 1801 | + $REG_IDs = array_filter($REG_IDs, 'absint'); |
|
| 1802 | + //loop through REG_ID's and change status |
|
| 1803 | + foreach ($REG_IDs as $REG_ID) { |
|
| 1804 | + $registration = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
| 1805 | + if ($registration instanceof EE_Registration) { |
|
| 1806 | + $registration->set_status($status); |
|
| 1807 | + $result = $registration->save(); |
|
| 1808 | + // verifying explicit fails because update *may* just return 0 for 0 rows affected |
|
| 1809 | + $success = $result !== false ? $success : false; |
|
| 1810 | + } |
|
| 1811 | + } |
|
| 1812 | + } |
|
| 1813 | + //reset _req_data['_REG_ID'] for any potential future messages notifications |
|
| 1814 | + $this->_req_data['_REG_ID'] = $REG_IDs; |
|
| 1815 | + //return $success and processed registrations |
|
| 1816 | + return array('REG_ID' => $REG_IDs, 'success' => $success); |
|
| 1817 | + } |
|
| 1818 | + |
|
| 1819 | + |
|
| 1820 | + /** |
|
| 1821 | + * Common logic for setting up success message and redirecting to appropriate route |
|
| 1822 | + * |
|
| 1823 | + * @param string $STS_ID status id for the registration changed to |
|
| 1824 | + * @param bool $notify indicates whether the _set_registration_status_from_request does notifications or not. |
|
| 1825 | + * @return void |
|
| 1826 | + */ |
|
| 1827 | + protected function _reg_status_change_return($STS_ID, $notify = false) |
|
| 1828 | + { |
|
| 1829 | + $result = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify) |
|
| 1830 | + : array('success' => false); |
|
| 1831 | + $success = isset($result['success']) && $result['success']; |
|
| 1832 | + //setup success message |
|
| 1833 | + if ($success) { |
|
| 1834 | + if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) { |
|
| 1835 | + $msg = sprintf(esc_html__('Registration status has been set to %s', 'event_espresso'), |
|
| 1836 | + EEH_Template::pretty_status($STS_ID, false, 'lower')); |
|
| 1837 | + } else { |
|
| 1838 | + $msg = sprintf(esc_html__('Registrations have been set to %s.', 'event_espresso'), |
|
| 1839 | + EEH_Template::pretty_status($STS_ID, false, 'lower')); |
|
| 1840 | + } |
|
| 1841 | + EE_Error::add_success($msg); |
|
| 1842 | + } else { |
|
| 1843 | + EE_Error::add_error( |
|
| 1844 | + esc_html__( |
|
| 1845 | + 'Something went wrong, and the status was not changed', |
|
| 1846 | + 'event_espresso' |
|
| 1847 | + ), __FILE__, __LINE__, __FUNCTION__ |
|
| 1848 | + ); |
|
| 1849 | + } |
|
| 1850 | + if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') { |
|
| 1851 | + $route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID'])); |
|
| 1852 | + } else { |
|
| 1853 | + $route = array('action' => 'default'); |
|
| 1854 | + } |
|
| 1855 | + //unset nonces |
|
| 1856 | + foreach ($this->_req_data as $ref => $value) { |
|
| 1857 | + if (strpos($ref, 'nonce') !== false) { |
|
| 1858 | + unset($this->_req_data[$ref]); |
|
| 1859 | + continue; |
|
| 1860 | + } |
|
| 1861 | + $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value); |
|
| 1862 | + $this->_req_data[$ref] = $value; |
|
| 1863 | + } |
|
| 1864 | + //merge request vars so that the reloaded list table contains any existing filter query params |
|
| 1865 | + $route = array_merge($this->_req_data, $route); |
|
| 1866 | + $this->_redirect_after_action($success, '', '', $route, true); |
|
| 1867 | + } |
|
| 1868 | + |
|
| 1869 | + |
|
| 1870 | + /** |
|
| 1871 | + * incoming reg status change from reg details page. |
|
| 1872 | + * |
|
| 1873 | + * @return void |
|
| 1874 | + */ |
|
| 1875 | + protected function _change_reg_status() |
|
| 1876 | + { |
|
| 1877 | + $this->_req_data['return'] = 'view_registration'; |
|
| 1878 | + //set notify based on whether the send notifications toggle is set or not |
|
| 1879 | + $notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']); |
|
| 1880 | + //$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] ); |
|
| 1881 | + $this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status']) |
|
| 1882 | + ? $this->_req_data['reg_status_change_form']['reg_status'] : ''; |
|
| 1883 | + switch ($this->_req_data['reg_status_change_form']['reg_status']) { |
|
| 1884 | + case EEM_Registration::status_id_approved : |
|
| 1885 | + case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') : |
|
| 1886 | + $this->approve_registration($notify); |
|
| 1887 | + break; |
|
| 1888 | + case EEM_Registration::status_id_pending_payment : |
|
| 1889 | + case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') : |
|
| 1890 | + $this->pending_registration($notify); |
|
| 1891 | + break; |
|
| 1892 | + case EEM_Registration::status_id_not_approved : |
|
| 1893 | + case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') : |
|
| 1894 | + $this->not_approve_registration($notify); |
|
| 1895 | + break; |
|
| 1896 | + case EEM_Registration::status_id_declined : |
|
| 1897 | + case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') : |
|
| 1898 | + $this->decline_registration($notify); |
|
| 1899 | + break; |
|
| 1900 | + case EEM_Registration::status_id_cancelled : |
|
| 1901 | + case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') : |
|
| 1902 | + $this->cancel_registration($notify); |
|
| 1903 | + break; |
|
| 1904 | + case EEM_Registration::status_id_wait_list : |
|
| 1905 | + case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') : |
|
| 1906 | + $this->wait_list_registration($notify); |
|
| 1907 | + break; |
|
| 1908 | + case EEM_Registration::status_id_incomplete : |
|
| 1909 | + default : |
|
| 1910 | + $result['success'] = false; |
|
| 1911 | + unset($this->_req_data['return']); |
|
| 1912 | + $this->_reg_status_change_return('', false); |
|
| 1913 | + break; |
|
| 1914 | + } |
|
| 1915 | + } |
|
| 1916 | + |
|
| 1917 | + |
|
| 1918 | + /** |
|
| 1919 | + * Callback for bulk action routes. |
|
| 1920 | + * Note: although we could just register the singular route callbacks for each bulk action route as well, this |
|
| 1921 | + * method was chosen so there is one central place all the registration status bulk actions are going through. |
|
| 1922 | + * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to |
|
| 1923 | + * when an action is happening on just a single registration). |
|
| 1924 | + * @param $action |
|
| 1925 | + * @param bool $notify |
|
| 1926 | + */ |
|
| 1927 | + protected function bulk_action_on_registrations($action, $notify = false) { |
|
| 1928 | + do_action( |
|
| 1929 | + 'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution', |
|
| 1930 | + $this, |
|
| 1931 | + $action, |
|
| 1932 | + $notify |
|
| 1933 | + ); |
|
| 1934 | + $method = $action . '_registration'; |
|
| 1935 | + if (method_exists($this, $method)) { |
|
| 1936 | + $this->$method($notify); |
|
| 1937 | + } |
|
| 1938 | + } |
|
| 1939 | + |
|
| 1940 | + |
|
| 1941 | + /** |
|
| 1942 | + * approve_registration |
|
| 1943 | + * |
|
| 1944 | + * @access protected |
|
| 1945 | + * @param bool $notify whether or not to notify the registrant about their approval. |
|
| 1946 | + * @return void |
|
| 1947 | + */ |
|
| 1948 | + protected function approve_registration($notify = false) |
|
| 1949 | + { |
|
| 1950 | + $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify); |
|
| 1951 | + } |
|
| 1952 | + |
|
| 1953 | + |
|
| 1954 | + /** |
|
| 1955 | + * decline_registration |
|
| 1956 | + * |
|
| 1957 | + * @access protected |
|
| 1958 | + * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1959 | + * @return void |
|
| 1960 | + */ |
|
| 1961 | + protected function decline_registration($notify = false) |
|
| 1962 | + { |
|
| 1963 | + $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify); |
|
| 1964 | + } |
|
| 1965 | + |
|
| 1966 | + |
|
| 1967 | + /** |
|
| 1968 | + * cancel_registration |
|
| 1969 | + * |
|
| 1970 | + * @access protected |
|
| 1971 | + * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1972 | + * @return void |
|
| 1973 | + */ |
|
| 1974 | + protected function cancel_registration($notify = false) |
|
| 1975 | + { |
|
| 1976 | + $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify); |
|
| 1977 | + } |
|
| 1978 | + |
|
| 1979 | + |
|
| 1980 | + /** |
|
| 1981 | + * not_approve_registration |
|
| 1982 | + * |
|
| 1983 | + * @access protected |
|
| 1984 | + * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1985 | + * @return void |
|
| 1986 | + */ |
|
| 1987 | + protected function not_approve_registration($notify = false) |
|
| 1988 | + { |
|
| 1989 | + $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify); |
|
| 1990 | + } |
|
| 1991 | + |
|
| 1992 | + |
|
| 1993 | + /** |
|
| 1994 | + * decline_registration |
|
| 1995 | + * |
|
| 1996 | + * @access protected |
|
| 1997 | + * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1998 | + * @return void |
|
| 1999 | + */ |
|
| 2000 | + protected function pending_registration($notify = false) |
|
| 2001 | + { |
|
| 2002 | + $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify); |
|
| 2003 | + } |
|
| 2004 | + |
|
| 2005 | + |
|
| 2006 | + /** |
|
| 2007 | + * waitlist_registration |
|
| 2008 | + * |
|
| 2009 | + * @access protected |
|
| 2010 | + * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 2011 | + * @return void |
|
| 2012 | + */ |
|
| 2013 | + protected function wait_list_registration($notify = false) |
|
| 2014 | + { |
|
| 2015 | + $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify); |
|
| 2016 | + } |
|
| 2017 | + |
|
| 2018 | + |
|
| 2019 | + /** |
|
| 2020 | + * generates HTML for the Registration main meta box |
|
| 2021 | + * |
|
| 2022 | + * @access public |
|
| 2023 | + * @return void |
|
| 2024 | + * @throws DomainException |
|
| 2025 | + * @throws EE_Error |
|
| 2026 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 2027 | + */ |
|
| 2028 | + public function _reg_details_meta_box() |
|
| 2029 | + { |
|
| 2030 | + EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 2031 | + EEH_Autoloader::register_line_item_filter_autoloaders(); |
|
| 2032 | + EE_Registry::instance()->load_helper('Line_Item'); |
|
| 2033 | + $transaction = $this->_registration->transaction() ? $this->_registration->transaction() |
|
| 2034 | + : EE_Transaction::new_instance(); |
|
| 2035 | + $this->_session = $transaction->session_data(); |
|
| 2036 | + $filters = new EE_Line_Item_Filter_Collection(); |
|
| 2037 | + //$filters->add( new EE_Non_Zero_Line_Item_Filter() ); |
|
| 2038 | + $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration)); |
|
| 2039 | + $line_item_filter_processor = new EE_Line_Item_Filter_Processor($filters, |
|
| 2040 | + $transaction->total_line_item()); |
|
| 2041 | + $filtered_line_item_tree = $line_item_filter_processor->process(); |
|
| 2042 | + $line_item_display = new EE_Line_Item_Display('reg_admin_table', |
|
| 2043 | + 'EE_Admin_Table_Registration_Line_Item_Display_Strategy'); |
|
| 2044 | + $this->_template_args['line_item_table'] = $line_item_display->display_line_item( |
|
| 2045 | + $filtered_line_item_tree, |
|
| 2046 | + array('EE_Registration' => $this->_registration) |
|
| 2047 | + ); |
|
| 2048 | + $attendee = $this->_registration->attendee(); |
|
| 2049 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 2050 | + 'ee_read_transaction', |
|
| 2051 | + 'espresso_transactions_view_transaction' |
|
| 2052 | + )) { |
|
| 2053 | + $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link( |
|
| 2054 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 2055 | + array( |
|
| 2056 | + 'action' => 'view_transaction', |
|
| 2057 | + 'TXN_ID' => $transaction->ID(), |
|
| 2058 | + ), |
|
| 2059 | + TXN_ADMIN_URL |
|
| 2060 | + ), |
|
| 2061 | + esc_html__(' View Transaction', 'event_espresso'), |
|
| 2062 | + 'button secondary-button right', |
|
| 2063 | + 'dashicons dashicons-cart' |
|
| 2064 | + ); |
|
| 2065 | + } else { |
|
| 2066 | + $this->_template_args['view_transaction_button'] = ''; |
|
| 2067 | + } |
|
| 2068 | + if ($attendee instanceof EE_Attendee |
|
| 2069 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 2070 | + 'ee_send_message', |
|
| 2071 | + 'espresso_registrations_resend_registration' |
|
| 2072 | + ) |
|
| 2073 | + ) { |
|
| 2074 | + $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link( |
|
| 2075 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 2076 | + array( |
|
| 2077 | + 'action' => 'resend_registration', |
|
| 2078 | + '_REG_ID' => $this->_registration->ID(), |
|
| 2079 | + 'redirect_to' => 'view_registration', |
|
| 2080 | + ), |
|
| 2081 | + REG_ADMIN_URL |
|
| 2082 | + ), |
|
| 2083 | + esc_html__(' Resend Registration', 'event_espresso'), |
|
| 2084 | + 'button secondary-button right', |
|
| 2085 | + 'dashicons dashicons-email-alt' |
|
| 2086 | + ); |
|
| 2087 | + } else { |
|
| 2088 | + $this->_template_args['resend_registration_button'] = ''; |
|
| 2089 | + } |
|
| 2090 | + $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 2091 | + $payment = $transaction->get_first_related('Payment'); |
|
| 2092 | + $payment = ! $payment instanceof EE_Payment |
|
| 2093 | + ? EE_Payment::new_instance() |
|
| 2094 | + : $payment; |
|
| 2095 | + $payment_method = $payment->get_first_related('Payment_Method'); |
|
| 2096 | + $payment_method = ! $payment_method instanceof EE_Payment_Method |
|
| 2097 | + ? EE_Payment_Method::new_instance() |
|
| 2098 | + : $payment_method; |
|
| 2099 | + $reg_details = array( |
|
| 2100 | + 'payment_method' => $payment_method->name(), |
|
| 2101 | + 'response_msg' => $payment->gateway_response(), |
|
| 2102 | + 'registration_id' => $this->_registration->get('REG_code'), |
|
| 2103 | + 'registration_session' => $this->_registration->session_ID(), |
|
| 2104 | + 'ip_address' => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '', |
|
| 2105 | + 'user_agent' => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '', |
|
| 2106 | + ); |
|
| 2107 | + if (isset($reg_details['registration_id'])) { |
|
| 2108 | + $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id']; |
|
| 2109 | + $this->_template_args['reg_details']['registration_id']['label'] = esc_html__( |
|
| 2110 | + 'Registration ID', |
|
| 2111 | + 'event_espresso' |
|
| 2112 | + ); |
|
| 2113 | + $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text'; |
|
| 2114 | + } |
|
| 2115 | + if (isset($reg_details['payment_method'])) { |
|
| 2116 | + $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method']; |
|
| 2117 | + $this->_template_args['reg_details']['payment_method']['label'] = esc_html__( |
|
| 2118 | + 'Most Recent Payment Method', |
|
| 2119 | + 'event_espresso' |
|
| 2120 | + ); |
|
| 2121 | + $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text'; |
|
| 2122 | + $this->_template_args['reg_details']['response_msg']['value'] = $reg_details['response_msg']; |
|
| 2123 | + $this->_template_args['reg_details']['response_msg']['label'] = esc_html__( |
|
| 2124 | + 'Payment method response', |
|
| 2125 | + 'event_espresso' |
|
| 2126 | + ); |
|
| 2127 | + $this->_template_args['reg_details']['response_msg']['class'] = 'regular-text'; |
|
| 2128 | + } |
|
| 2129 | + $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session']; |
|
| 2130 | + $this->_template_args['reg_details']['registration_session']['label'] = esc_html__( |
|
| 2131 | + 'Registration Session', |
|
| 2132 | + 'event_espresso' |
|
| 2133 | + ); |
|
| 2134 | + $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text'; |
|
| 2135 | + $this->_template_args['reg_details']['ip_address']['value'] = $reg_details['ip_address']; |
|
| 2136 | + $this->_template_args['reg_details']['ip_address']['label'] = esc_html__( |
|
| 2137 | + 'Registration placed from IP', |
|
| 2138 | + 'event_espresso' |
|
| 2139 | + ); |
|
| 2140 | + $this->_template_args['reg_details']['ip_address']['class'] = 'regular-text'; |
|
| 2141 | + $this->_template_args['reg_details']['user_agent']['value'] = $reg_details['user_agent']; |
|
| 2142 | + $this->_template_args['reg_details']['user_agent']['label'] = esc_html__('Registrant User Agent', |
|
| 2143 | + 'event_espresso'); |
|
| 2144 | + $this->_template_args['reg_details']['user_agent']['class'] = 'large-text'; |
|
| 2145 | + $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2146 | + array( |
|
| 2147 | + 'action' => 'default', |
|
| 2148 | + 'event_id' => $this->_registration->event_ID(), |
|
| 2149 | + ), |
|
| 2150 | + REG_ADMIN_URL |
|
| 2151 | + ); |
|
| 2152 | + $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
| 2153 | + $this->_template_args['event_id'] = $this->_registration->event_ID(); |
|
| 2154 | + $template_path = |
|
| 2155 | + REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php'; |
|
| 2156 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2157 | + } |
|
| 2158 | + |
|
| 2159 | + |
|
| 2160 | + /** |
|
| 2161 | + * generates HTML for the Registration Questions meta box. |
|
| 2162 | + * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters), |
|
| 2163 | + * otherwise uses new forms system |
|
| 2164 | + * |
|
| 2165 | + * @access public |
|
| 2166 | + * @return void |
|
| 2167 | + * @throws DomainException |
|
| 2168 | + * @throws EE_Error |
|
| 2169 | + */ |
|
| 2170 | + public function _reg_questions_meta_box() |
|
| 2171 | + { |
|
| 2172 | + //allow someone to override this method entirely |
|
| 2173 | + if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this, |
|
| 2174 | + $this->_registration)) { |
|
| 2175 | + $form = $this->_get_reg_custom_questions_form( |
|
| 2176 | + $this->_registration->ID() |
|
| 2177 | + ); |
|
| 2178 | + $this->_template_args['att_questions'] = count($form->subforms()) > 0 |
|
| 2179 | + ? $form->get_html_and_js() |
|
| 2180 | + : ''; |
|
| 2181 | + $this->_template_args['reg_questions_form_action'] = 'edit_registration'; |
|
| 2182 | + $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
| 2183 | + $template_path = |
|
| 2184 | + REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php'; |
|
| 2185 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2186 | + } |
|
| 2187 | + } |
|
| 2188 | + |
|
| 2189 | + |
|
| 2190 | + /** |
|
| 2191 | + * form_before_question_group |
|
| 2192 | + * |
|
| 2193 | + * @deprecated as of 4.8.32.rc.000 |
|
| 2194 | + * @access public |
|
| 2195 | + * @param string $output |
|
| 2196 | + * @return string |
|
| 2197 | + */ |
|
| 2198 | + public function form_before_question_group($output) |
|
| 2199 | + { |
|
| 2200 | + EE_Error::doing_it_wrong( |
|
| 2201 | + __CLASS__ . '::' . __FUNCTION__, |
|
| 2202 | + esc_html__( |
|
| 2203 | + 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
|
| 2204 | + 'event_espresso' |
|
| 2205 | + ), |
|
| 2206 | + '4.8.32.rc.000' |
|
| 2207 | + ); |
|
| 2208 | + return ' |
|
| 2209 | 2209 | <table class="form-table ee-width-100"> |
| 2210 | 2210 | <tbody> |
| 2211 | 2211 | '; |
| 2212 | - } |
|
| 2213 | - |
|
| 2214 | - |
|
| 2215 | - /** |
|
| 2216 | - * form_after_question_group |
|
| 2217 | - * |
|
| 2218 | - * @deprecated as of 4.8.32.rc.000 |
|
| 2219 | - * @access public |
|
| 2220 | - * @param string $output |
|
| 2221 | - * @return string |
|
| 2222 | - */ |
|
| 2223 | - public function form_after_question_group($output) |
|
| 2224 | - { |
|
| 2225 | - EE_Error::doing_it_wrong( |
|
| 2226 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 2227 | - esc_html__( |
|
| 2228 | - 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
|
| 2229 | - 'event_espresso' |
|
| 2230 | - ), |
|
| 2231 | - '4.8.32.rc.000' |
|
| 2232 | - ); |
|
| 2233 | - return ' |
|
| 2212 | + } |
|
| 2213 | + |
|
| 2214 | + |
|
| 2215 | + /** |
|
| 2216 | + * form_after_question_group |
|
| 2217 | + * |
|
| 2218 | + * @deprecated as of 4.8.32.rc.000 |
|
| 2219 | + * @access public |
|
| 2220 | + * @param string $output |
|
| 2221 | + * @return string |
|
| 2222 | + */ |
|
| 2223 | + public function form_after_question_group($output) |
|
| 2224 | + { |
|
| 2225 | + EE_Error::doing_it_wrong( |
|
| 2226 | + __CLASS__ . '::' . __FUNCTION__, |
|
| 2227 | + esc_html__( |
|
| 2228 | + 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
|
| 2229 | + 'event_espresso' |
|
| 2230 | + ), |
|
| 2231 | + '4.8.32.rc.000' |
|
| 2232 | + ); |
|
| 2233 | + return ' |
|
| 2234 | 2234 | <tr class="hide-if-no-js"> |
| 2235 | 2235 | <th> </th> |
| 2236 | 2236 | <td class="reg-admin-edit-attendee-question-td"> |
| 2237 | 2237 | <a class="reg-admin-edit-attendee-question-lnk" href="#" title="' |
| 2238 | - . esc_attr__('click to edit question', 'event_espresso') |
|
| 2239 | - . '"> |
|
| 2238 | + . esc_attr__('click to edit question', 'event_espresso') |
|
| 2239 | + . '"> |
|
| 2240 | 2240 | <span class="reg-admin-edit-question-group-spn lt-grey-txt">' |
| 2241 | - . esc_html__('edit the above question group', 'event_espresso') |
|
| 2242 | - . '</span> |
|
| 2241 | + . esc_html__('edit the above question group', 'event_espresso') |
|
| 2242 | + . '</span> |
|
| 2243 | 2243 | <div class="dashicons dashicons-edit"></div> |
| 2244 | 2244 | </a> |
| 2245 | 2245 | </td> |
@@ -2247,558 +2247,558 @@ discard block |
||
| 2247 | 2247 | </tbody> |
| 2248 | 2248 | </table> |
| 2249 | 2249 | '; |
| 2250 | - } |
|
| 2251 | - |
|
| 2252 | - |
|
| 2253 | - /** |
|
| 2254 | - * form_form_field_label_wrap |
|
| 2255 | - * |
|
| 2256 | - * @deprecated as of 4.8.32.rc.000 |
|
| 2257 | - * @access public |
|
| 2258 | - * @param string $label |
|
| 2259 | - * @return string |
|
| 2260 | - */ |
|
| 2261 | - public function form_form_field_label_wrap($label) |
|
| 2262 | - { |
|
| 2263 | - EE_Error::doing_it_wrong( |
|
| 2264 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 2265 | - esc_html__( |
|
| 2266 | - 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
|
| 2267 | - 'event_espresso' |
|
| 2268 | - ), |
|
| 2269 | - '4.8.32.rc.000' |
|
| 2270 | - ); |
|
| 2271 | - return ' |
|
| 2250 | + } |
|
| 2251 | + |
|
| 2252 | + |
|
| 2253 | + /** |
|
| 2254 | + * form_form_field_label_wrap |
|
| 2255 | + * |
|
| 2256 | + * @deprecated as of 4.8.32.rc.000 |
|
| 2257 | + * @access public |
|
| 2258 | + * @param string $label |
|
| 2259 | + * @return string |
|
| 2260 | + */ |
|
| 2261 | + public function form_form_field_label_wrap($label) |
|
| 2262 | + { |
|
| 2263 | + EE_Error::doing_it_wrong( |
|
| 2264 | + __CLASS__ . '::' . __FUNCTION__, |
|
| 2265 | + esc_html__( |
|
| 2266 | + 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
|
| 2267 | + 'event_espresso' |
|
| 2268 | + ), |
|
| 2269 | + '4.8.32.rc.000' |
|
| 2270 | + ); |
|
| 2271 | + return ' |
|
| 2272 | 2272 | <tr> |
| 2273 | 2273 | <th> |
| 2274 | 2274 | ' . $label . ' |
| 2275 | 2275 | </th>'; |
| 2276 | - } |
|
| 2277 | - |
|
| 2278 | - |
|
| 2279 | - /** |
|
| 2280 | - * form_form_field_input__wrap |
|
| 2281 | - * |
|
| 2282 | - * @deprecated as of 4.8.32.rc.000 |
|
| 2283 | - * @access public |
|
| 2284 | - * @param string $input |
|
| 2285 | - * @return string |
|
| 2286 | - */ |
|
| 2287 | - public function form_form_field_input__wrap($input) |
|
| 2288 | - { |
|
| 2289 | - EE_Error::doing_it_wrong( |
|
| 2290 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 2291 | - esc_html__( |
|
| 2292 | - 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
|
| 2293 | - 'event_espresso' |
|
| 2294 | - ), |
|
| 2295 | - '4.8.32.rc.000' |
|
| 2296 | - ); |
|
| 2297 | - return ' |
|
| 2276 | + } |
|
| 2277 | + |
|
| 2278 | + |
|
| 2279 | + /** |
|
| 2280 | + * form_form_field_input__wrap |
|
| 2281 | + * |
|
| 2282 | + * @deprecated as of 4.8.32.rc.000 |
|
| 2283 | + * @access public |
|
| 2284 | + * @param string $input |
|
| 2285 | + * @return string |
|
| 2286 | + */ |
|
| 2287 | + public function form_form_field_input__wrap($input) |
|
| 2288 | + { |
|
| 2289 | + EE_Error::doing_it_wrong( |
|
| 2290 | + __CLASS__ . '::' . __FUNCTION__, |
|
| 2291 | + esc_html__( |
|
| 2292 | + 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
|
| 2293 | + 'event_espresso' |
|
| 2294 | + ), |
|
| 2295 | + '4.8.32.rc.000' |
|
| 2296 | + ); |
|
| 2297 | + return ' |
|
| 2298 | 2298 | <td class="reg-admin-attendee-questions-input-td disabled-input"> |
| 2299 | 2299 | ' . $input . ' |
| 2300 | 2300 | </td> |
| 2301 | 2301 | </tr>'; |
| 2302 | - } |
|
| 2303 | - |
|
| 2304 | - |
|
| 2305 | - /** |
|
| 2306 | - * Updates the registration's custom questions according to the form info, if the form is submitted. |
|
| 2307 | - * If it's not a post, the "view_registrations" route will be called next on the SAME request |
|
| 2308 | - * to display the page |
|
| 2309 | - * |
|
| 2310 | - * @access protected |
|
| 2311 | - * @return void |
|
| 2312 | - * @throws EE_Error |
|
| 2313 | - */ |
|
| 2314 | - protected function _update_attendee_registration_form() |
|
| 2315 | - { |
|
| 2316 | - do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this); |
|
| 2317 | - if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
| 2318 | - $REG_ID = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false; |
|
| 2319 | - $success = $this->_save_reg_custom_questions_form($REG_ID); |
|
| 2320 | - if ($success) { |
|
| 2321 | - $what = esc_html__('Registration Form', 'event_espresso'); |
|
| 2322 | - $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID) |
|
| 2323 | - : array('action' => 'default'); |
|
| 2324 | - $this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route); |
|
| 2325 | - } |
|
| 2326 | - } |
|
| 2327 | - } |
|
| 2328 | - |
|
| 2329 | - |
|
| 2330 | - /** |
|
| 2331 | - * Gets the form for saving registrations custom questions (if done |
|
| 2332 | - * previously retrieves the cached form object, which may have validation errors in it) |
|
| 2333 | - * |
|
| 2334 | - * @param int $REG_ID |
|
| 2335 | - * @return EE_Registration_Custom_Questions_Form |
|
| 2336 | - * @throws EE_Error |
|
| 2337 | - */ |
|
| 2338 | - protected function _get_reg_custom_questions_form($REG_ID) |
|
| 2339 | - { |
|
| 2340 | - if ( ! $this->_reg_custom_questions_form) { |
|
| 2341 | - require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php'); |
|
| 2342 | - $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form( |
|
| 2343 | - EEM_Registration::instance()->get_one_by_ID($REG_ID) |
|
| 2344 | - ); |
|
| 2345 | - $this->_reg_custom_questions_form->_construct_finalize(null, null); |
|
| 2346 | - } |
|
| 2347 | - return $this->_reg_custom_questions_form; |
|
| 2348 | - } |
|
| 2349 | - |
|
| 2350 | - |
|
| 2351 | - /** |
|
| 2352 | - * Saves |
|
| 2353 | - * |
|
| 2354 | - * @access private |
|
| 2355 | - * @param bool $REG_ID |
|
| 2356 | - * @return bool |
|
| 2357 | - * @throws EE_Error |
|
| 2358 | - */ |
|
| 2359 | - private function _save_reg_custom_questions_form($REG_ID = false) |
|
| 2360 | - { |
|
| 2361 | - if ( ! $REG_ID) { |
|
| 2362 | - EE_Error::add_error( |
|
| 2363 | - esc_html__( |
|
| 2364 | - 'An error occurred. No registration ID was received.', 'event_espresso'), |
|
| 2365 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2366 | - ); |
|
| 2367 | - } |
|
| 2368 | - $form = $this->_get_reg_custom_questions_form($REG_ID); |
|
| 2369 | - $form->receive_form_submission($this->_req_data); |
|
| 2370 | - $success = false; |
|
| 2371 | - if ($form->is_valid()) { |
|
| 2372 | - foreach ($form->subforms() as $question_group_id => $question_group_form) { |
|
| 2373 | - foreach ($question_group_form->inputs() as $question_id => $input) { |
|
| 2374 | - $where_conditions = array( |
|
| 2375 | - 'QST_ID' => $question_id, |
|
| 2376 | - 'REG_ID' => $REG_ID, |
|
| 2377 | - ); |
|
| 2378 | - $possibly_new_values = array( |
|
| 2379 | - 'ANS_value' => $input->normalized_value(), |
|
| 2380 | - ); |
|
| 2381 | - $answer = EEM_Answer::instance()->get_one(array($where_conditions)); |
|
| 2382 | - if ($answer instanceof EE_Answer) { |
|
| 2383 | - $success = $answer->save($possibly_new_values); |
|
| 2384 | - } else { |
|
| 2385 | - //insert it then |
|
| 2386 | - $cols_n_vals = array_merge($where_conditions, $possibly_new_values); |
|
| 2387 | - $answer = EE_Answer::new_instance($cols_n_vals); |
|
| 2388 | - $success = $answer->save(); |
|
| 2389 | - } |
|
| 2390 | - } |
|
| 2391 | - } |
|
| 2392 | - } else { |
|
| 2393 | - EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__); |
|
| 2394 | - } |
|
| 2395 | - return $success; |
|
| 2396 | - } |
|
| 2397 | - |
|
| 2398 | - |
|
| 2399 | - /** |
|
| 2400 | - * generates HTML for the Registration main meta box |
|
| 2401 | - * |
|
| 2402 | - * @access public |
|
| 2403 | - * @return void |
|
| 2404 | - * @throws DomainException |
|
| 2405 | - * @throws EE_Error |
|
| 2406 | - */ |
|
| 2407 | - public function _reg_attendees_meta_box() |
|
| 2408 | - { |
|
| 2409 | - $REG = EEM_Registration::instance(); |
|
| 2410 | - //get all other registrations on this transaction, and cache |
|
| 2411 | - //the attendees for them so we don't have to run another query using force_join |
|
| 2412 | - $registrations = $REG->get_all(array( |
|
| 2413 | - array( |
|
| 2414 | - 'TXN_ID' => $this->_registration->transaction_ID(), |
|
| 2415 | - 'REG_ID' => array('!=', $this->_registration->ID()), |
|
| 2416 | - ), |
|
| 2417 | - 'force_join' => array('Attendee'), |
|
| 2418 | - )); |
|
| 2419 | - $this->_template_args['attendees'] = array(); |
|
| 2420 | - $this->_template_args['attendee_notice'] = ''; |
|
| 2421 | - if (empty($registrations) |
|
| 2422 | - || (is_array($registrations) |
|
| 2423 | - && ! EEH_Array::get_one_item_from_array($registrations)) |
|
| 2424 | - ) { |
|
| 2425 | - EE_Error::add_error( |
|
| 2426 | - esc_html__( |
|
| 2427 | - 'There are no records attached to this registration. Something may have gone wrong with the registration', |
|
| 2428 | - 'event_espresso' |
|
| 2429 | - ), __FILE__, __FUNCTION__, __LINE__ |
|
| 2430 | - ); |
|
| 2431 | - $this->_template_args['attendee_notice'] = EE_Error::get_notices(); |
|
| 2432 | - } else { |
|
| 2433 | - $att_nmbr = 1; |
|
| 2434 | - foreach ($registrations as $registration) { |
|
| 2435 | - /* @var $registration EE_Registration */ |
|
| 2436 | - $attendee = $registration->attendee() |
|
| 2437 | - ? $registration->attendee() |
|
| 2438 | - : EEM_Attendee::instance() |
|
| 2439 | - ->create_default_object(); |
|
| 2440 | - $this->_template_args['attendees'][$att_nmbr]['STS_ID'] = $registration->status_ID(); |
|
| 2441 | - $this->_template_args['attendees'][$att_nmbr]['fname'] = $attendee->fname(); |
|
| 2442 | - $this->_template_args['attendees'][$att_nmbr]['lname'] = $attendee->lname(); |
|
| 2443 | - $this->_template_args['attendees'][$att_nmbr]['email'] = $attendee->email(); |
|
| 2444 | - $this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price(); |
|
| 2445 | - $this->_template_args['attendees'][$att_nmbr]['address'] = implode( |
|
| 2446 | - ', ', |
|
| 2447 | - $attendee->full_address_as_array() |
|
| 2448 | - ); |
|
| 2449 | - $this->_template_args['attendees'][$att_nmbr]['att_link'] = self::add_query_args_and_nonce( |
|
| 2450 | - array( |
|
| 2451 | - 'action' => 'edit_attendee', |
|
| 2452 | - 'post' => $attendee->ID(), |
|
| 2453 | - ), |
|
| 2454 | - REG_ADMIN_URL |
|
| 2455 | - ); |
|
| 2456 | - $this->_template_args['attendees'][$att_nmbr]['event_name'] = $registration->event_obj()->name(); |
|
| 2457 | - $att_nmbr++; |
|
| 2458 | - } |
|
| 2459 | - $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 2460 | - } |
|
| 2461 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php'; |
|
| 2462 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2463 | - } |
|
| 2464 | - |
|
| 2465 | - |
|
| 2466 | - /** |
|
| 2467 | - * generates HTML for the Edit Registration side meta box |
|
| 2468 | - * |
|
| 2469 | - * @access public |
|
| 2470 | - * @return void |
|
| 2471 | - * @throws DomainException |
|
| 2472 | - * @throws EE_Error |
|
| 2473 | - */ |
|
| 2474 | - public function _reg_registrant_side_meta_box() |
|
| 2475 | - { |
|
| 2476 | - /*@var $attendee EE_Attendee */ |
|
| 2477 | - $att_check = $this->_registration->attendee(); |
|
| 2478 | - $attendee = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object(); |
|
| 2479 | - //now let's determine if this is not the primary registration. If it isn't then we set the |
|
| 2480 | - //primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the |
|
| 2481 | - //primary registration object (that way we know if we need to show create button or not) |
|
| 2482 | - if ( ! $this->_registration->is_primary_registrant()) { |
|
| 2483 | - $primary_registration = $this->_registration->get_primary_registration(); |
|
| 2484 | - $primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() |
|
| 2485 | - : null; |
|
| 2486 | - if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) { |
|
| 2487 | - //in here? This means the displayed registration is not the primary registrant but ALREADY HAS its own |
|
| 2488 | - //custom attendee object so let's not worry about the primary reg. |
|
| 2489 | - $primary_registration = null; |
|
| 2490 | - } |
|
| 2491 | - } else { |
|
| 2492 | - $primary_registration = null; |
|
| 2493 | - } |
|
| 2494 | - $this->_template_args['ATT_ID'] = $attendee->ID(); |
|
| 2495 | - $this->_template_args['fname'] = $attendee->fname(); |
|
| 2496 | - $this->_template_args['lname'] = $attendee->lname(); |
|
| 2497 | - $this->_template_args['email'] = $attendee->email(); |
|
| 2498 | - $this->_template_args['phone'] = $attendee->phone(); |
|
| 2499 | - $this->_template_args['formatted_address'] = EEH_Address::format($attendee); |
|
| 2500 | - //edit link |
|
| 2501 | - $this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 2502 | - 'action' => 'edit_attendee', |
|
| 2503 | - 'post' => $attendee->ID(), |
|
| 2504 | - ), REG_ADMIN_URL); |
|
| 2505 | - $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso'); |
|
| 2506 | - //create link |
|
| 2507 | - $this->_template_args['create_link'] = $primary_registration instanceof EE_Registration |
|
| 2508 | - ? EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 2509 | - 'action' => 'duplicate_attendee', |
|
| 2510 | - '_REG_ID' => $this->_registration->ID(), |
|
| 2511 | - ), REG_ADMIN_URL) : ''; |
|
| 2512 | - $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso'); |
|
| 2513 | - $this->_template_args['att_check'] = $att_check; |
|
| 2514 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php'; |
|
| 2515 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2516 | - } |
|
| 2517 | - |
|
| 2518 | - |
|
| 2519 | - /** |
|
| 2520 | - * trash or restore registrations |
|
| 2521 | - * |
|
| 2522 | - * @param boolean $trash whether to archive or restore |
|
| 2523 | - * @return void |
|
| 2524 | - * @throws EE_Error |
|
| 2525 | - * @throws RuntimeException |
|
| 2526 | - * @access protected |
|
| 2527 | - */ |
|
| 2528 | - protected function _trash_or_restore_registrations($trash = true) |
|
| 2529 | - { |
|
| 2530 | - //if empty _REG_ID then get out because there's nothing to do |
|
| 2531 | - if (empty($this->_req_data['_REG_ID'])) { |
|
| 2532 | - EE_Error::add_error( |
|
| 2533 | - sprintf( |
|
| 2534 | - esc_html__( |
|
| 2535 | - 'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.', |
|
| 2536 | - 'event_espresso' |
|
| 2537 | - ), |
|
| 2538 | - $trash ? 'trash' : 'restore' |
|
| 2539 | - ), |
|
| 2540 | - __FILE__, __LINE__, __FUNCTION__ |
|
| 2541 | - ); |
|
| 2542 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 2543 | - } |
|
| 2544 | - $success = 0; |
|
| 2545 | - $overwrite_msgs = false; |
|
| 2546 | - //Checkboxes |
|
| 2547 | - if ( ! is_array($this->_req_data['_REG_ID'])) { |
|
| 2548 | - $this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']); |
|
| 2549 | - } |
|
| 2550 | - $reg_count = count($this->_req_data['_REG_ID']); |
|
| 2551 | - // cycle thru checkboxes |
|
| 2552 | - foreach ($this->_req_data['_REG_ID'] as $REG_ID) { |
|
| 2553 | - /** @var EE_Registration $REG */ |
|
| 2554 | - $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
| 2555 | - $payments = $REG->registration_payments(); |
|
| 2556 | - if (! empty($payments)) { |
|
| 2557 | - $name = $REG->attendee() instanceof EE_Attendee |
|
| 2558 | - ? $REG->attendee()->full_name() |
|
| 2559 | - : esc_html__('Unknown Attendee', 'event_espresso'); |
|
| 2560 | - $overwrite_msgs = true; |
|
| 2561 | - EE_Error::add_error( |
|
| 2562 | - sprintf( |
|
| 2563 | - esc_html__( |
|
| 2564 | - 'The registration for %s could not be trashed because it has payments attached to the related transaction. If you wish to trash this registration you must first delete the payments on the related transaction.', |
|
| 2565 | - 'event_espresso' |
|
| 2566 | - ), |
|
| 2567 | - $name |
|
| 2568 | - ), |
|
| 2569 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2570 | - ); |
|
| 2571 | - //can't trash this registration because it has payments. |
|
| 2572 | - continue; |
|
| 2573 | - } |
|
| 2574 | - $updated = $trash ? $REG->delete() : $REG->restore(); |
|
| 2575 | - if ($updated) { |
|
| 2576 | - $success++; |
|
| 2577 | - } |
|
| 2578 | - } |
|
| 2579 | - $this->_redirect_after_action( |
|
| 2580 | - $success === $reg_count, // were ALL registrations affected? |
|
| 2581 | - $success > 1 |
|
| 2582 | - ? esc_html__('Registrations', 'event_espresso') |
|
| 2583 | - : esc_html__('Registration', 'event_espresso'), |
|
| 2584 | - $trash |
|
| 2585 | - ? esc_html__('moved to the trash', 'event_espresso') |
|
| 2586 | - : esc_html__('restored', 'event_espresso'), |
|
| 2587 | - array('action' => 'default'), |
|
| 2588 | - $overwrite_msgs |
|
| 2589 | - ); |
|
| 2590 | - } |
|
| 2591 | - |
|
| 2592 | - |
|
| 2593 | - /** |
|
| 2594 | - * This is used to permanently delete registrations. Note, this will handle not only deleting permanently the |
|
| 2595 | - * registration but also. |
|
| 2596 | - * 1. Removing relations to EE_Attendee |
|
| 2597 | - * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are |
|
| 2598 | - * ALSO trashed. |
|
| 2599 | - * 3. Deleting permanently any related Line items but only if the above conditions are met. |
|
| 2600 | - * 4. Removing relationships between all tickets and the related registrations |
|
| 2601 | - * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.) |
|
| 2602 | - * 6. Deleting permanently any related Checkins. |
|
| 2603 | - * |
|
| 2604 | - * @return void |
|
| 2605 | - * @throws EE_Error |
|
| 2606 | - */ |
|
| 2607 | - protected function _delete_registrations() |
|
| 2608 | - { |
|
| 2609 | - $REG_MDL = EEM_Registration::instance(); |
|
| 2610 | - $success = 1; |
|
| 2611 | - //Checkboxes |
|
| 2612 | - if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) { |
|
| 2613 | - // if array has more than one element than success message should be plural |
|
| 2614 | - $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1; |
|
| 2615 | - // cycle thru checkboxes |
|
| 2616 | - while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) { |
|
| 2617 | - $REG = $REG_MDL->get_one_by_ID($REG_ID); |
|
| 2618 | - if ( ! $REG instanceof EE_Registration) { |
|
| 2619 | - continue; |
|
| 2620 | - } |
|
| 2621 | - $deleted = $this->_delete_registration($REG); |
|
| 2622 | - if ( ! $deleted) { |
|
| 2623 | - $success = 0; |
|
| 2624 | - } |
|
| 2625 | - } |
|
| 2626 | - } else { |
|
| 2627 | - // grab single id and delete |
|
| 2628 | - $REG_ID = $this->_req_data['_REG_ID']; |
|
| 2629 | - $REG = $REG_MDL->get_one_by_ID($REG_ID); |
|
| 2630 | - $deleted = $this->_delete_registration($REG); |
|
| 2631 | - if ( ! $deleted) { |
|
| 2632 | - $success = 0; |
|
| 2633 | - } |
|
| 2634 | - } |
|
| 2635 | - $what = $success > 1 |
|
| 2636 | - ? esc_html__('Registrations', 'event_espresso') |
|
| 2637 | - : esc_html__('Registration', 'event_espresso'); |
|
| 2638 | - $action_desc = esc_html__('permanently deleted.', 'event_espresso'); |
|
| 2639 | - $this->_redirect_after_action( |
|
| 2640 | - $success, |
|
| 2641 | - $what, |
|
| 2642 | - $action_desc, |
|
| 2643 | - array('action' => 'default'), |
|
| 2644 | - true |
|
| 2645 | - ); |
|
| 2646 | - } |
|
| 2647 | - |
|
| 2648 | - |
|
| 2649 | - /** |
|
| 2650 | - * handles the permanent deletion of a registration. See comments with _delete_registrations() for details on what |
|
| 2651 | - * models get affected. |
|
| 2652 | - * |
|
| 2653 | - * @param EE_Registration $REG registration to be deleted permenantly |
|
| 2654 | - * @return bool true = successful deletion, false = fail. |
|
| 2655 | - * @throws EE_Error |
|
| 2656 | - */ |
|
| 2657 | - protected function _delete_registration(EE_Registration $REG) |
|
| 2658 | - { |
|
| 2659 | - //first we start with the transaction... ultimately, we WILL not delete permanently if there are any related |
|
| 2660 | - //registrations on the transaction that are NOT trashed. |
|
| 2661 | - $TXN = $REG->get_first_related('Transaction'); |
|
| 2662 | - $REGS = $TXN->get_many_related('Registration'); |
|
| 2663 | - $all_trashed = true; |
|
| 2664 | - foreach ($REGS as $registration) { |
|
| 2665 | - if ( ! $registration->get('REG_deleted')) { |
|
| 2666 | - $all_trashed = false; |
|
| 2667 | - } |
|
| 2668 | - } |
|
| 2669 | - if ( ! $all_trashed) { |
|
| 2670 | - EE_Error::add_error( |
|
| 2671 | - esc_html__( |
|
| 2672 | - 'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well. These registrations will be permanently deleted in the same action.', |
|
| 2673 | - 'event_espresso' |
|
| 2674 | - ), |
|
| 2675 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2676 | - ); |
|
| 2677 | - return false; |
|
| 2678 | - } |
|
| 2679 | - //k made it here so that means we can delete all the related transactions and their answers (but let's do them |
|
| 2680 | - //separately from THIS one). |
|
| 2681 | - foreach ($REGS as $registration) { |
|
| 2682 | - //delete related answers |
|
| 2683 | - $registration->delete_related_permanently('Answer'); |
|
| 2684 | - //remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact) |
|
| 2685 | - $attendee = $registration->get_first_related('Attendee'); |
|
| 2686 | - if ($attendee instanceof EE_Attendee) { |
|
| 2687 | - $registration->_remove_relation_to($attendee, 'Attendee'); |
|
| 2688 | - } |
|
| 2689 | - //now remove relationships to tickets on this registration. |
|
| 2690 | - $registration->_remove_relations('Ticket'); |
|
| 2691 | - //now delete permanently the checkins related to this registration. |
|
| 2692 | - $registration->delete_related_permanently('Checkin'); |
|
| 2693 | - if ($registration->ID() === $REG->ID()) { |
|
| 2694 | - continue; |
|
| 2695 | - } //we don't want to delete permanently the existing registration just yet. |
|
| 2696 | - //remove relation to transaction for these registrations if NOT the existing registrations |
|
| 2697 | - $registration->_remove_relations('Transaction'); |
|
| 2698 | - //delete permanently any related messages. |
|
| 2699 | - $registration->delete_related_permanently('Message'); |
|
| 2700 | - //now delete this registration permanently |
|
| 2701 | - $registration->delete_permanently(); |
|
| 2702 | - } |
|
| 2703 | - //now all related registrations on the transaction are handled. So let's just handle this registration itself |
|
| 2704 | - // (the transaction and line items should be all that's left). |
|
| 2705 | - // delete the line items related to the transaction for this registration. |
|
| 2706 | - $TXN->delete_related_permanently('Line_Item'); |
|
| 2707 | - //we need to remove all the relationships on the transaction |
|
| 2708 | - $TXN->delete_related_permanently('Payment'); |
|
| 2709 | - $TXN->delete_related_permanently('Extra_Meta'); |
|
| 2710 | - $TXN->delete_related_permanently('Message'); |
|
| 2711 | - //now we can delete this REG permanently (and the transaction of course) |
|
| 2712 | - $REG->delete_related_permanently('Transaction'); |
|
| 2713 | - return $REG->delete_permanently(); |
|
| 2714 | - } |
|
| 2715 | - |
|
| 2716 | - |
|
| 2717 | - /** |
|
| 2718 | - * generates HTML for the Register New Attendee Admin page |
|
| 2719 | - * |
|
| 2720 | - * @access private |
|
| 2721 | - * @throws DomainException |
|
| 2722 | - * @throws EE_Error |
|
| 2723 | - */ |
|
| 2724 | - public function new_registration() |
|
| 2725 | - { |
|
| 2726 | - if ( ! $this->_set_reg_event()) { |
|
| 2727 | - throw new EE_Error( |
|
| 2728 | - esc_html__( |
|
| 2729 | - 'Unable to continue with registering because there is no Event ID in the request', |
|
| 2730 | - 'event_espresso' |
|
| 2731 | - ) |
|
| 2732 | - ); |
|
| 2733 | - } |
|
| 2734 | - EE_Registry::instance()->REQ->set_espresso_page(true); |
|
| 2735 | - // gotta start with a clean slate if we're not coming here via ajax |
|
| 2736 | - if ( ! defined('DOING_AJAX') |
|
| 2737 | - && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error'])) |
|
| 2738 | - ) { |
|
| 2739 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 2740 | - } |
|
| 2741 | - $this->_template_args['event_name'] = ''; |
|
| 2742 | - // event name |
|
| 2743 | - if ($this->_reg_event) { |
|
| 2744 | - $this->_template_args['event_name'] = $this->_reg_event->name(); |
|
| 2745 | - $edit_event_url = self::add_query_args_and_nonce(array( |
|
| 2746 | - 'action' => 'edit', |
|
| 2747 | - 'post' => $this->_reg_event->ID(), |
|
| 2748 | - ), EVENTS_ADMIN_URL); |
|
| 2749 | - $edit_event_lnk = '<a href="' |
|
| 2750 | - . $edit_event_url |
|
| 2751 | - . '" title="' |
|
| 2752 | - . esc_attr__('Edit ', 'event_espresso') |
|
| 2753 | - . $this->_reg_event->name() |
|
| 2754 | - . '">' |
|
| 2755 | - . esc_html__('Edit Event', 'event_espresso') |
|
| 2756 | - . '</a>'; |
|
| 2757 | - $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">' |
|
| 2758 | - . $edit_event_lnk |
|
| 2759 | - . '</span>'; |
|
| 2760 | - } |
|
| 2761 | - $this->_template_args['step_content'] = $this->_get_registration_step_content(); |
|
| 2762 | - if (defined('DOING_AJAX')) { |
|
| 2763 | - $this->_return_json(); |
|
| 2764 | - } |
|
| 2765 | - // grab header |
|
| 2766 | - $template_path = |
|
| 2767 | - REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php'; |
|
| 2768 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, |
|
| 2769 | - $this->_template_args, true); |
|
| 2770 | - //$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE ); |
|
| 2771 | - // the details template wrapper |
|
| 2772 | - $this->display_admin_page_with_sidebar(); |
|
| 2773 | - } |
|
| 2774 | - |
|
| 2775 | - |
|
| 2776 | - /** |
|
| 2777 | - * This returns the content for a registration step |
|
| 2778 | - * |
|
| 2779 | - * @access protected |
|
| 2780 | - * @return string html |
|
| 2781 | - * @throws DomainException |
|
| 2782 | - * @throws EE_Error |
|
| 2783 | - */ |
|
| 2784 | - protected function _get_registration_step_content() |
|
| 2785 | - { |
|
| 2786 | - if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) { |
|
| 2787 | - $warning_msg = sprintf( |
|
| 2788 | - esc_html__( |
|
| 2789 | - '%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s', |
|
| 2790 | - 'event_espresso' |
|
| 2791 | - ), |
|
| 2792 | - '<br />', |
|
| 2793 | - '<h3 class="important-notice">', |
|
| 2794 | - '</h3>', |
|
| 2795 | - '<div class="float-right">', |
|
| 2796 | - '<span id="redirect_timer" class="important-notice">30</span>', |
|
| 2797 | - '</div>', |
|
| 2798 | - '<b>', |
|
| 2799 | - '</b>' |
|
| 2800 | - ); |
|
| 2801 | - return ' |
|
| 2302 | + } |
|
| 2303 | + |
|
| 2304 | + |
|
| 2305 | + /** |
|
| 2306 | + * Updates the registration's custom questions according to the form info, if the form is submitted. |
|
| 2307 | + * If it's not a post, the "view_registrations" route will be called next on the SAME request |
|
| 2308 | + * to display the page |
|
| 2309 | + * |
|
| 2310 | + * @access protected |
|
| 2311 | + * @return void |
|
| 2312 | + * @throws EE_Error |
|
| 2313 | + */ |
|
| 2314 | + protected function _update_attendee_registration_form() |
|
| 2315 | + { |
|
| 2316 | + do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this); |
|
| 2317 | + if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
| 2318 | + $REG_ID = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false; |
|
| 2319 | + $success = $this->_save_reg_custom_questions_form($REG_ID); |
|
| 2320 | + if ($success) { |
|
| 2321 | + $what = esc_html__('Registration Form', 'event_espresso'); |
|
| 2322 | + $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID) |
|
| 2323 | + : array('action' => 'default'); |
|
| 2324 | + $this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route); |
|
| 2325 | + } |
|
| 2326 | + } |
|
| 2327 | + } |
|
| 2328 | + |
|
| 2329 | + |
|
| 2330 | + /** |
|
| 2331 | + * Gets the form for saving registrations custom questions (if done |
|
| 2332 | + * previously retrieves the cached form object, which may have validation errors in it) |
|
| 2333 | + * |
|
| 2334 | + * @param int $REG_ID |
|
| 2335 | + * @return EE_Registration_Custom_Questions_Form |
|
| 2336 | + * @throws EE_Error |
|
| 2337 | + */ |
|
| 2338 | + protected function _get_reg_custom_questions_form($REG_ID) |
|
| 2339 | + { |
|
| 2340 | + if ( ! $this->_reg_custom_questions_form) { |
|
| 2341 | + require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php'); |
|
| 2342 | + $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form( |
|
| 2343 | + EEM_Registration::instance()->get_one_by_ID($REG_ID) |
|
| 2344 | + ); |
|
| 2345 | + $this->_reg_custom_questions_form->_construct_finalize(null, null); |
|
| 2346 | + } |
|
| 2347 | + return $this->_reg_custom_questions_form; |
|
| 2348 | + } |
|
| 2349 | + |
|
| 2350 | + |
|
| 2351 | + /** |
|
| 2352 | + * Saves |
|
| 2353 | + * |
|
| 2354 | + * @access private |
|
| 2355 | + * @param bool $REG_ID |
|
| 2356 | + * @return bool |
|
| 2357 | + * @throws EE_Error |
|
| 2358 | + */ |
|
| 2359 | + private function _save_reg_custom_questions_form($REG_ID = false) |
|
| 2360 | + { |
|
| 2361 | + if ( ! $REG_ID) { |
|
| 2362 | + EE_Error::add_error( |
|
| 2363 | + esc_html__( |
|
| 2364 | + 'An error occurred. No registration ID was received.', 'event_espresso'), |
|
| 2365 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2366 | + ); |
|
| 2367 | + } |
|
| 2368 | + $form = $this->_get_reg_custom_questions_form($REG_ID); |
|
| 2369 | + $form->receive_form_submission($this->_req_data); |
|
| 2370 | + $success = false; |
|
| 2371 | + if ($form->is_valid()) { |
|
| 2372 | + foreach ($form->subforms() as $question_group_id => $question_group_form) { |
|
| 2373 | + foreach ($question_group_form->inputs() as $question_id => $input) { |
|
| 2374 | + $where_conditions = array( |
|
| 2375 | + 'QST_ID' => $question_id, |
|
| 2376 | + 'REG_ID' => $REG_ID, |
|
| 2377 | + ); |
|
| 2378 | + $possibly_new_values = array( |
|
| 2379 | + 'ANS_value' => $input->normalized_value(), |
|
| 2380 | + ); |
|
| 2381 | + $answer = EEM_Answer::instance()->get_one(array($where_conditions)); |
|
| 2382 | + if ($answer instanceof EE_Answer) { |
|
| 2383 | + $success = $answer->save($possibly_new_values); |
|
| 2384 | + } else { |
|
| 2385 | + //insert it then |
|
| 2386 | + $cols_n_vals = array_merge($where_conditions, $possibly_new_values); |
|
| 2387 | + $answer = EE_Answer::new_instance($cols_n_vals); |
|
| 2388 | + $success = $answer->save(); |
|
| 2389 | + } |
|
| 2390 | + } |
|
| 2391 | + } |
|
| 2392 | + } else { |
|
| 2393 | + EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__); |
|
| 2394 | + } |
|
| 2395 | + return $success; |
|
| 2396 | + } |
|
| 2397 | + |
|
| 2398 | + |
|
| 2399 | + /** |
|
| 2400 | + * generates HTML for the Registration main meta box |
|
| 2401 | + * |
|
| 2402 | + * @access public |
|
| 2403 | + * @return void |
|
| 2404 | + * @throws DomainException |
|
| 2405 | + * @throws EE_Error |
|
| 2406 | + */ |
|
| 2407 | + public function _reg_attendees_meta_box() |
|
| 2408 | + { |
|
| 2409 | + $REG = EEM_Registration::instance(); |
|
| 2410 | + //get all other registrations on this transaction, and cache |
|
| 2411 | + //the attendees for them so we don't have to run another query using force_join |
|
| 2412 | + $registrations = $REG->get_all(array( |
|
| 2413 | + array( |
|
| 2414 | + 'TXN_ID' => $this->_registration->transaction_ID(), |
|
| 2415 | + 'REG_ID' => array('!=', $this->_registration->ID()), |
|
| 2416 | + ), |
|
| 2417 | + 'force_join' => array('Attendee'), |
|
| 2418 | + )); |
|
| 2419 | + $this->_template_args['attendees'] = array(); |
|
| 2420 | + $this->_template_args['attendee_notice'] = ''; |
|
| 2421 | + if (empty($registrations) |
|
| 2422 | + || (is_array($registrations) |
|
| 2423 | + && ! EEH_Array::get_one_item_from_array($registrations)) |
|
| 2424 | + ) { |
|
| 2425 | + EE_Error::add_error( |
|
| 2426 | + esc_html__( |
|
| 2427 | + 'There are no records attached to this registration. Something may have gone wrong with the registration', |
|
| 2428 | + 'event_espresso' |
|
| 2429 | + ), __FILE__, __FUNCTION__, __LINE__ |
|
| 2430 | + ); |
|
| 2431 | + $this->_template_args['attendee_notice'] = EE_Error::get_notices(); |
|
| 2432 | + } else { |
|
| 2433 | + $att_nmbr = 1; |
|
| 2434 | + foreach ($registrations as $registration) { |
|
| 2435 | + /* @var $registration EE_Registration */ |
|
| 2436 | + $attendee = $registration->attendee() |
|
| 2437 | + ? $registration->attendee() |
|
| 2438 | + : EEM_Attendee::instance() |
|
| 2439 | + ->create_default_object(); |
|
| 2440 | + $this->_template_args['attendees'][$att_nmbr]['STS_ID'] = $registration->status_ID(); |
|
| 2441 | + $this->_template_args['attendees'][$att_nmbr]['fname'] = $attendee->fname(); |
|
| 2442 | + $this->_template_args['attendees'][$att_nmbr]['lname'] = $attendee->lname(); |
|
| 2443 | + $this->_template_args['attendees'][$att_nmbr]['email'] = $attendee->email(); |
|
| 2444 | + $this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price(); |
|
| 2445 | + $this->_template_args['attendees'][$att_nmbr]['address'] = implode( |
|
| 2446 | + ', ', |
|
| 2447 | + $attendee->full_address_as_array() |
|
| 2448 | + ); |
|
| 2449 | + $this->_template_args['attendees'][$att_nmbr]['att_link'] = self::add_query_args_and_nonce( |
|
| 2450 | + array( |
|
| 2451 | + 'action' => 'edit_attendee', |
|
| 2452 | + 'post' => $attendee->ID(), |
|
| 2453 | + ), |
|
| 2454 | + REG_ADMIN_URL |
|
| 2455 | + ); |
|
| 2456 | + $this->_template_args['attendees'][$att_nmbr]['event_name'] = $registration->event_obj()->name(); |
|
| 2457 | + $att_nmbr++; |
|
| 2458 | + } |
|
| 2459 | + $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 2460 | + } |
|
| 2461 | + $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php'; |
|
| 2462 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2463 | + } |
|
| 2464 | + |
|
| 2465 | + |
|
| 2466 | + /** |
|
| 2467 | + * generates HTML for the Edit Registration side meta box |
|
| 2468 | + * |
|
| 2469 | + * @access public |
|
| 2470 | + * @return void |
|
| 2471 | + * @throws DomainException |
|
| 2472 | + * @throws EE_Error |
|
| 2473 | + */ |
|
| 2474 | + public function _reg_registrant_side_meta_box() |
|
| 2475 | + { |
|
| 2476 | + /*@var $attendee EE_Attendee */ |
|
| 2477 | + $att_check = $this->_registration->attendee(); |
|
| 2478 | + $attendee = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object(); |
|
| 2479 | + //now let's determine if this is not the primary registration. If it isn't then we set the |
|
| 2480 | + //primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the |
|
| 2481 | + //primary registration object (that way we know if we need to show create button or not) |
|
| 2482 | + if ( ! $this->_registration->is_primary_registrant()) { |
|
| 2483 | + $primary_registration = $this->_registration->get_primary_registration(); |
|
| 2484 | + $primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() |
|
| 2485 | + : null; |
|
| 2486 | + if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) { |
|
| 2487 | + //in here? This means the displayed registration is not the primary registrant but ALREADY HAS its own |
|
| 2488 | + //custom attendee object so let's not worry about the primary reg. |
|
| 2489 | + $primary_registration = null; |
|
| 2490 | + } |
|
| 2491 | + } else { |
|
| 2492 | + $primary_registration = null; |
|
| 2493 | + } |
|
| 2494 | + $this->_template_args['ATT_ID'] = $attendee->ID(); |
|
| 2495 | + $this->_template_args['fname'] = $attendee->fname(); |
|
| 2496 | + $this->_template_args['lname'] = $attendee->lname(); |
|
| 2497 | + $this->_template_args['email'] = $attendee->email(); |
|
| 2498 | + $this->_template_args['phone'] = $attendee->phone(); |
|
| 2499 | + $this->_template_args['formatted_address'] = EEH_Address::format($attendee); |
|
| 2500 | + //edit link |
|
| 2501 | + $this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 2502 | + 'action' => 'edit_attendee', |
|
| 2503 | + 'post' => $attendee->ID(), |
|
| 2504 | + ), REG_ADMIN_URL); |
|
| 2505 | + $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso'); |
|
| 2506 | + //create link |
|
| 2507 | + $this->_template_args['create_link'] = $primary_registration instanceof EE_Registration |
|
| 2508 | + ? EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 2509 | + 'action' => 'duplicate_attendee', |
|
| 2510 | + '_REG_ID' => $this->_registration->ID(), |
|
| 2511 | + ), REG_ADMIN_URL) : ''; |
|
| 2512 | + $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso'); |
|
| 2513 | + $this->_template_args['att_check'] = $att_check; |
|
| 2514 | + $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php'; |
|
| 2515 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2516 | + } |
|
| 2517 | + |
|
| 2518 | + |
|
| 2519 | + /** |
|
| 2520 | + * trash or restore registrations |
|
| 2521 | + * |
|
| 2522 | + * @param boolean $trash whether to archive or restore |
|
| 2523 | + * @return void |
|
| 2524 | + * @throws EE_Error |
|
| 2525 | + * @throws RuntimeException |
|
| 2526 | + * @access protected |
|
| 2527 | + */ |
|
| 2528 | + protected function _trash_or_restore_registrations($trash = true) |
|
| 2529 | + { |
|
| 2530 | + //if empty _REG_ID then get out because there's nothing to do |
|
| 2531 | + if (empty($this->_req_data['_REG_ID'])) { |
|
| 2532 | + EE_Error::add_error( |
|
| 2533 | + sprintf( |
|
| 2534 | + esc_html__( |
|
| 2535 | + 'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.', |
|
| 2536 | + 'event_espresso' |
|
| 2537 | + ), |
|
| 2538 | + $trash ? 'trash' : 'restore' |
|
| 2539 | + ), |
|
| 2540 | + __FILE__, __LINE__, __FUNCTION__ |
|
| 2541 | + ); |
|
| 2542 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 2543 | + } |
|
| 2544 | + $success = 0; |
|
| 2545 | + $overwrite_msgs = false; |
|
| 2546 | + //Checkboxes |
|
| 2547 | + if ( ! is_array($this->_req_data['_REG_ID'])) { |
|
| 2548 | + $this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']); |
|
| 2549 | + } |
|
| 2550 | + $reg_count = count($this->_req_data['_REG_ID']); |
|
| 2551 | + // cycle thru checkboxes |
|
| 2552 | + foreach ($this->_req_data['_REG_ID'] as $REG_ID) { |
|
| 2553 | + /** @var EE_Registration $REG */ |
|
| 2554 | + $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
| 2555 | + $payments = $REG->registration_payments(); |
|
| 2556 | + if (! empty($payments)) { |
|
| 2557 | + $name = $REG->attendee() instanceof EE_Attendee |
|
| 2558 | + ? $REG->attendee()->full_name() |
|
| 2559 | + : esc_html__('Unknown Attendee', 'event_espresso'); |
|
| 2560 | + $overwrite_msgs = true; |
|
| 2561 | + EE_Error::add_error( |
|
| 2562 | + sprintf( |
|
| 2563 | + esc_html__( |
|
| 2564 | + 'The registration for %s could not be trashed because it has payments attached to the related transaction. If you wish to trash this registration you must first delete the payments on the related transaction.', |
|
| 2565 | + 'event_espresso' |
|
| 2566 | + ), |
|
| 2567 | + $name |
|
| 2568 | + ), |
|
| 2569 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2570 | + ); |
|
| 2571 | + //can't trash this registration because it has payments. |
|
| 2572 | + continue; |
|
| 2573 | + } |
|
| 2574 | + $updated = $trash ? $REG->delete() : $REG->restore(); |
|
| 2575 | + if ($updated) { |
|
| 2576 | + $success++; |
|
| 2577 | + } |
|
| 2578 | + } |
|
| 2579 | + $this->_redirect_after_action( |
|
| 2580 | + $success === $reg_count, // were ALL registrations affected? |
|
| 2581 | + $success > 1 |
|
| 2582 | + ? esc_html__('Registrations', 'event_espresso') |
|
| 2583 | + : esc_html__('Registration', 'event_espresso'), |
|
| 2584 | + $trash |
|
| 2585 | + ? esc_html__('moved to the trash', 'event_espresso') |
|
| 2586 | + : esc_html__('restored', 'event_espresso'), |
|
| 2587 | + array('action' => 'default'), |
|
| 2588 | + $overwrite_msgs |
|
| 2589 | + ); |
|
| 2590 | + } |
|
| 2591 | + |
|
| 2592 | + |
|
| 2593 | + /** |
|
| 2594 | + * This is used to permanently delete registrations. Note, this will handle not only deleting permanently the |
|
| 2595 | + * registration but also. |
|
| 2596 | + * 1. Removing relations to EE_Attendee |
|
| 2597 | + * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are |
|
| 2598 | + * ALSO trashed. |
|
| 2599 | + * 3. Deleting permanently any related Line items but only if the above conditions are met. |
|
| 2600 | + * 4. Removing relationships between all tickets and the related registrations |
|
| 2601 | + * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.) |
|
| 2602 | + * 6. Deleting permanently any related Checkins. |
|
| 2603 | + * |
|
| 2604 | + * @return void |
|
| 2605 | + * @throws EE_Error |
|
| 2606 | + */ |
|
| 2607 | + protected function _delete_registrations() |
|
| 2608 | + { |
|
| 2609 | + $REG_MDL = EEM_Registration::instance(); |
|
| 2610 | + $success = 1; |
|
| 2611 | + //Checkboxes |
|
| 2612 | + if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) { |
|
| 2613 | + // if array has more than one element than success message should be plural |
|
| 2614 | + $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1; |
|
| 2615 | + // cycle thru checkboxes |
|
| 2616 | + while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) { |
|
| 2617 | + $REG = $REG_MDL->get_one_by_ID($REG_ID); |
|
| 2618 | + if ( ! $REG instanceof EE_Registration) { |
|
| 2619 | + continue; |
|
| 2620 | + } |
|
| 2621 | + $deleted = $this->_delete_registration($REG); |
|
| 2622 | + if ( ! $deleted) { |
|
| 2623 | + $success = 0; |
|
| 2624 | + } |
|
| 2625 | + } |
|
| 2626 | + } else { |
|
| 2627 | + // grab single id and delete |
|
| 2628 | + $REG_ID = $this->_req_data['_REG_ID']; |
|
| 2629 | + $REG = $REG_MDL->get_one_by_ID($REG_ID); |
|
| 2630 | + $deleted = $this->_delete_registration($REG); |
|
| 2631 | + if ( ! $deleted) { |
|
| 2632 | + $success = 0; |
|
| 2633 | + } |
|
| 2634 | + } |
|
| 2635 | + $what = $success > 1 |
|
| 2636 | + ? esc_html__('Registrations', 'event_espresso') |
|
| 2637 | + : esc_html__('Registration', 'event_espresso'); |
|
| 2638 | + $action_desc = esc_html__('permanently deleted.', 'event_espresso'); |
|
| 2639 | + $this->_redirect_after_action( |
|
| 2640 | + $success, |
|
| 2641 | + $what, |
|
| 2642 | + $action_desc, |
|
| 2643 | + array('action' => 'default'), |
|
| 2644 | + true |
|
| 2645 | + ); |
|
| 2646 | + } |
|
| 2647 | + |
|
| 2648 | + |
|
| 2649 | + /** |
|
| 2650 | + * handles the permanent deletion of a registration. See comments with _delete_registrations() for details on what |
|
| 2651 | + * models get affected. |
|
| 2652 | + * |
|
| 2653 | + * @param EE_Registration $REG registration to be deleted permenantly |
|
| 2654 | + * @return bool true = successful deletion, false = fail. |
|
| 2655 | + * @throws EE_Error |
|
| 2656 | + */ |
|
| 2657 | + protected function _delete_registration(EE_Registration $REG) |
|
| 2658 | + { |
|
| 2659 | + //first we start with the transaction... ultimately, we WILL not delete permanently if there are any related |
|
| 2660 | + //registrations on the transaction that are NOT trashed. |
|
| 2661 | + $TXN = $REG->get_first_related('Transaction'); |
|
| 2662 | + $REGS = $TXN->get_many_related('Registration'); |
|
| 2663 | + $all_trashed = true; |
|
| 2664 | + foreach ($REGS as $registration) { |
|
| 2665 | + if ( ! $registration->get('REG_deleted')) { |
|
| 2666 | + $all_trashed = false; |
|
| 2667 | + } |
|
| 2668 | + } |
|
| 2669 | + if ( ! $all_trashed) { |
|
| 2670 | + EE_Error::add_error( |
|
| 2671 | + esc_html__( |
|
| 2672 | + 'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well. These registrations will be permanently deleted in the same action.', |
|
| 2673 | + 'event_espresso' |
|
| 2674 | + ), |
|
| 2675 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2676 | + ); |
|
| 2677 | + return false; |
|
| 2678 | + } |
|
| 2679 | + //k made it here so that means we can delete all the related transactions and their answers (but let's do them |
|
| 2680 | + //separately from THIS one). |
|
| 2681 | + foreach ($REGS as $registration) { |
|
| 2682 | + //delete related answers |
|
| 2683 | + $registration->delete_related_permanently('Answer'); |
|
| 2684 | + //remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact) |
|
| 2685 | + $attendee = $registration->get_first_related('Attendee'); |
|
| 2686 | + if ($attendee instanceof EE_Attendee) { |
|
| 2687 | + $registration->_remove_relation_to($attendee, 'Attendee'); |
|
| 2688 | + } |
|
| 2689 | + //now remove relationships to tickets on this registration. |
|
| 2690 | + $registration->_remove_relations('Ticket'); |
|
| 2691 | + //now delete permanently the checkins related to this registration. |
|
| 2692 | + $registration->delete_related_permanently('Checkin'); |
|
| 2693 | + if ($registration->ID() === $REG->ID()) { |
|
| 2694 | + continue; |
|
| 2695 | + } //we don't want to delete permanently the existing registration just yet. |
|
| 2696 | + //remove relation to transaction for these registrations if NOT the existing registrations |
|
| 2697 | + $registration->_remove_relations('Transaction'); |
|
| 2698 | + //delete permanently any related messages. |
|
| 2699 | + $registration->delete_related_permanently('Message'); |
|
| 2700 | + //now delete this registration permanently |
|
| 2701 | + $registration->delete_permanently(); |
|
| 2702 | + } |
|
| 2703 | + //now all related registrations on the transaction are handled. So let's just handle this registration itself |
|
| 2704 | + // (the transaction and line items should be all that's left). |
|
| 2705 | + // delete the line items related to the transaction for this registration. |
|
| 2706 | + $TXN->delete_related_permanently('Line_Item'); |
|
| 2707 | + //we need to remove all the relationships on the transaction |
|
| 2708 | + $TXN->delete_related_permanently('Payment'); |
|
| 2709 | + $TXN->delete_related_permanently('Extra_Meta'); |
|
| 2710 | + $TXN->delete_related_permanently('Message'); |
|
| 2711 | + //now we can delete this REG permanently (and the transaction of course) |
|
| 2712 | + $REG->delete_related_permanently('Transaction'); |
|
| 2713 | + return $REG->delete_permanently(); |
|
| 2714 | + } |
|
| 2715 | + |
|
| 2716 | + |
|
| 2717 | + /** |
|
| 2718 | + * generates HTML for the Register New Attendee Admin page |
|
| 2719 | + * |
|
| 2720 | + * @access private |
|
| 2721 | + * @throws DomainException |
|
| 2722 | + * @throws EE_Error |
|
| 2723 | + */ |
|
| 2724 | + public function new_registration() |
|
| 2725 | + { |
|
| 2726 | + if ( ! $this->_set_reg_event()) { |
|
| 2727 | + throw new EE_Error( |
|
| 2728 | + esc_html__( |
|
| 2729 | + 'Unable to continue with registering because there is no Event ID in the request', |
|
| 2730 | + 'event_espresso' |
|
| 2731 | + ) |
|
| 2732 | + ); |
|
| 2733 | + } |
|
| 2734 | + EE_Registry::instance()->REQ->set_espresso_page(true); |
|
| 2735 | + // gotta start with a clean slate if we're not coming here via ajax |
|
| 2736 | + if ( ! defined('DOING_AJAX') |
|
| 2737 | + && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error'])) |
|
| 2738 | + ) { |
|
| 2739 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 2740 | + } |
|
| 2741 | + $this->_template_args['event_name'] = ''; |
|
| 2742 | + // event name |
|
| 2743 | + if ($this->_reg_event) { |
|
| 2744 | + $this->_template_args['event_name'] = $this->_reg_event->name(); |
|
| 2745 | + $edit_event_url = self::add_query_args_and_nonce(array( |
|
| 2746 | + 'action' => 'edit', |
|
| 2747 | + 'post' => $this->_reg_event->ID(), |
|
| 2748 | + ), EVENTS_ADMIN_URL); |
|
| 2749 | + $edit_event_lnk = '<a href="' |
|
| 2750 | + . $edit_event_url |
|
| 2751 | + . '" title="' |
|
| 2752 | + . esc_attr__('Edit ', 'event_espresso') |
|
| 2753 | + . $this->_reg_event->name() |
|
| 2754 | + . '">' |
|
| 2755 | + . esc_html__('Edit Event', 'event_espresso') |
|
| 2756 | + . '</a>'; |
|
| 2757 | + $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">' |
|
| 2758 | + . $edit_event_lnk |
|
| 2759 | + . '</span>'; |
|
| 2760 | + } |
|
| 2761 | + $this->_template_args['step_content'] = $this->_get_registration_step_content(); |
|
| 2762 | + if (defined('DOING_AJAX')) { |
|
| 2763 | + $this->_return_json(); |
|
| 2764 | + } |
|
| 2765 | + // grab header |
|
| 2766 | + $template_path = |
|
| 2767 | + REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php'; |
|
| 2768 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, |
|
| 2769 | + $this->_template_args, true); |
|
| 2770 | + //$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE ); |
|
| 2771 | + // the details template wrapper |
|
| 2772 | + $this->display_admin_page_with_sidebar(); |
|
| 2773 | + } |
|
| 2774 | + |
|
| 2775 | + |
|
| 2776 | + /** |
|
| 2777 | + * This returns the content for a registration step |
|
| 2778 | + * |
|
| 2779 | + * @access protected |
|
| 2780 | + * @return string html |
|
| 2781 | + * @throws DomainException |
|
| 2782 | + * @throws EE_Error |
|
| 2783 | + */ |
|
| 2784 | + protected function _get_registration_step_content() |
|
| 2785 | + { |
|
| 2786 | + if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) { |
|
| 2787 | + $warning_msg = sprintf( |
|
| 2788 | + esc_html__( |
|
| 2789 | + '%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s', |
|
| 2790 | + 'event_espresso' |
|
| 2791 | + ), |
|
| 2792 | + '<br />', |
|
| 2793 | + '<h3 class="important-notice">', |
|
| 2794 | + '</h3>', |
|
| 2795 | + '<div class="float-right">', |
|
| 2796 | + '<span id="redirect_timer" class="important-notice">30</span>', |
|
| 2797 | + '</div>', |
|
| 2798 | + '<b>', |
|
| 2799 | + '</b>' |
|
| 2800 | + ); |
|
| 2801 | + return ' |
|
| 2802 | 2802 | <div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div> |
| 2803 | 2803 | <script > |
| 2804 | 2804 | // WHOAH !!! it appears that someone is using the back button from the Transaction admin page |
@@ -2811,792 +2811,792 @@ discard block |
||
| 2811 | 2811 | } |
| 2812 | 2812 | }, 800 ); |
| 2813 | 2813 | </script >'; |
| 2814 | - } |
|
| 2815 | - $template_args = array( |
|
| 2816 | - 'title' => '', |
|
| 2817 | - 'content' => '', |
|
| 2818 | - 'step_button_text' => '', |
|
| 2819 | - 'show_notification_toggle' => false, |
|
| 2820 | - ); |
|
| 2821 | - //to indicate we're processing a new registration |
|
| 2822 | - $hidden_fields = array( |
|
| 2823 | - 'processing_registration' => array( |
|
| 2824 | - 'type' => 'hidden', |
|
| 2825 | - 'value' => 0, |
|
| 2826 | - ), |
|
| 2827 | - 'event_id' => array( |
|
| 2828 | - 'type' => 'hidden', |
|
| 2829 | - 'value' => $this->_reg_event->ID(), |
|
| 2830 | - ), |
|
| 2831 | - ); |
|
| 2832 | - //if the cart is empty then we know we're at step one so we'll display ticket selector |
|
| 2833 | - $cart = EE_Registry::instance()->SSN->cart(); |
|
| 2834 | - $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions'; |
|
| 2835 | - switch ($step) { |
|
| 2836 | - case 'ticket' : |
|
| 2837 | - $hidden_fields['processing_registration']['value'] = 1; |
|
| 2838 | - $template_args['title'] = esc_html__( |
|
| 2839 | - 'Step One: Select the Ticket for this registration', |
|
| 2840 | - 'event_espresso' |
|
| 2841 | - ); |
|
| 2842 | - $template_args['content'] = |
|
| 2843 | - EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event); |
|
| 2844 | - $template_args['step_button_text'] = esc_html__( |
|
| 2845 | - 'Add Tickets and Continue to Registrant Details', |
|
| 2846 | - 'event_espresso' |
|
| 2847 | - ); |
|
| 2848 | - $template_args['show_notification_toggle'] = false; |
|
| 2849 | - break; |
|
| 2850 | - case 'questions' : |
|
| 2851 | - $hidden_fields['processing_registration']['value'] = 2; |
|
| 2852 | - $template_args['title'] = esc_html__( |
|
| 2853 | - 'Step Two: Add Registrant Details for this Registration', |
|
| 2854 | - 'event_espresso' |
|
| 2855 | - ); |
|
| 2856 | - //in theory we should be able to run EED_SPCO at this point because the cart should have been setup |
|
| 2857 | - // properly by the first process_reg_step run. |
|
| 2858 | - $template_args['content'] = |
|
| 2859 | - EED_Single_Page_Checkout::registration_checkout_for_admin(); |
|
| 2860 | - $template_args['step_button_text'] = esc_html__( |
|
| 2861 | - 'Save Registration and Continue to Details', |
|
| 2862 | - 'event_espresso' |
|
| 2863 | - ); |
|
| 2864 | - $template_args['show_notification_toggle'] = true; |
|
| 2865 | - break; |
|
| 2866 | - } |
|
| 2867 | - //we come back to the process_registration_step route. |
|
| 2868 | - $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields); |
|
| 2869 | - return EEH_Template::display_template( |
|
| 2870 | - REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php', |
|
| 2871 | - $template_args, |
|
| 2872 | - true |
|
| 2873 | - ); |
|
| 2874 | - } |
|
| 2875 | - |
|
| 2876 | - |
|
| 2877 | - /** |
|
| 2878 | - * set_reg_event |
|
| 2879 | - * |
|
| 2880 | - * @access private |
|
| 2881 | - * @return bool |
|
| 2882 | - * @throws EE_Error |
|
| 2883 | - */ |
|
| 2884 | - private function _set_reg_event() |
|
| 2885 | - { |
|
| 2886 | - if (is_object($this->_reg_event)) { |
|
| 2887 | - return true; |
|
| 2888 | - } |
|
| 2889 | - $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false; |
|
| 2890 | - if ( ! $EVT_ID) { |
|
| 2891 | - return false; |
|
| 2892 | - } |
|
| 2893 | - $this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2894 | - return true; |
|
| 2895 | - } |
|
| 2896 | - |
|
| 2897 | - |
|
| 2898 | - /** |
|
| 2899 | - * process_reg_step |
|
| 2900 | - * |
|
| 2901 | - * @access public |
|
| 2902 | - * @return string |
|
| 2903 | - * @throws DomainException |
|
| 2904 | - * @throws EE_Error |
|
| 2905 | - * @throws RuntimeException |
|
| 2906 | - */ |
|
| 2907 | - public function process_reg_step() |
|
| 2908 | - { |
|
| 2909 | - EE_System::do_not_cache(); |
|
| 2910 | - $this->_set_reg_event(); |
|
| 2911 | - EE_Registry::instance()->REQ->set_espresso_page(true); |
|
| 2912 | - EE_Registry::instance()->REQ->set('uts', time()); |
|
| 2913 | - //what step are we on? |
|
| 2914 | - $cart = EE_Registry::instance()->SSN->cart(); |
|
| 2915 | - $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions'; |
|
| 2916 | - //if doing ajax then we need to verify the nonce |
|
| 2917 | - if (defined('DOING_AJAX')) { |
|
| 2918 | - $nonce = isset($this->_req_data[$this->_req_nonce]) |
|
| 2919 | - ? sanitize_text_field($this->_req_data[$this->_req_nonce]) : ''; |
|
| 2920 | - $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 2921 | - } |
|
| 2922 | - switch ($step) { |
|
| 2923 | - case 'ticket' : |
|
| 2924 | - //process ticket selection |
|
| 2925 | - $success = EED_Ticket_Selector::instance()->process_ticket_selections(); |
|
| 2926 | - if ($success) { |
|
| 2927 | - EE_Error::add_success( |
|
| 2928 | - esc_html__( |
|
| 2929 | - 'Tickets Selected. Now complete the registration.', |
|
| 2930 | - 'event_espresso' |
|
| 2931 | - ) |
|
| 2932 | - ); |
|
| 2933 | - } else { |
|
| 2934 | - $query_args['step_error'] = $this->_req_data['step_error'] = true; |
|
| 2935 | - } |
|
| 2936 | - if (defined('DOING_AJAX')) { |
|
| 2937 | - $this->new_registration(); //display next step |
|
| 2938 | - } else { |
|
| 2939 | - $query_args = array( |
|
| 2940 | - 'action' => 'new_registration', |
|
| 2941 | - 'processing_registration' => 1, |
|
| 2942 | - 'event_id' => $this->_reg_event->ID(), |
|
| 2943 | - 'uts' => time(), |
|
| 2944 | - ); |
|
| 2945 | - $this->_redirect_after_action( |
|
| 2946 | - false, |
|
| 2947 | - '', |
|
| 2948 | - '', |
|
| 2949 | - $query_args, |
|
| 2950 | - true |
|
| 2951 | - ); |
|
| 2952 | - } |
|
| 2953 | - break; |
|
| 2954 | - case 'questions' : |
|
| 2955 | - if (! isset( |
|
| 2956 | - $this->_req_data['txn_reg_status_change'], |
|
| 2957 | - $this->_req_data['txn_reg_status_change']['send_notifications']) |
|
| 2958 | - ) { |
|
| 2959 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15); |
|
| 2960 | - } |
|
| 2961 | - //process registration |
|
| 2962 | - $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin(); |
|
| 2963 | - if ($cart instanceof EE_Cart) { |
|
| 2964 | - $grand_total = $cart->get_cart_grand_total(); |
|
| 2965 | - if ($grand_total instanceof EE_Line_Item) { |
|
| 2966 | - $grand_total->save_this_and_descendants_to_txn(); |
|
| 2967 | - } |
|
| 2968 | - } |
|
| 2969 | - if ( ! $transaction instanceof EE_Transaction) { |
|
| 2970 | - $query_args = array( |
|
| 2971 | - 'action' => 'new_registration', |
|
| 2972 | - 'processing_registration' => 2, |
|
| 2973 | - 'event_id' => $this->_reg_event->ID(), |
|
| 2974 | - 'uts' => time(), |
|
| 2975 | - ); |
|
| 2976 | - if (defined('DOING_AJAX')) { |
|
| 2977 | - //display registration form again because there are errors (maybe validation?) |
|
| 2978 | - $this->new_registration(); |
|
| 2979 | - return; |
|
| 2980 | - } else { |
|
| 2981 | - $this->_redirect_after_action( |
|
| 2982 | - false, |
|
| 2983 | - '', |
|
| 2984 | - '', |
|
| 2985 | - $query_args, |
|
| 2986 | - true |
|
| 2987 | - ); |
|
| 2988 | - return; |
|
| 2989 | - } |
|
| 2990 | - } |
|
| 2991 | - // maybe update status, and make sure to save transaction if not done already |
|
| 2992 | - if ( ! $transaction->update_status_based_on_total_paid()) { |
|
| 2993 | - $transaction->save(); |
|
| 2994 | - } |
|
| 2995 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 2996 | - $this->_req_data = array(); |
|
| 2997 | - $query_args = array( |
|
| 2998 | - 'action' => 'redirect_to_txn', |
|
| 2999 | - 'TXN_ID' => $transaction->ID(), |
|
| 3000 | - 'EVT_ID' => $this->_reg_event->ID(), |
|
| 3001 | - 'event_name' => urlencode($this->_reg_event->name()), |
|
| 3002 | - 'redirect_from' => 'new_registration', |
|
| 3003 | - ); |
|
| 3004 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 3005 | - break; |
|
| 3006 | - } |
|
| 3007 | - //what are you looking here for? Should be nothing to do at this point. |
|
| 3008 | - } |
|
| 3009 | - |
|
| 3010 | - |
|
| 3011 | - /** |
|
| 3012 | - * redirect_to_txn |
|
| 3013 | - * |
|
| 3014 | - * @access public |
|
| 3015 | - * @return void |
|
| 3016 | - * @throws EE_Error |
|
| 3017 | - */ |
|
| 3018 | - public function redirect_to_txn() |
|
| 3019 | - { |
|
| 3020 | - EE_System::do_not_cache(); |
|
| 3021 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 3022 | - $query_args = array( |
|
| 3023 | - 'action' => 'view_transaction', |
|
| 3024 | - 'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0, |
|
| 3025 | - 'page' => 'espresso_transactions', |
|
| 3026 | - ); |
|
| 3027 | - if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) { |
|
| 3028 | - $query_args['EVT_ID'] = $this->_req_data['EVT_ID']; |
|
| 3029 | - $query_args['event_name'] = urlencode($this->_req_data['event_name']); |
|
| 3030 | - $query_args['redirect_from'] = $this->_req_data['redirect_from']; |
|
| 3031 | - } |
|
| 3032 | - EE_Error::add_success( |
|
| 3033 | - esc_html__( |
|
| 3034 | - 'Registration Created. Please review the transaction and add any payments as necessary', |
|
| 3035 | - 'event_espresso' |
|
| 3036 | - ) |
|
| 3037 | - ); |
|
| 3038 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 3039 | - } |
|
| 3040 | - |
|
| 3041 | - |
|
| 3042 | - /** |
|
| 3043 | - * generates HTML for the Attendee Contact List |
|
| 3044 | - * |
|
| 3045 | - * @access protected |
|
| 3046 | - * @return void |
|
| 3047 | - */ |
|
| 3048 | - protected function _attendee_contact_list_table() |
|
| 3049 | - { |
|
| 3050 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3051 | - $this->_search_btn_label = esc_html__('Contacts', 'event_espresso'); |
|
| 3052 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 3053 | - } |
|
| 3054 | - |
|
| 3055 | - |
|
| 3056 | - /** |
|
| 3057 | - * get_attendees |
|
| 3058 | - * |
|
| 3059 | - * @param $per_page |
|
| 3060 | - * @param bool $count whether to return count or data. |
|
| 3061 | - * @param bool $trash |
|
| 3062 | - * @return array |
|
| 3063 | - * @throws EE_Error |
|
| 3064 | - * @access public |
|
| 3065 | - */ |
|
| 3066 | - public function get_attendees($per_page, $count = false, $trash = false) |
|
| 3067 | - { |
|
| 3068 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3069 | - require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php'); |
|
| 3070 | - $ATT_MDL = EEM_Attendee::instance(); |
|
| 3071 | - $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
|
| 3072 | - switch ($this->_req_data['orderby']) { |
|
| 3073 | - case 'ATT_ID': |
|
| 3074 | - $orderby = 'ATT_ID'; |
|
| 3075 | - break; |
|
| 3076 | - case 'ATT_fname': |
|
| 3077 | - $orderby = 'ATT_fname'; |
|
| 3078 | - break; |
|
| 3079 | - case 'ATT_email': |
|
| 3080 | - $orderby = 'ATT_email'; |
|
| 3081 | - break; |
|
| 3082 | - case 'ATT_city': |
|
| 3083 | - $orderby = 'ATT_city'; |
|
| 3084 | - break; |
|
| 3085 | - case 'STA_ID': |
|
| 3086 | - $orderby = 'STA_ID'; |
|
| 3087 | - break; |
|
| 3088 | - case 'CNT_ID': |
|
| 3089 | - $orderby = 'CNT_ID'; |
|
| 3090 | - break; |
|
| 3091 | - default: |
|
| 3092 | - $orderby = 'ATT_lname'; |
|
| 3093 | - } |
|
| 3094 | - $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) |
|
| 3095 | - ? $this->_req_data['order'] |
|
| 3096 | - : 'ASC'; |
|
| 3097 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 3098 | - ? $this->_req_data['paged'] |
|
| 3099 | - : 1; |
|
| 3100 | - $per_page = isset($per_page) && ! empty($per_page) ? $per_page : 10; |
|
| 3101 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 3102 | - ? $this->_req_data['perpage'] |
|
| 3103 | - : $per_page; |
|
| 3104 | - $_where = array(); |
|
| 3105 | - if ( ! empty($this->_req_data['s'])) { |
|
| 3106 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 3107 | - $_where['OR'] = array( |
|
| 3108 | - 'Registration.Event.EVT_name' => array('LIKE', $sstr), |
|
| 3109 | - 'Registration.Event.EVT_desc' => array('LIKE', $sstr), |
|
| 3110 | - 'Registration.Event.EVT_short_desc' => array('LIKE', $sstr), |
|
| 3111 | - 'ATT_fname' => array('LIKE', $sstr), |
|
| 3112 | - 'ATT_lname' => array('LIKE', $sstr), |
|
| 3113 | - 'ATT_short_bio' => array('LIKE', $sstr), |
|
| 3114 | - 'ATT_email' => array('LIKE', $sstr), |
|
| 3115 | - 'ATT_address' => array('LIKE', $sstr), |
|
| 3116 | - 'ATT_address2' => array('LIKE', $sstr), |
|
| 3117 | - 'ATT_city' => array('LIKE', $sstr), |
|
| 3118 | - 'Country.CNT_name' => array('LIKE', $sstr), |
|
| 3119 | - 'State.STA_name' => array('LIKE', $sstr), |
|
| 3120 | - 'ATT_phone' => array('LIKE', $sstr), |
|
| 3121 | - 'Registration.REG_final_price' => array('LIKE', $sstr), |
|
| 3122 | - 'Registration.REG_code' => array('LIKE', $sstr), |
|
| 3123 | - 'Registration.REG_count' => array('LIKE', $sstr), |
|
| 3124 | - 'Registration.REG_group_size' => array('LIKE', $sstr), |
|
| 3125 | - ); |
|
| 3126 | - } |
|
| 3127 | - $offset = ($current_page - 1) * $per_page; |
|
| 3128 | - $limit = $count ? null : array($offset, $per_page); |
|
| 3129 | - if ($trash) { |
|
| 3130 | - $_where['status'] = array('!=', 'publish'); |
|
| 3131 | - $all_attendees = $count |
|
| 3132 | - ? $ATT_MDL->count(array( |
|
| 3133 | - $_where, |
|
| 3134 | - 'order_by' => array($orderby => $sort), |
|
| 3135 | - 'limit' => $limit, |
|
| 3136 | - ), 'ATT_ID', true) |
|
| 3137 | - : $ATT_MDL->get_all(array( |
|
| 3138 | - $_where, |
|
| 3139 | - 'order_by' => array($orderby => $sort), |
|
| 3140 | - 'limit' => $limit, |
|
| 3141 | - )); |
|
| 3142 | - } else { |
|
| 3143 | - $_where['status'] = array('IN', array('publish')); |
|
| 3144 | - $all_attendees = $count |
|
| 3145 | - ? $ATT_MDL->count(array( |
|
| 3146 | - $_where, |
|
| 3147 | - 'order_by' => array($orderby => $sort), |
|
| 3148 | - 'limit' => $limit, |
|
| 3149 | - ), 'ATT_ID', true) |
|
| 3150 | - : $ATT_MDL->get_all(array( |
|
| 3151 | - $_where, |
|
| 3152 | - 'order_by' => array($orderby => $sort), |
|
| 3153 | - 'limit' => $limit, |
|
| 3154 | - )); |
|
| 3155 | - } |
|
| 3156 | - return $all_attendees; |
|
| 3157 | - } |
|
| 3158 | - |
|
| 3159 | - |
|
| 3160 | - /** |
|
| 3161 | - * This is just taking care of resending the registration confirmation |
|
| 3162 | - * |
|
| 3163 | - * @access protected |
|
| 3164 | - * @return void |
|
| 3165 | - */ |
|
| 3166 | - protected function _resend_registration() |
|
| 3167 | - { |
|
| 3168 | - $this->_process_resend_registration(); |
|
| 3169 | - $query_args = isset($this->_req_data['redirect_to']) |
|
| 3170 | - ? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID']) |
|
| 3171 | - : array('action' => 'default'); |
|
| 3172 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 3173 | - } |
|
| 3174 | - |
|
| 3175 | - /** |
|
| 3176 | - * Creates a registration report, but accepts the name of a method to use for preparing the query parameters |
|
| 3177 | - * to use when selecting registrations |
|
| 3178 | - * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing |
|
| 3179 | - * the query parameters from the request |
|
| 3180 | - * @return void ends the request with a redirect or download |
|
| 3181 | - */ |
|
| 3182 | - public function _registrations_report_base( $method_name_for_getting_query_params ) |
|
| 3183 | - { |
|
| 3184 | - if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) { |
|
| 3185 | - wp_redirect(EE_Admin_Page::add_query_args_and_nonce( |
|
| 3186 | - array( |
|
| 3187 | - 'page' => 'espresso_batch', |
|
| 3188 | - 'batch' => 'file', |
|
| 3189 | - 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null, |
|
| 3190 | - 'filters' => urlencode( |
|
| 3191 | - serialize( |
|
| 3192 | - call_user_func( |
|
| 3193 | - array( $this, $method_name_for_getting_query_params ), |
|
| 3194 | - EEH_Array::is_set( |
|
| 3195 | - $this->_req_data, |
|
| 3196 | - 'filters', |
|
| 3197 | - array() |
|
| 3198 | - ) |
|
| 3199 | - ) |
|
| 3200 | - ) |
|
| 3201 | - ), |
|
| 3202 | - 'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false), |
|
| 3203 | - 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'), |
|
| 3204 | - 'return_url' => urlencode($this->_req_data['return_url']), |
|
| 3205 | - ))); |
|
| 3206 | - } else { |
|
| 3207 | - $new_request_args = array( |
|
| 3208 | - 'export' => 'report', |
|
| 3209 | - 'action' => 'registrations_report_for_event', |
|
| 3210 | - 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null, |
|
| 3211 | - ); |
|
| 3212 | - $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
| 3213 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 3214 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 3215 | - $EE_Export = EE_Export::instance($this->_req_data); |
|
| 3216 | - $EE_Export->export(); |
|
| 3217 | - } |
|
| 3218 | - } |
|
| 3219 | - } |
|
| 3220 | - |
|
| 3221 | - |
|
| 3222 | - |
|
| 3223 | - /** |
|
| 3224 | - * Creates a registration report using only query parameters in the request |
|
| 3225 | - * @return void |
|
| 3226 | - */ |
|
| 3227 | - public function _registrations_report() |
|
| 3228 | - { |
|
| 3229 | - $this->_registrations_report_base('_get_registration_query_parameters'); |
|
| 3230 | - } |
|
| 3231 | - |
|
| 3232 | - |
|
| 3233 | - public function _contact_list_export() |
|
| 3234 | - { |
|
| 3235 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 3236 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 3237 | - $EE_Export = EE_Export::instance($this->_req_data); |
|
| 3238 | - $EE_Export->export_attendees(); |
|
| 3239 | - } |
|
| 3240 | - } |
|
| 3241 | - |
|
| 3242 | - |
|
| 3243 | - public function _contact_list_report() |
|
| 3244 | - { |
|
| 3245 | - if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) { |
|
| 3246 | - wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 3247 | - 'page' => 'espresso_batch', |
|
| 3248 | - 'batch' => 'file', |
|
| 3249 | - 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'), |
|
| 3250 | - 'return_url' => urlencode($this->_req_data['return_url']), |
|
| 3251 | - ))); |
|
| 3252 | - } else { |
|
| 3253 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 3254 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 3255 | - $EE_Export = EE_Export::instance($this->_req_data); |
|
| 3256 | - $EE_Export->report_attendees(); |
|
| 3257 | - } |
|
| 3258 | - } |
|
| 3259 | - } |
|
| 3260 | - |
|
| 3261 | - |
|
| 3262 | - |
|
| 3263 | - |
|
| 3264 | - |
|
| 3265 | - /*************************************** ATTENDEE DETAILS ***************************************/ |
|
| 3266 | - /** |
|
| 3267 | - * This duplicates the attendee object for the given incoming registration id and attendee_id. |
|
| 3268 | - * |
|
| 3269 | - * @return void |
|
| 3270 | - * @throws EE_Error |
|
| 3271 | - */ |
|
| 3272 | - protected function _duplicate_attendee() |
|
| 3273 | - { |
|
| 3274 | - $action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default'; |
|
| 3275 | - //verify we have necessary info |
|
| 3276 | - if (empty($this->_req_data['_REG_ID'])) { |
|
| 3277 | - EE_Error::add_error( |
|
| 3278 | - esc_html__( |
|
| 3279 | - 'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )', |
|
| 3280 | - 'event_espresso' |
|
| 3281 | - ), __FILE__, __LINE__, __FUNCTION__ |
|
| 3282 | - ); |
|
| 3283 | - $query_args = array('action' => $action); |
|
| 3284 | - $this->_redirect_after_action('', '', '', $query_args, true); |
|
| 3285 | - } |
|
| 3286 | - //okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration. |
|
| 3287 | - $registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']); |
|
| 3288 | - $attendee = $registration->attendee(); |
|
| 3289 | - //remove relation of existing attendee on registration |
|
| 3290 | - $registration->_remove_relation_to($attendee, 'Attendee'); |
|
| 3291 | - //new attendee |
|
| 3292 | - $new_attendee = clone $attendee; |
|
| 3293 | - $new_attendee->set('ATT_ID', 0); |
|
| 3294 | - $new_attendee->save(); |
|
| 3295 | - //add new attendee to reg |
|
| 3296 | - $registration->_add_relation_to($new_attendee, 'Attendee'); |
|
| 3297 | - EE_Error::add_success( |
|
| 3298 | - esc_html__( |
|
| 3299 | - 'New Contact record created. Now make any edits you wish to make for this contact.', |
|
| 3300 | - 'event_espresso' |
|
| 3301 | - ) |
|
| 3302 | - ); |
|
| 3303 | - //redirect to edit page for attendee |
|
| 3304 | - $query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee'); |
|
| 3305 | - $this->_redirect_after_action('', '', '', $query_args, true); |
|
| 3306 | - } |
|
| 3307 | - |
|
| 3308 | - |
|
| 3309 | - //related to cpt routes |
|
| 3310 | - protected function _insert_update_cpt_item($post_id, $post) |
|
| 3311 | - { |
|
| 3312 | - $success = true; |
|
| 3313 | - $attendee = EEM_Attendee::instance()->get_one_by_ID($post_id); |
|
| 3314 | - //for attendee updates |
|
| 3315 | - if ($post->post_type = 'espresso_attendees' && ! empty($attendee)) { |
|
| 3316 | - //note we should only be UPDATING attendees at this point. |
|
| 3317 | - $updated_fields = array( |
|
| 3318 | - 'ATT_fname' => $this->_req_data['ATT_fname'], |
|
| 3319 | - 'ATT_lname' => $this->_req_data['ATT_lname'], |
|
| 3320 | - 'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'], |
|
| 3321 | - 'ATT_address' => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '', |
|
| 3322 | - 'ATT_address2' => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '', |
|
| 3323 | - 'ATT_city' => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '', |
|
| 3324 | - 'STA_ID' => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '', |
|
| 3325 | - 'CNT_ISO' => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '', |
|
| 3326 | - 'ATT_zip' => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '', |
|
| 3327 | - 'ATT_email' => isset($this->_req_data['ATT_email']) ? $this->_req_data['ATT_email'] : '', |
|
| 3328 | - 'ATT_phone' => isset($this->_req_data['ATT_phone']) ? $this->_req_data['ATT_phone'] : '', |
|
| 3329 | - ); |
|
| 3330 | - foreach ($updated_fields as $field => $value) { |
|
| 3331 | - $attendee->set($field, $value); |
|
| 3332 | - } |
|
| 3333 | - $success = $attendee->save(); |
|
| 3334 | - $attendee_update_callbacks = apply_filters( |
|
| 3335 | - 'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update', |
|
| 3336 | - array() |
|
| 3337 | - ); |
|
| 3338 | - foreach ($attendee_update_callbacks as $a_callback) { |
|
| 3339 | - if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) { |
|
| 3340 | - throw new EE_Error( |
|
| 3341 | - sprintf( |
|
| 3342 | - esc_html__( |
|
| 3343 | - 'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback. Please check the spelling.', |
|
| 3344 | - 'event_espresso' |
|
| 3345 | - ), |
|
| 3346 | - $a_callback |
|
| 3347 | - ) |
|
| 3348 | - ); |
|
| 3349 | - } |
|
| 3350 | - } |
|
| 3351 | - } |
|
| 3352 | - if ($success === false) { |
|
| 3353 | - EE_Error::add_error( |
|
| 3354 | - esc_html__( |
|
| 3355 | - 'Something went wrong with updating the meta table data for the registration.', |
|
| 3356 | - 'event_espresso' |
|
| 3357 | - ), |
|
| 3358 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 3359 | - ); |
|
| 3360 | - } |
|
| 3361 | - } |
|
| 3362 | - |
|
| 3363 | - |
|
| 3364 | - public function trash_cpt_item($post_id) |
|
| 3365 | - { |
|
| 3366 | - } |
|
| 3367 | - |
|
| 3368 | - |
|
| 3369 | - public function delete_cpt_item($post_id) |
|
| 3370 | - { |
|
| 3371 | - } |
|
| 3372 | - |
|
| 3373 | - |
|
| 3374 | - public function restore_cpt_item($post_id) |
|
| 3375 | - { |
|
| 3376 | - } |
|
| 3377 | - |
|
| 3378 | - |
|
| 3379 | - protected function _restore_cpt_item($post_id, $revision_id) |
|
| 3380 | - { |
|
| 3381 | - } |
|
| 3382 | - |
|
| 3383 | - |
|
| 3384 | - public function attendee_editor_metaboxes() |
|
| 3385 | - { |
|
| 3386 | - $this->verify_cpt_object(); |
|
| 3387 | - remove_meta_box( |
|
| 3388 | - 'postexcerpt', |
|
| 3389 | - esc_html__('Excerpt', 'event_espresso'), |
|
| 3390 | - 'post_excerpt_meta_box', |
|
| 3391 | - $this->_cpt_routes[$this->_req_action], |
|
| 3392 | - 'normal', |
|
| 3393 | - 'core' |
|
| 3394 | - ); |
|
| 3395 | - remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core'); |
|
| 3396 | - if (post_type_supports('espresso_attendees', 'excerpt')) { |
|
| 3397 | - add_meta_box( |
|
| 3398 | - 'postexcerpt', |
|
| 3399 | - esc_html__('Short Biography', 'event_espresso'), |
|
| 3400 | - 'post_excerpt_meta_box', |
|
| 3401 | - $this->_cpt_routes[$this->_req_action], |
|
| 3402 | - 'normal' |
|
| 3403 | - ); |
|
| 3404 | - } |
|
| 3405 | - if (post_type_supports('espresso_attendees', 'comments')) { |
|
| 3406 | - add_meta_box( |
|
| 3407 | - 'commentsdiv', |
|
| 3408 | - esc_html__('Notes on the Contact', 'event_espresso'), |
|
| 3409 | - 'post_comment_meta_box', |
|
| 3410 | - $this->_cpt_routes[$this->_req_action], |
|
| 3411 | - 'normal', |
|
| 3412 | - 'core' |
|
| 3413 | - ); |
|
| 3414 | - } |
|
| 3415 | - add_meta_box( |
|
| 3416 | - 'attendee_contact_info', |
|
| 3417 | - esc_html__('Contact Info', 'event_espresso'), |
|
| 3418 | - array($this, 'attendee_contact_info'), |
|
| 3419 | - $this->_cpt_routes[$this->_req_action], |
|
| 3420 | - 'side', |
|
| 3421 | - 'core' |
|
| 3422 | - ); |
|
| 3423 | - add_meta_box( |
|
| 3424 | - 'attendee_details_address', |
|
| 3425 | - esc_html__('Address Details', 'event_espresso'), |
|
| 3426 | - array($this, 'attendee_address_details'), |
|
| 3427 | - $this->_cpt_routes[$this->_req_action], |
|
| 3428 | - 'normal', |
|
| 3429 | - 'core' |
|
| 3430 | - ); |
|
| 3431 | - add_meta_box( |
|
| 3432 | - 'attendee_registrations', |
|
| 3433 | - esc_html__('Registrations for this Contact', 'event_espresso'), |
|
| 3434 | - array($this, 'attendee_registrations_meta_box'), |
|
| 3435 | - $this->_cpt_routes[$this->_req_action], |
|
| 3436 | - 'normal', |
|
| 3437 | - 'high' |
|
| 3438 | - ); |
|
| 3439 | - } |
|
| 3440 | - |
|
| 3441 | - |
|
| 3442 | - /** |
|
| 3443 | - * Metabox for attendee contact info |
|
| 3444 | - * |
|
| 3445 | - * @param WP_Post $post wp post object |
|
| 3446 | - * @return string attendee contact info ( and form ) |
|
| 3447 | - * @throws DomainException |
|
| 3448 | - */ |
|
| 3449 | - public function attendee_contact_info($post) |
|
| 3450 | - { |
|
| 3451 | - //get attendee object ( should already have it ) |
|
| 3452 | - $this->_template_args['attendee'] = $this->_cpt_model_obj; |
|
| 3453 | - $template = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php'; |
|
| 3454 | - EEH_Template::display_template($template, $this->_template_args); |
|
| 3455 | - } |
|
| 3456 | - |
|
| 3457 | - |
|
| 3458 | - /** |
|
| 3459 | - * Metabox for attendee details |
|
| 3460 | - * |
|
| 3461 | - * @param WP_Post $post wp post object |
|
| 3462 | - * @return string attendee address details (and form) |
|
| 3463 | - * @throws DomainException |
|
| 3464 | - */ |
|
| 3465 | - public function attendee_address_details($post) |
|
| 3466 | - { |
|
| 3467 | - //get attendee object (should already have it) |
|
| 3468 | - $this->_template_args['attendee'] = $this->_cpt_model_obj; |
|
| 3469 | - $this->_template_args['state_html'] = EEH_Form_Fields::generate_form_input( |
|
| 3470 | - new EE_Question_Form_Input( |
|
| 3471 | - EE_Question::new_instance( |
|
| 3472 | - array( |
|
| 3473 | - 'QST_ID' => 0, |
|
| 3474 | - 'QST_display_text' => esc_html__('State/Province', 'event_espresso'), |
|
| 3475 | - 'QST_system' => 'admin-state', |
|
| 3476 | - ) |
|
| 3477 | - ), |
|
| 3478 | - EE_Answer::new_instance( |
|
| 3479 | - array( |
|
| 3480 | - 'ANS_ID' => 0, |
|
| 3481 | - 'ANS_value' => $this->_cpt_model_obj->state_ID(), |
|
| 3482 | - ) |
|
| 3483 | - ), |
|
| 3484 | - array( |
|
| 3485 | - 'input_id' => 'STA_ID', |
|
| 3486 | - 'input_name' => 'STA_ID', |
|
| 3487 | - 'input_prefix' => '', |
|
| 3488 | - 'append_qstn_id' => false, |
|
| 3489 | - ) |
|
| 3490 | - ) |
|
| 3491 | - ); |
|
| 3492 | - $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input( |
|
| 3493 | - new EE_Question_Form_Input( |
|
| 3494 | - EE_Question::new_instance( |
|
| 3495 | - array( |
|
| 3496 | - 'QST_ID' => 0, |
|
| 3497 | - 'QST_display_text' => esc_html__('Country', 'event_espresso'), |
|
| 3498 | - 'QST_system' => 'admin-country', |
|
| 3499 | - ) |
|
| 3500 | - ), |
|
| 3501 | - EE_Answer::new_instance( |
|
| 3502 | - array( |
|
| 3503 | - 'ANS_ID' => 0, |
|
| 3504 | - 'ANS_value' => $this->_cpt_model_obj->country_ID(), |
|
| 3505 | - ) |
|
| 3506 | - ), |
|
| 3507 | - array( |
|
| 3508 | - 'input_id' => 'CNT_ISO', |
|
| 3509 | - 'input_name' => 'CNT_ISO', |
|
| 3510 | - 'input_prefix' => '', |
|
| 3511 | - 'append_qstn_id' => false, |
|
| 3512 | - ) |
|
| 3513 | - ) |
|
| 3514 | - ); |
|
| 3515 | - $template = |
|
| 3516 | - REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php'; |
|
| 3517 | - EEH_Template::display_template($template, $this->_template_args); |
|
| 3518 | - } |
|
| 3519 | - |
|
| 3520 | - |
|
| 3521 | - /** |
|
| 3522 | - * _attendee_details |
|
| 3523 | - * |
|
| 3524 | - * @access protected |
|
| 3525 | - * @param $post |
|
| 3526 | - * @return void |
|
| 3527 | - * @throws DomainException |
|
| 3528 | - * @throws EE_Error |
|
| 3529 | - */ |
|
| 3530 | - public function attendee_registrations_meta_box($post) |
|
| 3531 | - { |
|
| 3532 | - $this->_template_args['attendee'] = $this->_cpt_model_obj; |
|
| 3533 | - $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration'); |
|
| 3534 | - $template = |
|
| 3535 | - REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php'; |
|
| 3536 | - EEH_Template::display_template($template, $this->_template_args); |
|
| 3537 | - } |
|
| 3538 | - |
|
| 3539 | - |
|
| 3540 | - /** |
|
| 3541 | - * add in the form fields for the attendee edit |
|
| 3542 | - * |
|
| 3543 | - * @param WP_Post $post wp post object |
|
| 3544 | - * @return string html for new form. |
|
| 3545 | - * @throws DomainException |
|
| 3546 | - */ |
|
| 3547 | - public function after_title_form_fields($post) |
|
| 3548 | - { |
|
| 3549 | - if ($post->post_type == 'espresso_attendees') { |
|
| 3550 | - $template = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php'; |
|
| 3551 | - $template_args['attendee'] = $this->_cpt_model_obj; |
|
| 3552 | - EEH_Template::display_template($template, $template_args); |
|
| 3553 | - } |
|
| 3554 | - } |
|
| 3555 | - |
|
| 3556 | - |
|
| 3557 | - /** |
|
| 3558 | - * _trash_or_restore_attendee |
|
| 3559 | - * |
|
| 3560 | - * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE) |
|
| 3561 | - * @return void |
|
| 3562 | - * @throws EE_Error |
|
| 3563 | - * @access protected |
|
| 3564 | - */ |
|
| 3565 | - protected function _trash_or_restore_attendees($trash = true) |
|
| 3566 | - { |
|
| 3567 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3568 | - $ATT_MDL = EEM_Attendee::instance(); |
|
| 3569 | - $success = 1; |
|
| 3570 | - //Checkboxes |
|
| 3571 | - if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 3572 | - // if array has more than one element than success message should be plural |
|
| 3573 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 3574 | - // cycle thru checkboxes |
|
| 3575 | - while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 3576 | - $updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID) |
|
| 3577 | - : $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID); |
|
| 3578 | - if ( ! $updated) { |
|
| 3579 | - $success = 0; |
|
| 3580 | - } |
|
| 3581 | - } |
|
| 3582 | - } else { |
|
| 3583 | - // grab single id and delete |
|
| 3584 | - $ATT_ID = absint($this->_req_data['ATT_ID']); |
|
| 3585 | - //get attendee |
|
| 3586 | - $att = $ATT_MDL->get_one_by_ID($ATT_ID); |
|
| 3587 | - $updated = $trash ? $att->set_status('trash') : $att->set_status('publish'); |
|
| 3588 | - $updated = $att->save(); |
|
| 3589 | - if ( ! $updated) { |
|
| 3590 | - $success = 0; |
|
| 3591 | - } |
|
| 3592 | - } |
|
| 3593 | - $what = $success > 1 |
|
| 3594 | - ? esc_html__('Contacts', 'event_espresso') |
|
| 3595 | - : esc_html__('Contact', 'event_espresso'); |
|
| 3596 | - $action_desc = $trash |
|
| 3597 | - ? esc_html__('moved to the trash', 'event_espresso') |
|
| 3598 | - : esc_html__('restored', 'event_espresso'); |
|
| 3599 | - $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list')); |
|
| 3600 | - } |
|
| 2814 | + } |
|
| 2815 | + $template_args = array( |
|
| 2816 | + 'title' => '', |
|
| 2817 | + 'content' => '', |
|
| 2818 | + 'step_button_text' => '', |
|
| 2819 | + 'show_notification_toggle' => false, |
|
| 2820 | + ); |
|
| 2821 | + //to indicate we're processing a new registration |
|
| 2822 | + $hidden_fields = array( |
|
| 2823 | + 'processing_registration' => array( |
|
| 2824 | + 'type' => 'hidden', |
|
| 2825 | + 'value' => 0, |
|
| 2826 | + ), |
|
| 2827 | + 'event_id' => array( |
|
| 2828 | + 'type' => 'hidden', |
|
| 2829 | + 'value' => $this->_reg_event->ID(), |
|
| 2830 | + ), |
|
| 2831 | + ); |
|
| 2832 | + //if the cart is empty then we know we're at step one so we'll display ticket selector |
|
| 2833 | + $cart = EE_Registry::instance()->SSN->cart(); |
|
| 2834 | + $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions'; |
|
| 2835 | + switch ($step) { |
|
| 2836 | + case 'ticket' : |
|
| 2837 | + $hidden_fields['processing_registration']['value'] = 1; |
|
| 2838 | + $template_args['title'] = esc_html__( |
|
| 2839 | + 'Step One: Select the Ticket for this registration', |
|
| 2840 | + 'event_espresso' |
|
| 2841 | + ); |
|
| 2842 | + $template_args['content'] = |
|
| 2843 | + EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event); |
|
| 2844 | + $template_args['step_button_text'] = esc_html__( |
|
| 2845 | + 'Add Tickets and Continue to Registrant Details', |
|
| 2846 | + 'event_espresso' |
|
| 2847 | + ); |
|
| 2848 | + $template_args['show_notification_toggle'] = false; |
|
| 2849 | + break; |
|
| 2850 | + case 'questions' : |
|
| 2851 | + $hidden_fields['processing_registration']['value'] = 2; |
|
| 2852 | + $template_args['title'] = esc_html__( |
|
| 2853 | + 'Step Two: Add Registrant Details for this Registration', |
|
| 2854 | + 'event_espresso' |
|
| 2855 | + ); |
|
| 2856 | + //in theory we should be able to run EED_SPCO at this point because the cart should have been setup |
|
| 2857 | + // properly by the first process_reg_step run. |
|
| 2858 | + $template_args['content'] = |
|
| 2859 | + EED_Single_Page_Checkout::registration_checkout_for_admin(); |
|
| 2860 | + $template_args['step_button_text'] = esc_html__( |
|
| 2861 | + 'Save Registration and Continue to Details', |
|
| 2862 | + 'event_espresso' |
|
| 2863 | + ); |
|
| 2864 | + $template_args['show_notification_toggle'] = true; |
|
| 2865 | + break; |
|
| 2866 | + } |
|
| 2867 | + //we come back to the process_registration_step route. |
|
| 2868 | + $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields); |
|
| 2869 | + return EEH_Template::display_template( |
|
| 2870 | + REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php', |
|
| 2871 | + $template_args, |
|
| 2872 | + true |
|
| 2873 | + ); |
|
| 2874 | + } |
|
| 2875 | + |
|
| 2876 | + |
|
| 2877 | + /** |
|
| 2878 | + * set_reg_event |
|
| 2879 | + * |
|
| 2880 | + * @access private |
|
| 2881 | + * @return bool |
|
| 2882 | + * @throws EE_Error |
|
| 2883 | + */ |
|
| 2884 | + private function _set_reg_event() |
|
| 2885 | + { |
|
| 2886 | + if (is_object($this->_reg_event)) { |
|
| 2887 | + return true; |
|
| 2888 | + } |
|
| 2889 | + $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false; |
|
| 2890 | + if ( ! $EVT_ID) { |
|
| 2891 | + return false; |
|
| 2892 | + } |
|
| 2893 | + $this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2894 | + return true; |
|
| 2895 | + } |
|
| 2896 | + |
|
| 2897 | + |
|
| 2898 | + /** |
|
| 2899 | + * process_reg_step |
|
| 2900 | + * |
|
| 2901 | + * @access public |
|
| 2902 | + * @return string |
|
| 2903 | + * @throws DomainException |
|
| 2904 | + * @throws EE_Error |
|
| 2905 | + * @throws RuntimeException |
|
| 2906 | + */ |
|
| 2907 | + public function process_reg_step() |
|
| 2908 | + { |
|
| 2909 | + EE_System::do_not_cache(); |
|
| 2910 | + $this->_set_reg_event(); |
|
| 2911 | + EE_Registry::instance()->REQ->set_espresso_page(true); |
|
| 2912 | + EE_Registry::instance()->REQ->set('uts', time()); |
|
| 2913 | + //what step are we on? |
|
| 2914 | + $cart = EE_Registry::instance()->SSN->cart(); |
|
| 2915 | + $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions'; |
|
| 2916 | + //if doing ajax then we need to verify the nonce |
|
| 2917 | + if (defined('DOING_AJAX')) { |
|
| 2918 | + $nonce = isset($this->_req_data[$this->_req_nonce]) |
|
| 2919 | + ? sanitize_text_field($this->_req_data[$this->_req_nonce]) : ''; |
|
| 2920 | + $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 2921 | + } |
|
| 2922 | + switch ($step) { |
|
| 2923 | + case 'ticket' : |
|
| 2924 | + //process ticket selection |
|
| 2925 | + $success = EED_Ticket_Selector::instance()->process_ticket_selections(); |
|
| 2926 | + if ($success) { |
|
| 2927 | + EE_Error::add_success( |
|
| 2928 | + esc_html__( |
|
| 2929 | + 'Tickets Selected. Now complete the registration.', |
|
| 2930 | + 'event_espresso' |
|
| 2931 | + ) |
|
| 2932 | + ); |
|
| 2933 | + } else { |
|
| 2934 | + $query_args['step_error'] = $this->_req_data['step_error'] = true; |
|
| 2935 | + } |
|
| 2936 | + if (defined('DOING_AJAX')) { |
|
| 2937 | + $this->new_registration(); //display next step |
|
| 2938 | + } else { |
|
| 2939 | + $query_args = array( |
|
| 2940 | + 'action' => 'new_registration', |
|
| 2941 | + 'processing_registration' => 1, |
|
| 2942 | + 'event_id' => $this->_reg_event->ID(), |
|
| 2943 | + 'uts' => time(), |
|
| 2944 | + ); |
|
| 2945 | + $this->_redirect_after_action( |
|
| 2946 | + false, |
|
| 2947 | + '', |
|
| 2948 | + '', |
|
| 2949 | + $query_args, |
|
| 2950 | + true |
|
| 2951 | + ); |
|
| 2952 | + } |
|
| 2953 | + break; |
|
| 2954 | + case 'questions' : |
|
| 2955 | + if (! isset( |
|
| 2956 | + $this->_req_data['txn_reg_status_change'], |
|
| 2957 | + $this->_req_data['txn_reg_status_change']['send_notifications']) |
|
| 2958 | + ) { |
|
| 2959 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15); |
|
| 2960 | + } |
|
| 2961 | + //process registration |
|
| 2962 | + $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin(); |
|
| 2963 | + if ($cart instanceof EE_Cart) { |
|
| 2964 | + $grand_total = $cart->get_cart_grand_total(); |
|
| 2965 | + if ($grand_total instanceof EE_Line_Item) { |
|
| 2966 | + $grand_total->save_this_and_descendants_to_txn(); |
|
| 2967 | + } |
|
| 2968 | + } |
|
| 2969 | + if ( ! $transaction instanceof EE_Transaction) { |
|
| 2970 | + $query_args = array( |
|
| 2971 | + 'action' => 'new_registration', |
|
| 2972 | + 'processing_registration' => 2, |
|
| 2973 | + 'event_id' => $this->_reg_event->ID(), |
|
| 2974 | + 'uts' => time(), |
|
| 2975 | + ); |
|
| 2976 | + if (defined('DOING_AJAX')) { |
|
| 2977 | + //display registration form again because there are errors (maybe validation?) |
|
| 2978 | + $this->new_registration(); |
|
| 2979 | + return; |
|
| 2980 | + } else { |
|
| 2981 | + $this->_redirect_after_action( |
|
| 2982 | + false, |
|
| 2983 | + '', |
|
| 2984 | + '', |
|
| 2985 | + $query_args, |
|
| 2986 | + true |
|
| 2987 | + ); |
|
| 2988 | + return; |
|
| 2989 | + } |
|
| 2990 | + } |
|
| 2991 | + // maybe update status, and make sure to save transaction if not done already |
|
| 2992 | + if ( ! $transaction->update_status_based_on_total_paid()) { |
|
| 2993 | + $transaction->save(); |
|
| 2994 | + } |
|
| 2995 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 2996 | + $this->_req_data = array(); |
|
| 2997 | + $query_args = array( |
|
| 2998 | + 'action' => 'redirect_to_txn', |
|
| 2999 | + 'TXN_ID' => $transaction->ID(), |
|
| 3000 | + 'EVT_ID' => $this->_reg_event->ID(), |
|
| 3001 | + 'event_name' => urlencode($this->_reg_event->name()), |
|
| 3002 | + 'redirect_from' => 'new_registration', |
|
| 3003 | + ); |
|
| 3004 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 3005 | + break; |
|
| 3006 | + } |
|
| 3007 | + //what are you looking here for? Should be nothing to do at this point. |
|
| 3008 | + } |
|
| 3009 | + |
|
| 3010 | + |
|
| 3011 | + /** |
|
| 3012 | + * redirect_to_txn |
|
| 3013 | + * |
|
| 3014 | + * @access public |
|
| 3015 | + * @return void |
|
| 3016 | + * @throws EE_Error |
|
| 3017 | + */ |
|
| 3018 | + public function redirect_to_txn() |
|
| 3019 | + { |
|
| 3020 | + EE_System::do_not_cache(); |
|
| 3021 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 3022 | + $query_args = array( |
|
| 3023 | + 'action' => 'view_transaction', |
|
| 3024 | + 'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0, |
|
| 3025 | + 'page' => 'espresso_transactions', |
|
| 3026 | + ); |
|
| 3027 | + if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) { |
|
| 3028 | + $query_args['EVT_ID'] = $this->_req_data['EVT_ID']; |
|
| 3029 | + $query_args['event_name'] = urlencode($this->_req_data['event_name']); |
|
| 3030 | + $query_args['redirect_from'] = $this->_req_data['redirect_from']; |
|
| 3031 | + } |
|
| 3032 | + EE_Error::add_success( |
|
| 3033 | + esc_html__( |
|
| 3034 | + 'Registration Created. Please review the transaction and add any payments as necessary', |
|
| 3035 | + 'event_espresso' |
|
| 3036 | + ) |
|
| 3037 | + ); |
|
| 3038 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 3039 | + } |
|
| 3040 | + |
|
| 3041 | + |
|
| 3042 | + /** |
|
| 3043 | + * generates HTML for the Attendee Contact List |
|
| 3044 | + * |
|
| 3045 | + * @access protected |
|
| 3046 | + * @return void |
|
| 3047 | + */ |
|
| 3048 | + protected function _attendee_contact_list_table() |
|
| 3049 | + { |
|
| 3050 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3051 | + $this->_search_btn_label = esc_html__('Contacts', 'event_espresso'); |
|
| 3052 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 3053 | + } |
|
| 3054 | + |
|
| 3055 | + |
|
| 3056 | + /** |
|
| 3057 | + * get_attendees |
|
| 3058 | + * |
|
| 3059 | + * @param $per_page |
|
| 3060 | + * @param bool $count whether to return count or data. |
|
| 3061 | + * @param bool $trash |
|
| 3062 | + * @return array |
|
| 3063 | + * @throws EE_Error |
|
| 3064 | + * @access public |
|
| 3065 | + */ |
|
| 3066 | + public function get_attendees($per_page, $count = false, $trash = false) |
|
| 3067 | + { |
|
| 3068 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3069 | + require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php'); |
|
| 3070 | + $ATT_MDL = EEM_Attendee::instance(); |
|
| 3071 | + $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
|
| 3072 | + switch ($this->_req_data['orderby']) { |
|
| 3073 | + case 'ATT_ID': |
|
| 3074 | + $orderby = 'ATT_ID'; |
|
| 3075 | + break; |
|
| 3076 | + case 'ATT_fname': |
|
| 3077 | + $orderby = 'ATT_fname'; |
|
| 3078 | + break; |
|
| 3079 | + case 'ATT_email': |
|
| 3080 | + $orderby = 'ATT_email'; |
|
| 3081 | + break; |
|
| 3082 | + case 'ATT_city': |
|
| 3083 | + $orderby = 'ATT_city'; |
|
| 3084 | + break; |
|
| 3085 | + case 'STA_ID': |
|
| 3086 | + $orderby = 'STA_ID'; |
|
| 3087 | + break; |
|
| 3088 | + case 'CNT_ID': |
|
| 3089 | + $orderby = 'CNT_ID'; |
|
| 3090 | + break; |
|
| 3091 | + default: |
|
| 3092 | + $orderby = 'ATT_lname'; |
|
| 3093 | + } |
|
| 3094 | + $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) |
|
| 3095 | + ? $this->_req_data['order'] |
|
| 3096 | + : 'ASC'; |
|
| 3097 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 3098 | + ? $this->_req_data['paged'] |
|
| 3099 | + : 1; |
|
| 3100 | + $per_page = isset($per_page) && ! empty($per_page) ? $per_page : 10; |
|
| 3101 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 3102 | + ? $this->_req_data['perpage'] |
|
| 3103 | + : $per_page; |
|
| 3104 | + $_where = array(); |
|
| 3105 | + if ( ! empty($this->_req_data['s'])) { |
|
| 3106 | + $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 3107 | + $_where['OR'] = array( |
|
| 3108 | + 'Registration.Event.EVT_name' => array('LIKE', $sstr), |
|
| 3109 | + 'Registration.Event.EVT_desc' => array('LIKE', $sstr), |
|
| 3110 | + 'Registration.Event.EVT_short_desc' => array('LIKE', $sstr), |
|
| 3111 | + 'ATT_fname' => array('LIKE', $sstr), |
|
| 3112 | + 'ATT_lname' => array('LIKE', $sstr), |
|
| 3113 | + 'ATT_short_bio' => array('LIKE', $sstr), |
|
| 3114 | + 'ATT_email' => array('LIKE', $sstr), |
|
| 3115 | + 'ATT_address' => array('LIKE', $sstr), |
|
| 3116 | + 'ATT_address2' => array('LIKE', $sstr), |
|
| 3117 | + 'ATT_city' => array('LIKE', $sstr), |
|
| 3118 | + 'Country.CNT_name' => array('LIKE', $sstr), |
|
| 3119 | + 'State.STA_name' => array('LIKE', $sstr), |
|
| 3120 | + 'ATT_phone' => array('LIKE', $sstr), |
|
| 3121 | + 'Registration.REG_final_price' => array('LIKE', $sstr), |
|
| 3122 | + 'Registration.REG_code' => array('LIKE', $sstr), |
|
| 3123 | + 'Registration.REG_count' => array('LIKE', $sstr), |
|
| 3124 | + 'Registration.REG_group_size' => array('LIKE', $sstr), |
|
| 3125 | + ); |
|
| 3126 | + } |
|
| 3127 | + $offset = ($current_page - 1) * $per_page; |
|
| 3128 | + $limit = $count ? null : array($offset, $per_page); |
|
| 3129 | + if ($trash) { |
|
| 3130 | + $_where['status'] = array('!=', 'publish'); |
|
| 3131 | + $all_attendees = $count |
|
| 3132 | + ? $ATT_MDL->count(array( |
|
| 3133 | + $_where, |
|
| 3134 | + 'order_by' => array($orderby => $sort), |
|
| 3135 | + 'limit' => $limit, |
|
| 3136 | + ), 'ATT_ID', true) |
|
| 3137 | + : $ATT_MDL->get_all(array( |
|
| 3138 | + $_where, |
|
| 3139 | + 'order_by' => array($orderby => $sort), |
|
| 3140 | + 'limit' => $limit, |
|
| 3141 | + )); |
|
| 3142 | + } else { |
|
| 3143 | + $_where['status'] = array('IN', array('publish')); |
|
| 3144 | + $all_attendees = $count |
|
| 3145 | + ? $ATT_MDL->count(array( |
|
| 3146 | + $_where, |
|
| 3147 | + 'order_by' => array($orderby => $sort), |
|
| 3148 | + 'limit' => $limit, |
|
| 3149 | + ), 'ATT_ID', true) |
|
| 3150 | + : $ATT_MDL->get_all(array( |
|
| 3151 | + $_where, |
|
| 3152 | + 'order_by' => array($orderby => $sort), |
|
| 3153 | + 'limit' => $limit, |
|
| 3154 | + )); |
|
| 3155 | + } |
|
| 3156 | + return $all_attendees; |
|
| 3157 | + } |
|
| 3158 | + |
|
| 3159 | + |
|
| 3160 | + /** |
|
| 3161 | + * This is just taking care of resending the registration confirmation |
|
| 3162 | + * |
|
| 3163 | + * @access protected |
|
| 3164 | + * @return void |
|
| 3165 | + */ |
|
| 3166 | + protected function _resend_registration() |
|
| 3167 | + { |
|
| 3168 | + $this->_process_resend_registration(); |
|
| 3169 | + $query_args = isset($this->_req_data['redirect_to']) |
|
| 3170 | + ? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID']) |
|
| 3171 | + : array('action' => 'default'); |
|
| 3172 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 3173 | + } |
|
| 3174 | + |
|
| 3175 | + /** |
|
| 3176 | + * Creates a registration report, but accepts the name of a method to use for preparing the query parameters |
|
| 3177 | + * to use when selecting registrations |
|
| 3178 | + * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing |
|
| 3179 | + * the query parameters from the request |
|
| 3180 | + * @return void ends the request with a redirect or download |
|
| 3181 | + */ |
|
| 3182 | + public function _registrations_report_base( $method_name_for_getting_query_params ) |
|
| 3183 | + { |
|
| 3184 | + if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) { |
|
| 3185 | + wp_redirect(EE_Admin_Page::add_query_args_and_nonce( |
|
| 3186 | + array( |
|
| 3187 | + 'page' => 'espresso_batch', |
|
| 3188 | + 'batch' => 'file', |
|
| 3189 | + 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null, |
|
| 3190 | + 'filters' => urlencode( |
|
| 3191 | + serialize( |
|
| 3192 | + call_user_func( |
|
| 3193 | + array( $this, $method_name_for_getting_query_params ), |
|
| 3194 | + EEH_Array::is_set( |
|
| 3195 | + $this->_req_data, |
|
| 3196 | + 'filters', |
|
| 3197 | + array() |
|
| 3198 | + ) |
|
| 3199 | + ) |
|
| 3200 | + ) |
|
| 3201 | + ), |
|
| 3202 | + 'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false), |
|
| 3203 | + 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'), |
|
| 3204 | + 'return_url' => urlencode($this->_req_data['return_url']), |
|
| 3205 | + ))); |
|
| 3206 | + } else { |
|
| 3207 | + $new_request_args = array( |
|
| 3208 | + 'export' => 'report', |
|
| 3209 | + 'action' => 'registrations_report_for_event', |
|
| 3210 | + 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null, |
|
| 3211 | + ); |
|
| 3212 | + $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
| 3213 | + if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 3214 | + require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 3215 | + $EE_Export = EE_Export::instance($this->_req_data); |
|
| 3216 | + $EE_Export->export(); |
|
| 3217 | + } |
|
| 3218 | + } |
|
| 3219 | + } |
|
| 3220 | + |
|
| 3221 | + |
|
| 3222 | + |
|
| 3223 | + /** |
|
| 3224 | + * Creates a registration report using only query parameters in the request |
|
| 3225 | + * @return void |
|
| 3226 | + */ |
|
| 3227 | + public function _registrations_report() |
|
| 3228 | + { |
|
| 3229 | + $this->_registrations_report_base('_get_registration_query_parameters'); |
|
| 3230 | + } |
|
| 3231 | + |
|
| 3232 | + |
|
| 3233 | + public function _contact_list_export() |
|
| 3234 | + { |
|
| 3235 | + if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 3236 | + require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 3237 | + $EE_Export = EE_Export::instance($this->_req_data); |
|
| 3238 | + $EE_Export->export_attendees(); |
|
| 3239 | + } |
|
| 3240 | + } |
|
| 3241 | + |
|
| 3242 | + |
|
| 3243 | + public function _contact_list_report() |
|
| 3244 | + { |
|
| 3245 | + if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) { |
|
| 3246 | + wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 3247 | + 'page' => 'espresso_batch', |
|
| 3248 | + 'batch' => 'file', |
|
| 3249 | + 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'), |
|
| 3250 | + 'return_url' => urlencode($this->_req_data['return_url']), |
|
| 3251 | + ))); |
|
| 3252 | + } else { |
|
| 3253 | + if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 3254 | + require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 3255 | + $EE_Export = EE_Export::instance($this->_req_data); |
|
| 3256 | + $EE_Export->report_attendees(); |
|
| 3257 | + } |
|
| 3258 | + } |
|
| 3259 | + } |
|
| 3260 | + |
|
| 3261 | + |
|
| 3262 | + |
|
| 3263 | + |
|
| 3264 | + |
|
| 3265 | + /*************************************** ATTENDEE DETAILS ***************************************/ |
|
| 3266 | + /** |
|
| 3267 | + * This duplicates the attendee object for the given incoming registration id and attendee_id. |
|
| 3268 | + * |
|
| 3269 | + * @return void |
|
| 3270 | + * @throws EE_Error |
|
| 3271 | + */ |
|
| 3272 | + protected function _duplicate_attendee() |
|
| 3273 | + { |
|
| 3274 | + $action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default'; |
|
| 3275 | + //verify we have necessary info |
|
| 3276 | + if (empty($this->_req_data['_REG_ID'])) { |
|
| 3277 | + EE_Error::add_error( |
|
| 3278 | + esc_html__( |
|
| 3279 | + 'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )', |
|
| 3280 | + 'event_espresso' |
|
| 3281 | + ), __FILE__, __LINE__, __FUNCTION__ |
|
| 3282 | + ); |
|
| 3283 | + $query_args = array('action' => $action); |
|
| 3284 | + $this->_redirect_after_action('', '', '', $query_args, true); |
|
| 3285 | + } |
|
| 3286 | + //okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration. |
|
| 3287 | + $registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']); |
|
| 3288 | + $attendee = $registration->attendee(); |
|
| 3289 | + //remove relation of existing attendee on registration |
|
| 3290 | + $registration->_remove_relation_to($attendee, 'Attendee'); |
|
| 3291 | + //new attendee |
|
| 3292 | + $new_attendee = clone $attendee; |
|
| 3293 | + $new_attendee->set('ATT_ID', 0); |
|
| 3294 | + $new_attendee->save(); |
|
| 3295 | + //add new attendee to reg |
|
| 3296 | + $registration->_add_relation_to($new_attendee, 'Attendee'); |
|
| 3297 | + EE_Error::add_success( |
|
| 3298 | + esc_html__( |
|
| 3299 | + 'New Contact record created. Now make any edits you wish to make for this contact.', |
|
| 3300 | + 'event_espresso' |
|
| 3301 | + ) |
|
| 3302 | + ); |
|
| 3303 | + //redirect to edit page for attendee |
|
| 3304 | + $query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee'); |
|
| 3305 | + $this->_redirect_after_action('', '', '', $query_args, true); |
|
| 3306 | + } |
|
| 3307 | + |
|
| 3308 | + |
|
| 3309 | + //related to cpt routes |
|
| 3310 | + protected function _insert_update_cpt_item($post_id, $post) |
|
| 3311 | + { |
|
| 3312 | + $success = true; |
|
| 3313 | + $attendee = EEM_Attendee::instance()->get_one_by_ID($post_id); |
|
| 3314 | + //for attendee updates |
|
| 3315 | + if ($post->post_type = 'espresso_attendees' && ! empty($attendee)) { |
|
| 3316 | + //note we should only be UPDATING attendees at this point. |
|
| 3317 | + $updated_fields = array( |
|
| 3318 | + 'ATT_fname' => $this->_req_data['ATT_fname'], |
|
| 3319 | + 'ATT_lname' => $this->_req_data['ATT_lname'], |
|
| 3320 | + 'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'], |
|
| 3321 | + 'ATT_address' => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '', |
|
| 3322 | + 'ATT_address2' => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '', |
|
| 3323 | + 'ATT_city' => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '', |
|
| 3324 | + 'STA_ID' => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '', |
|
| 3325 | + 'CNT_ISO' => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '', |
|
| 3326 | + 'ATT_zip' => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '', |
|
| 3327 | + 'ATT_email' => isset($this->_req_data['ATT_email']) ? $this->_req_data['ATT_email'] : '', |
|
| 3328 | + 'ATT_phone' => isset($this->_req_data['ATT_phone']) ? $this->_req_data['ATT_phone'] : '', |
|
| 3329 | + ); |
|
| 3330 | + foreach ($updated_fields as $field => $value) { |
|
| 3331 | + $attendee->set($field, $value); |
|
| 3332 | + } |
|
| 3333 | + $success = $attendee->save(); |
|
| 3334 | + $attendee_update_callbacks = apply_filters( |
|
| 3335 | + 'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update', |
|
| 3336 | + array() |
|
| 3337 | + ); |
|
| 3338 | + foreach ($attendee_update_callbacks as $a_callback) { |
|
| 3339 | + if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) { |
|
| 3340 | + throw new EE_Error( |
|
| 3341 | + sprintf( |
|
| 3342 | + esc_html__( |
|
| 3343 | + 'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback. Please check the spelling.', |
|
| 3344 | + 'event_espresso' |
|
| 3345 | + ), |
|
| 3346 | + $a_callback |
|
| 3347 | + ) |
|
| 3348 | + ); |
|
| 3349 | + } |
|
| 3350 | + } |
|
| 3351 | + } |
|
| 3352 | + if ($success === false) { |
|
| 3353 | + EE_Error::add_error( |
|
| 3354 | + esc_html__( |
|
| 3355 | + 'Something went wrong with updating the meta table data for the registration.', |
|
| 3356 | + 'event_espresso' |
|
| 3357 | + ), |
|
| 3358 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 3359 | + ); |
|
| 3360 | + } |
|
| 3361 | + } |
|
| 3362 | + |
|
| 3363 | + |
|
| 3364 | + public function trash_cpt_item($post_id) |
|
| 3365 | + { |
|
| 3366 | + } |
|
| 3367 | + |
|
| 3368 | + |
|
| 3369 | + public function delete_cpt_item($post_id) |
|
| 3370 | + { |
|
| 3371 | + } |
|
| 3372 | + |
|
| 3373 | + |
|
| 3374 | + public function restore_cpt_item($post_id) |
|
| 3375 | + { |
|
| 3376 | + } |
|
| 3377 | + |
|
| 3378 | + |
|
| 3379 | + protected function _restore_cpt_item($post_id, $revision_id) |
|
| 3380 | + { |
|
| 3381 | + } |
|
| 3382 | + |
|
| 3383 | + |
|
| 3384 | + public function attendee_editor_metaboxes() |
|
| 3385 | + { |
|
| 3386 | + $this->verify_cpt_object(); |
|
| 3387 | + remove_meta_box( |
|
| 3388 | + 'postexcerpt', |
|
| 3389 | + esc_html__('Excerpt', 'event_espresso'), |
|
| 3390 | + 'post_excerpt_meta_box', |
|
| 3391 | + $this->_cpt_routes[$this->_req_action], |
|
| 3392 | + 'normal', |
|
| 3393 | + 'core' |
|
| 3394 | + ); |
|
| 3395 | + remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core'); |
|
| 3396 | + if (post_type_supports('espresso_attendees', 'excerpt')) { |
|
| 3397 | + add_meta_box( |
|
| 3398 | + 'postexcerpt', |
|
| 3399 | + esc_html__('Short Biography', 'event_espresso'), |
|
| 3400 | + 'post_excerpt_meta_box', |
|
| 3401 | + $this->_cpt_routes[$this->_req_action], |
|
| 3402 | + 'normal' |
|
| 3403 | + ); |
|
| 3404 | + } |
|
| 3405 | + if (post_type_supports('espresso_attendees', 'comments')) { |
|
| 3406 | + add_meta_box( |
|
| 3407 | + 'commentsdiv', |
|
| 3408 | + esc_html__('Notes on the Contact', 'event_espresso'), |
|
| 3409 | + 'post_comment_meta_box', |
|
| 3410 | + $this->_cpt_routes[$this->_req_action], |
|
| 3411 | + 'normal', |
|
| 3412 | + 'core' |
|
| 3413 | + ); |
|
| 3414 | + } |
|
| 3415 | + add_meta_box( |
|
| 3416 | + 'attendee_contact_info', |
|
| 3417 | + esc_html__('Contact Info', 'event_espresso'), |
|
| 3418 | + array($this, 'attendee_contact_info'), |
|
| 3419 | + $this->_cpt_routes[$this->_req_action], |
|
| 3420 | + 'side', |
|
| 3421 | + 'core' |
|
| 3422 | + ); |
|
| 3423 | + add_meta_box( |
|
| 3424 | + 'attendee_details_address', |
|
| 3425 | + esc_html__('Address Details', 'event_espresso'), |
|
| 3426 | + array($this, 'attendee_address_details'), |
|
| 3427 | + $this->_cpt_routes[$this->_req_action], |
|
| 3428 | + 'normal', |
|
| 3429 | + 'core' |
|
| 3430 | + ); |
|
| 3431 | + add_meta_box( |
|
| 3432 | + 'attendee_registrations', |
|
| 3433 | + esc_html__('Registrations for this Contact', 'event_espresso'), |
|
| 3434 | + array($this, 'attendee_registrations_meta_box'), |
|
| 3435 | + $this->_cpt_routes[$this->_req_action], |
|
| 3436 | + 'normal', |
|
| 3437 | + 'high' |
|
| 3438 | + ); |
|
| 3439 | + } |
|
| 3440 | + |
|
| 3441 | + |
|
| 3442 | + /** |
|
| 3443 | + * Metabox for attendee contact info |
|
| 3444 | + * |
|
| 3445 | + * @param WP_Post $post wp post object |
|
| 3446 | + * @return string attendee contact info ( and form ) |
|
| 3447 | + * @throws DomainException |
|
| 3448 | + */ |
|
| 3449 | + public function attendee_contact_info($post) |
|
| 3450 | + { |
|
| 3451 | + //get attendee object ( should already have it ) |
|
| 3452 | + $this->_template_args['attendee'] = $this->_cpt_model_obj; |
|
| 3453 | + $template = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php'; |
|
| 3454 | + EEH_Template::display_template($template, $this->_template_args); |
|
| 3455 | + } |
|
| 3456 | + |
|
| 3457 | + |
|
| 3458 | + /** |
|
| 3459 | + * Metabox for attendee details |
|
| 3460 | + * |
|
| 3461 | + * @param WP_Post $post wp post object |
|
| 3462 | + * @return string attendee address details (and form) |
|
| 3463 | + * @throws DomainException |
|
| 3464 | + */ |
|
| 3465 | + public function attendee_address_details($post) |
|
| 3466 | + { |
|
| 3467 | + //get attendee object (should already have it) |
|
| 3468 | + $this->_template_args['attendee'] = $this->_cpt_model_obj; |
|
| 3469 | + $this->_template_args['state_html'] = EEH_Form_Fields::generate_form_input( |
|
| 3470 | + new EE_Question_Form_Input( |
|
| 3471 | + EE_Question::new_instance( |
|
| 3472 | + array( |
|
| 3473 | + 'QST_ID' => 0, |
|
| 3474 | + 'QST_display_text' => esc_html__('State/Province', 'event_espresso'), |
|
| 3475 | + 'QST_system' => 'admin-state', |
|
| 3476 | + ) |
|
| 3477 | + ), |
|
| 3478 | + EE_Answer::new_instance( |
|
| 3479 | + array( |
|
| 3480 | + 'ANS_ID' => 0, |
|
| 3481 | + 'ANS_value' => $this->_cpt_model_obj->state_ID(), |
|
| 3482 | + ) |
|
| 3483 | + ), |
|
| 3484 | + array( |
|
| 3485 | + 'input_id' => 'STA_ID', |
|
| 3486 | + 'input_name' => 'STA_ID', |
|
| 3487 | + 'input_prefix' => '', |
|
| 3488 | + 'append_qstn_id' => false, |
|
| 3489 | + ) |
|
| 3490 | + ) |
|
| 3491 | + ); |
|
| 3492 | + $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input( |
|
| 3493 | + new EE_Question_Form_Input( |
|
| 3494 | + EE_Question::new_instance( |
|
| 3495 | + array( |
|
| 3496 | + 'QST_ID' => 0, |
|
| 3497 | + 'QST_display_text' => esc_html__('Country', 'event_espresso'), |
|
| 3498 | + 'QST_system' => 'admin-country', |
|
| 3499 | + ) |
|
| 3500 | + ), |
|
| 3501 | + EE_Answer::new_instance( |
|
| 3502 | + array( |
|
| 3503 | + 'ANS_ID' => 0, |
|
| 3504 | + 'ANS_value' => $this->_cpt_model_obj->country_ID(), |
|
| 3505 | + ) |
|
| 3506 | + ), |
|
| 3507 | + array( |
|
| 3508 | + 'input_id' => 'CNT_ISO', |
|
| 3509 | + 'input_name' => 'CNT_ISO', |
|
| 3510 | + 'input_prefix' => '', |
|
| 3511 | + 'append_qstn_id' => false, |
|
| 3512 | + ) |
|
| 3513 | + ) |
|
| 3514 | + ); |
|
| 3515 | + $template = |
|
| 3516 | + REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php'; |
|
| 3517 | + EEH_Template::display_template($template, $this->_template_args); |
|
| 3518 | + } |
|
| 3519 | + |
|
| 3520 | + |
|
| 3521 | + /** |
|
| 3522 | + * _attendee_details |
|
| 3523 | + * |
|
| 3524 | + * @access protected |
|
| 3525 | + * @param $post |
|
| 3526 | + * @return void |
|
| 3527 | + * @throws DomainException |
|
| 3528 | + * @throws EE_Error |
|
| 3529 | + */ |
|
| 3530 | + public function attendee_registrations_meta_box($post) |
|
| 3531 | + { |
|
| 3532 | + $this->_template_args['attendee'] = $this->_cpt_model_obj; |
|
| 3533 | + $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration'); |
|
| 3534 | + $template = |
|
| 3535 | + REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php'; |
|
| 3536 | + EEH_Template::display_template($template, $this->_template_args); |
|
| 3537 | + } |
|
| 3538 | + |
|
| 3539 | + |
|
| 3540 | + /** |
|
| 3541 | + * add in the form fields for the attendee edit |
|
| 3542 | + * |
|
| 3543 | + * @param WP_Post $post wp post object |
|
| 3544 | + * @return string html for new form. |
|
| 3545 | + * @throws DomainException |
|
| 3546 | + */ |
|
| 3547 | + public function after_title_form_fields($post) |
|
| 3548 | + { |
|
| 3549 | + if ($post->post_type == 'espresso_attendees') { |
|
| 3550 | + $template = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php'; |
|
| 3551 | + $template_args['attendee'] = $this->_cpt_model_obj; |
|
| 3552 | + EEH_Template::display_template($template, $template_args); |
|
| 3553 | + } |
|
| 3554 | + } |
|
| 3555 | + |
|
| 3556 | + |
|
| 3557 | + /** |
|
| 3558 | + * _trash_or_restore_attendee |
|
| 3559 | + * |
|
| 3560 | + * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE) |
|
| 3561 | + * @return void |
|
| 3562 | + * @throws EE_Error |
|
| 3563 | + * @access protected |
|
| 3564 | + */ |
|
| 3565 | + protected function _trash_or_restore_attendees($trash = true) |
|
| 3566 | + { |
|
| 3567 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3568 | + $ATT_MDL = EEM_Attendee::instance(); |
|
| 3569 | + $success = 1; |
|
| 3570 | + //Checkboxes |
|
| 3571 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 3572 | + // if array has more than one element than success message should be plural |
|
| 3573 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 3574 | + // cycle thru checkboxes |
|
| 3575 | + while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 3576 | + $updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID) |
|
| 3577 | + : $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID); |
|
| 3578 | + if ( ! $updated) { |
|
| 3579 | + $success = 0; |
|
| 3580 | + } |
|
| 3581 | + } |
|
| 3582 | + } else { |
|
| 3583 | + // grab single id and delete |
|
| 3584 | + $ATT_ID = absint($this->_req_data['ATT_ID']); |
|
| 3585 | + //get attendee |
|
| 3586 | + $att = $ATT_MDL->get_one_by_ID($ATT_ID); |
|
| 3587 | + $updated = $trash ? $att->set_status('trash') : $att->set_status('publish'); |
|
| 3588 | + $updated = $att->save(); |
|
| 3589 | + if ( ! $updated) { |
|
| 3590 | + $success = 0; |
|
| 3591 | + } |
|
| 3592 | + } |
|
| 3593 | + $what = $success > 1 |
|
| 3594 | + ? esc_html__('Contacts', 'event_espresso') |
|
| 3595 | + : esc_html__('Contact', 'event_espresso'); |
|
| 3596 | + $action_desc = $trash |
|
| 3597 | + ? esc_html__('moved to the trash', 'event_espresso') |
|
| 3598 | + : esc_html__('restored', 'event_espresso'); |
|
| 3599 | + $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list')); |
|
| 3600 | + } |
|
| 3601 | 3601 | |
| 3602 | 3602 | } |
@@ -26,765 +26,765 @@ |
||
| 26 | 26 | class EE_Registration_Processor extends EE_Processor_Base |
| 27 | 27 | { |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @var EE_Registration_Processor $_instance |
|
| 31 | - * @access private |
|
| 32 | - */ |
|
| 33 | - private static $_instance; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * initial reg status at the beginning of this request. |
|
| 37 | - * indexed by registration ID |
|
| 38 | - * |
|
| 39 | - * @var array |
|
| 40 | - */ |
|
| 41 | - protected $_old_reg_status = array(); |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * reg status at the end of the request after all processing. |
|
| 45 | - * indexed by registration ID |
|
| 46 | - * |
|
| 47 | - * @var array |
|
| 48 | - */ |
|
| 49 | - protected $_new_reg_status = array(); |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * amounts paid at the end of the request after all processing. |
|
| 53 | - * indexed by registration ID |
|
| 54 | - * |
|
| 55 | - * @var array |
|
| 56 | - */ |
|
| 57 | - protected static $_amount_paid = array(); |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Cache of the reg final price for registrations corresponding to a ticket line item |
|
| 61 | - * |
|
| 62 | - * @deprecated |
|
| 63 | - * @var array @see EEH_Line_Item::calculate_reg_final_prices_per_line_item()'s return value |
|
| 64 | - */ |
|
| 65 | - protected $_reg_final_price_per_tkt_line_item; |
|
| 66 | - |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @singleton method used to instantiate class object |
|
| 71 | - * @access public |
|
| 72 | - * @return EE_Registration_Processor instance |
|
| 73 | - */ |
|
| 74 | - public static function instance() |
|
| 75 | - { |
|
| 76 | - // check if class object is instantiated |
|
| 77 | - if (! self::$_instance instanceof EE_Registration_Processor) { |
|
| 78 | - self::$_instance = new self(); |
|
| 79 | - } |
|
| 80 | - return self::$_instance; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * EE_Registration_Processor constructor |
|
| 87 | - */ |
|
| 88 | - private function __construct() |
|
| 89 | - { |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @param int $REG_ID |
|
| 96 | - * @return string |
|
| 97 | - */ |
|
| 98 | - public function old_reg_status($REG_ID) |
|
| 99 | - { |
|
| 100 | - return isset($this->_old_reg_status[$REG_ID]) ? $this->_old_reg_status[$REG_ID] : null; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * @param int $REG_ID |
|
| 107 | - * @param string $old_reg_status |
|
| 108 | - */ |
|
| 109 | - public function set_old_reg_status($REG_ID, $old_reg_status) |
|
| 110 | - { |
|
| 111 | - // only set the first time |
|
| 112 | - if (! isset($this->_old_reg_status[$REG_ID])) { |
|
| 113 | - $this->_old_reg_status[$REG_ID] = $old_reg_status; |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * @param int $REG_ID |
|
| 121 | - * @return string |
|
| 122 | - */ |
|
| 123 | - public function new_reg_status($REG_ID) |
|
| 124 | - { |
|
| 125 | - return isset($this->_new_reg_status[$REG_ID]) ? $this->_new_reg_status[$REG_ID] : null; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @param int $REG_ID |
|
| 132 | - * @param string $new_reg_status |
|
| 133 | - */ |
|
| 134 | - public function set_new_reg_status($REG_ID, $new_reg_status) |
|
| 135 | - { |
|
| 136 | - $this->_new_reg_status[$REG_ID] = $new_reg_status; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * reg_status_updated |
|
| 143 | - * |
|
| 144 | - * @param int $REG_ID |
|
| 145 | - * @return bool |
|
| 146 | - */ |
|
| 147 | - public function reg_status_updated($REG_ID) |
|
| 148 | - { |
|
| 149 | - return $this->new_reg_status($REG_ID) !== $this->old_reg_status($REG_ID); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * @param EE_Registration $registration |
|
| 156 | - * @throws EE_Error |
|
| 157 | - * @throws EntityNotFoundException |
|
| 158 | - * @throws InvalidArgumentException |
|
| 159 | - * @throws InvalidDataTypeException |
|
| 160 | - * @throws InvalidInterfaceException |
|
| 161 | - * @throws ReflectionException |
|
| 162 | - * @throws RuntimeException |
|
| 163 | - */ |
|
| 164 | - public function update_registration_status_and_trigger_notifications(EE_Registration $registration) |
|
| 165 | - { |
|
| 166 | - $this->toggle_incomplete_registration_status_to_default($registration, false); |
|
| 167 | - $this->toggle_registration_status_for_default_approved_events($registration, false); |
|
| 168 | - $this->toggle_registration_status_if_no_monies_owing($registration, false); |
|
| 169 | - $registration->save(); |
|
| 170 | - // trigger notifications |
|
| 171 | - $this->trigger_registration_update_notifications($registration); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * manually_update_registration_status |
|
| 178 | - * |
|
| 179 | - * @access public |
|
| 180 | - * @param EE_Registration $registration |
|
| 181 | - * @param string $new_reg_status |
|
| 182 | - * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave that up |
|
| 183 | - * to client code |
|
| 184 | - * @return bool |
|
| 185 | - * @throws EE_Error |
|
| 186 | - * @throws EntityNotFoundException |
|
| 187 | - * @throws InvalidArgumentException |
|
| 188 | - * @throws InvalidDataTypeException |
|
| 189 | - * @throws InvalidInterfaceException |
|
| 190 | - * @throws ReflectionException |
|
| 191 | - * @throws RuntimeException |
|
| 192 | - */ |
|
| 193 | - public function manually_update_registration_status( |
|
| 194 | - EE_Registration $registration, |
|
| 195 | - $new_reg_status = '', |
|
| 196 | - $save = true |
|
| 197 | - ) { |
|
| 198 | - // set initial REG_Status |
|
| 199 | - $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
| 200 | - // set incoming REG_Status |
|
| 201 | - $this->set_new_reg_status($registration->ID(), $new_reg_status); |
|
| 202 | - // toggle reg status but only if it has changed and the user can do so |
|
| 203 | - if ( |
|
| 204 | - $this->reg_status_updated($registration->ID()) |
|
| 205 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 206 | - 'ee_edit_registration', |
|
| 207 | - 'toggle_registration_status', |
|
| 208 | - $registration->ID() |
|
| 209 | - ) |
|
| 210 | - ) { |
|
| 211 | - // change status to new value |
|
| 212 | - $updated = $registration->set_status($this->new_reg_status($registration->ID())); |
|
| 213 | - if ($updated && $save) { |
|
| 214 | - $registration->save(); |
|
| 215 | - } |
|
| 216 | - return true; |
|
| 217 | - } |
|
| 218 | - return false; |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * toggle_incomplete_registration_status_to_default |
|
| 225 | - * changes any incomplete registrations to either the event or global default registration status |
|
| 226 | - * |
|
| 227 | - * @access public |
|
| 228 | - * @param EE_Registration $registration |
|
| 229 | - * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave that up |
|
| 230 | - * to client code |
|
| 231 | - * @param Context|null $context |
|
| 232 | - * @return void |
|
| 233 | - * @throws EE_Error |
|
| 234 | - * @throws InvalidArgumentException |
|
| 235 | - * @throws ReflectionException |
|
| 236 | - * @throws RuntimeException |
|
| 237 | - * @throws EntityNotFoundException |
|
| 238 | - * @throws InvalidDataTypeException |
|
| 239 | - * @throws InvalidInterfaceException |
|
| 240 | - */ |
|
| 241 | - public function toggle_incomplete_registration_status_to_default( |
|
| 242 | - EE_Registration $registration, |
|
| 243 | - $save = true, |
|
| 244 | - Context $context = null |
|
| 245 | - ) { |
|
| 246 | - $existing_reg_status = $registration->status_ID(); |
|
| 247 | - // set initial REG_Status |
|
| 248 | - $this->set_old_reg_status($registration->ID(), $existing_reg_status); |
|
| 249 | - // is the registration currently incomplete ? |
|
| 250 | - if ($registration->status_ID() === EEM_Registration::status_id_incomplete) { |
|
| 251 | - // grab default reg status for the event, if set |
|
| 252 | - $event_default_registration_status = $registration->event()->default_registration_status(); |
|
| 253 | - // if no default reg status is set for the event, then use the global value |
|
| 254 | - $STS_ID = ! empty($event_default_registration_status) |
|
| 255 | - ? $event_default_registration_status |
|
| 256 | - : EE_Registry::instance()->CFG->registration->default_STS_ID; |
|
| 257 | - // if the event default reg status is approved, then downgrade temporarily to payment pending to ensure that payments are triggered |
|
| 258 | - $STS_ID = $STS_ID === EEM_Registration::status_id_approved ? EEM_Registration::status_id_pending_payment |
|
| 259 | - : $STS_ID; |
|
| 260 | - // set incoming REG_Status |
|
| 261 | - $this->set_new_reg_status($registration->ID(), $STS_ID); |
|
| 262 | - $registration->set_status($STS_ID, false, $context); |
|
| 263 | - if ($save) { |
|
| 264 | - $registration->save(); |
|
| 265 | - } |
|
| 266 | - // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
|
| 267 | - if (! EE_Processor_Base::$IPN) { |
|
| 268 | - // otherwise, send out notifications |
|
| 269 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
| 270 | - } |
|
| 271 | - // DEBUG LOG |
|
| 272 | - //$this->log( |
|
| 273 | - // __CLASS__, __FUNCTION__, __LINE__, |
|
| 274 | - // $registration->transaction(), |
|
| 275 | - // array( |
|
| 276 | - // 'IPN' => EE_Processor_Base::$IPN, |
|
| 277 | - // 'deliver_notifications' => has_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications' ), |
|
| 278 | - // ) |
|
| 279 | - //); |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * toggle_registration_status_for_default_approved_events |
|
| 287 | - * |
|
| 288 | - * @access public |
|
| 289 | - * @param EE_Registration $registration |
|
| 290 | - * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave that up |
|
| 291 | - * to client code |
|
| 292 | - * @return bool |
|
| 293 | - * @throws EE_Error |
|
| 294 | - * @throws EntityNotFoundException |
|
| 295 | - * @throws InvalidArgumentException |
|
| 296 | - * @throws InvalidDataTypeException |
|
| 297 | - * @throws InvalidInterfaceException |
|
| 298 | - * @throws ReflectionException |
|
| 299 | - * @throws RuntimeException |
|
| 300 | - */ |
|
| 301 | - public function toggle_registration_status_for_default_approved_events(EE_Registration $registration, $save = true) |
|
| 302 | - { |
|
| 303 | - $reg_status = $registration->status_ID(); |
|
| 304 | - // set initial REG_Status |
|
| 305 | - $this->set_old_reg_status($registration->ID(), $reg_status); |
|
| 306 | - // if not already, toggle reg status to approved IF the event default reg status is approved |
|
| 307 | - // ( as long as the registration wasn't cancelled or declined at some point ) |
|
| 308 | - if ( |
|
| 309 | - $reg_status !== EEM_Registration::status_id_cancelled |
|
| 310 | - && $reg_status |
|
| 311 | - !== EEM_Registration::status_id_declined |
|
| 312 | - && $reg_status !== EEM_Registration::status_id_approved |
|
| 313 | - && $registration->event()->default_registration_status() === EEM_Registration::status_id_approved |
|
| 314 | - ) { |
|
| 315 | - // set incoming REG_Status |
|
| 316 | - $this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved); |
|
| 317 | - // toggle status to approved |
|
| 318 | - $registration->set_status(EEM_Registration::status_id_approved); |
|
| 319 | - if ($save) { |
|
| 320 | - $registration->save(); |
|
| 321 | - } |
|
| 322 | - // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
|
| 323 | - if (! EE_Processor_Base::$IPN) { |
|
| 324 | - // otherwise, send out notifications |
|
| 325 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
| 326 | - } |
|
| 327 | - // DEBUG LOG |
|
| 328 | - //$this->log( |
|
| 329 | - // __CLASS__, __FUNCTION__, __LINE__, |
|
| 330 | - // $registration->transaction(), |
|
| 331 | - // array( |
|
| 332 | - // 'IPN' => EE_Processor_Base::$IPN, |
|
| 333 | - // 'deliver_notifications' => has_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications' ), |
|
| 334 | - // ) |
|
| 335 | - //); |
|
| 336 | - return true; |
|
| 337 | - } |
|
| 338 | - return false; |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * toggle_registration_statuses_if_no_monies_owing |
|
| 345 | - * |
|
| 346 | - * @access public |
|
| 347 | - * @param EE_Registration $registration |
|
| 348 | - * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave that up |
|
| 349 | - * to client code |
|
| 350 | - * @param array $additional_details |
|
| 351 | - * @return bool |
|
| 352 | - * @throws EE_Error |
|
| 353 | - * @throws EntityNotFoundException |
|
| 354 | - * @throws InvalidArgumentException |
|
| 355 | - * @throws InvalidDataTypeException |
|
| 356 | - * @throws InvalidInterfaceException |
|
| 357 | - * @throws ReflectionException |
|
| 358 | - * @throws RuntimeException |
|
| 359 | - */ |
|
| 360 | - public function toggle_registration_status_if_no_monies_owing( |
|
| 361 | - EE_Registration $registration, |
|
| 362 | - $save = true, |
|
| 363 | - array $additional_details = array() |
|
| 364 | - ) { |
|
| 365 | - // set initial REG_Status |
|
| 366 | - $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
| 367 | - // was a payment just made ? |
|
| 368 | - $payment = isset($additional_details['payment_updates'], $additional_details['last_payment']) |
|
| 369 | - && $additional_details['payment_updates'] |
|
| 370 | - && $additional_details['last_payment'] instanceof EE_Payment |
|
| 371 | - ? $additional_details['last_payment'] |
|
| 372 | - : null; |
|
| 373 | - $total_paid = array_sum(self::$_amount_paid); |
|
| 374 | - // toggle reg status to approved IF |
|
| 375 | - if ( |
|
| 376 | - // REG status is pending payment |
|
| 377 | - $registration->status_ID() === EEM_Registration::status_id_pending_payment |
|
| 378 | - // AND no monies are owing |
|
| 379 | - && ( |
|
| 380 | - ( |
|
| 381 | - $registration->transaction()->is_completed() |
|
| 382 | - || $registration->transaction()->is_overpaid() |
|
| 383 | - || $registration->transaction()->is_free() |
|
| 384 | - || apply_filters( |
|
| 385 | - 'FHEE__EE_Registration_Processor__toggle_registration_status_if_no_monies_owing', |
|
| 386 | - false, |
|
| 387 | - $registration |
|
| 388 | - ) |
|
| 389 | - ) |
|
| 390 | - || ( |
|
| 391 | - $payment instanceof EE_Payment && $payment->is_approved() |
|
| 392 | - && // this specific registration has not yet been paid for |
|
| 393 | - ! isset(self::$_amount_paid[$registration->ID()]) |
|
| 394 | - && // payment amount, less what we have already attributed to other registrations, is greater than this reg's final price |
|
| 395 | - $payment->amount() - $total_paid >= $registration->final_price() |
|
| 396 | - ) |
|
| 397 | - ) |
|
| 398 | - ) { |
|
| 399 | - // mark as paid |
|
| 400 | - self::$_amount_paid[$registration->ID()] = $registration->final_price(); |
|
| 401 | - // track new REG_Status |
|
| 402 | - $this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved); |
|
| 403 | - // toggle status to approved |
|
| 404 | - $registration->set_status(EEM_Registration::status_id_approved); |
|
| 405 | - if ($save) { |
|
| 406 | - $registration->save(); |
|
| 407 | - } |
|
| 408 | - // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
|
| 409 | - if (! EE_Processor_Base::$IPN) { |
|
| 410 | - // otherwise, send out notifications |
|
| 411 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
| 412 | - } |
|
| 413 | - // DEBUG LOG |
|
| 414 | - //$this->log( |
|
| 415 | - // __CLASS__, __FUNCTION__, __LINE__, |
|
| 416 | - // $registration->transaction(), |
|
| 417 | - // array( |
|
| 418 | - // 'IPN' => EE_Processor_Base::$IPN, |
|
| 419 | - // 'deliver_notifications' => has_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications' ), |
|
| 420 | - // ) |
|
| 421 | - //); |
|
| 422 | - return true; |
|
| 423 | - } |
|
| 424 | - return false; |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - |
|
| 428 | - |
|
| 429 | - /** |
|
| 430 | - * registration_status_changed |
|
| 431 | - * |
|
| 432 | - * @access public |
|
| 433 | - * @param EE_Registration $registration |
|
| 434 | - * @param array $additional_details |
|
| 435 | - * @return void |
|
| 436 | - */ |
|
| 437 | - public function trigger_registration_update_notifications($registration, array $additional_details = array()) |
|
| 438 | - { |
|
| 439 | - try { |
|
| 440 | - if (! $registration instanceof EE_Registration) { |
|
| 441 | - throw new EE_Error( |
|
| 442 | - esc_html__('An invalid registration was received.', 'event_espresso') |
|
| 443 | - ); |
|
| 444 | - } |
|
| 445 | - // EE_Registry::instance()->load_helper( 'Debug_Tools' ); |
|
| 446 | - // EEH_Debug_Tools::log( |
|
| 447 | - // __CLASS__, |
|
| 448 | - // __FUNCTION__, |
|
| 449 | - // __LINE__, |
|
| 450 | - // array( $registration->transaction(), $additional_details ), |
|
| 451 | - // false, |
|
| 452 | - // 'EE_Transaction: ' . $registration->transaction()->ID() |
|
| 453 | - // ); |
|
| 454 | - if (! $registration->is_primary_registrant()) { |
|
| 455 | - return; |
|
| 456 | - } |
|
| 457 | - do_action( |
|
| 458 | - 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 459 | - $registration, |
|
| 460 | - $additional_details |
|
| 461 | - ); |
|
| 462 | - } catch (Exception $e) { |
|
| 463 | - EE_Error::add_error($e->getMessage(), $e->getFile(), 'unknown_function_from_exception', $e->getLine()); |
|
| 464 | - } |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - |
|
| 468 | - |
|
| 469 | - /** |
|
| 470 | - * sets reg status based either on passed param or on transaction status and event pre-approval setting |
|
| 471 | - * |
|
| 472 | - * @param EE_Registration $registration |
|
| 473 | - * @param array $additional_details |
|
| 474 | - * @return bool |
|
| 475 | - * @throws EE_Error |
|
| 476 | - * @throws EntityNotFoundException |
|
| 477 | - * @throws InvalidArgumentException |
|
| 478 | - * @throws InvalidDataTypeException |
|
| 479 | - * @throws InvalidInterfaceException |
|
| 480 | - * @throws ReflectionException |
|
| 481 | - * @throws RuntimeException |
|
| 482 | - */ |
|
| 483 | - public function update_registration_after_checkout_or_payment( |
|
| 484 | - EE_Registration $registration, |
|
| 485 | - array $additional_details = array() |
|
| 486 | - ) { |
|
| 487 | - // set initial REG_Status |
|
| 488 | - $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
| 489 | - // if the registration status gets updated, then save the registration |
|
| 490 | - if ( |
|
| 491 | - $this->toggle_registration_status_for_default_approved_events($registration, false) |
|
| 492 | - || $this->toggle_registration_status_if_no_monies_owing( |
|
| 493 | - $registration, |
|
| 494 | - false, |
|
| 495 | - $additional_details |
|
| 496 | - ) |
|
| 497 | - ) { |
|
| 498 | - $registration->save(); |
|
| 499 | - } |
|
| 500 | - // set new REG_Status |
|
| 501 | - $this->set_new_reg_status($registration->ID(), $registration->status_ID()); |
|
| 502 | - return $this->reg_status_updated($registration->ID()) |
|
| 503 | - && $this->new_reg_status($registration->ID()) === EEM_Registration::status_id_approved; |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - |
|
| 507 | - |
|
| 508 | - /** |
|
| 509 | - * Updates the registration' final prices based on the current line item tree (taking into account |
|
| 510 | - * discounts, taxes, and other line items unrelated to tickets.) |
|
| 511 | - * |
|
| 512 | - * @param EE_Transaction $transaction |
|
| 513 | - * @param boolean $save_regs whether to immediately save registrations in this function or not |
|
| 514 | - * @return void |
|
| 515 | - * @throws EE_Error |
|
| 516 | - * @throws InvalidArgumentException |
|
| 517 | - * @throws InvalidDataTypeException |
|
| 518 | - * @throws InvalidInterfaceException |
|
| 519 | - * @throws RuntimeException |
|
| 520 | - */ |
|
| 521 | - public function update_registration_final_prices($transaction, $save_regs = true) |
|
| 522 | - { |
|
| 523 | - $reg_final_price_per_ticket_line_item = EEH_Line_Item::calculate_reg_final_prices_per_line_item( |
|
| 524 | - $transaction->total_line_item() |
|
| 525 | - ); |
|
| 526 | - foreach ($transaction->registrations() as $registration) { |
|
| 527 | - /** @var EE_Line_Item $line_item */ |
|
| 528 | - $line_item = EEM_Line_Item::instance()->get_line_item_for_registration($registration); |
|
| 529 | - if (isset($reg_final_price_per_ticket_line_item[$line_item->ID()])) { |
|
| 530 | - $registration->set_final_price($reg_final_price_per_ticket_line_item[$line_item->ID()]); |
|
| 531 | - if ($save_regs) { |
|
| 532 | - $registration->save(); |
|
| 533 | - } |
|
| 534 | - } |
|
| 535 | - } |
|
| 536 | - //and make sure there's no rounding problem |
|
| 537 | - $this->fix_reg_final_price_rounding_issue($transaction); |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - |
|
| 541 | - |
|
| 542 | - /** |
|
| 543 | - * Makes sure there is no rounding errors for the REG_final_prices. |
|
| 544 | - * Eg, if we have 3 registrations for $1, and there is a $0.01 discount between the three of them, |
|
| 545 | - * they will each be for $0.99333333, which gets rounded to $1 again. |
|
| 546 | - * So the transaction total will be $2.99, but each registration will be for $1, |
|
| 547 | - * so if each registrant paid individually they will have overpaid by $0.01. |
|
| 548 | - * So in order to overcome this, we check for any difference, and if there is a difference |
|
| 549 | - * we just grab one registrant at random and make them responsible for it. |
|
| 550 | - * This should be used after setting REG_final_prices (it's done automatically as part of |
|
| 551 | - * EE_Registration_Processor::update_registration_final_prices()) |
|
| 552 | - * |
|
| 553 | - * @param EE_Transaction $transaction |
|
| 554 | - * @return bool success verifying that there is NO difference after this method is done |
|
| 555 | - * @throws EE_Error |
|
| 556 | - * @throws InvalidArgumentException |
|
| 557 | - * @throws InvalidDataTypeException |
|
| 558 | - * @throws InvalidInterfaceException |
|
| 559 | - */ |
|
| 560 | - public function fix_reg_final_price_rounding_issue($transaction) |
|
| 561 | - { |
|
| 562 | - $reg_final_price_sum = EEM_Registration::instance()->sum( |
|
| 563 | - array( |
|
| 564 | - array( |
|
| 565 | - 'TXN_ID' => $transaction->ID(), |
|
| 566 | - ), |
|
| 567 | - ), |
|
| 568 | - 'REG_final_price' |
|
| 569 | - ); |
|
| 570 | - $diff = $transaction->total() - $reg_final_price_sum; |
|
| 571 | - //ok then, just grab one of the registrations |
|
| 572 | - if ($diff !== 0) { |
|
| 573 | - $a_reg = EEM_Registration::instance()->get_one( |
|
| 574 | - array( |
|
| 575 | - array( |
|
| 576 | - 'TXN_ID' => $transaction->ID(), |
|
| 577 | - ), |
|
| 578 | - ) |
|
| 579 | - ); |
|
| 580 | - return $a_reg instanceof EE_Registration |
|
| 581 | - ? (bool) $a_reg->save(array('REG_final_price' => $a_reg->final_price() + $diff)) |
|
| 582 | - : false; |
|
| 583 | - } |
|
| 584 | - return true; |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - |
|
| 588 | - |
|
| 589 | - /** |
|
| 590 | - * update_registration_after_being_canceled_or_declined |
|
| 591 | - * |
|
| 592 | - * @param EE_Registration $registration |
|
| 593 | - * @param array $closed_reg_statuses |
|
| 594 | - * @param bool $update_reg |
|
| 595 | - * @return bool |
|
| 596 | - * @throws EE_Error |
|
| 597 | - * @throws RuntimeException |
|
| 598 | - */ |
|
| 599 | - public function update_registration_after_being_canceled_or_declined( |
|
| 600 | - EE_Registration $registration, |
|
| 601 | - array $closed_reg_statuses = array(), |
|
| 602 | - $update_reg = true |
|
| 603 | - ) { |
|
| 604 | - // these reg statuses should not be considered in any calculations involving monies owing |
|
| 605 | - $closed_reg_statuses = ! empty($closed_reg_statuses) |
|
| 606 | - ? $closed_reg_statuses |
|
| 607 | - : EEM_Registration::closed_reg_statuses(); |
|
| 608 | - if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
| 609 | - return false; |
|
| 610 | - } |
|
| 611 | - // release a reserved ticket by decrementing ticket and datetime reserved values |
|
| 612 | - $registration->release_reserved_ticket(true); |
|
| 613 | - $registration->set_final_price(0); |
|
| 614 | - if ($update_reg) { |
|
| 615 | - $registration->save(); |
|
| 616 | - } |
|
| 617 | - return true; |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - |
|
| 621 | - |
|
| 622 | - /** |
|
| 623 | - * update_canceled_or_declined_registration_after_being_reinstated |
|
| 624 | - * |
|
| 625 | - * @param EE_Registration $registration |
|
| 626 | - * @param array $closed_reg_statuses |
|
| 627 | - * @param bool $update_reg |
|
| 628 | - * @return bool |
|
| 629 | - * @throws EE_Error |
|
| 630 | - * @throws RuntimeException |
|
| 631 | - */ |
|
| 632 | - public function update_canceled_or_declined_registration_after_being_reinstated( |
|
| 633 | - EE_Registration $registration, |
|
| 634 | - array $closed_reg_statuses = array(), |
|
| 635 | - $update_reg = true |
|
| 636 | - ) { |
|
| 637 | - // these reg statuses should not be considered in any calculations involving monies owing |
|
| 638 | - $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses |
|
| 639 | - : EEM_Registration::closed_reg_statuses(); |
|
| 640 | - if (in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
| 641 | - return false; |
|
| 642 | - } |
|
| 643 | - $ticket = $registration->ticket(); |
|
| 644 | - if (! $ticket instanceof EE_Ticket) { |
|
| 645 | - throw new EE_Error( |
|
| 646 | - sprintf( |
|
| 647 | - esc_html__( |
|
| 648 | - 'The Ticket for Registration %1$d was not found or is invalid.', |
|
| 649 | - 'event_espresso' |
|
| 650 | - ), |
|
| 651 | - $registration->ticket_ID() |
|
| 652 | - ) |
|
| 653 | - ); |
|
| 654 | - } |
|
| 655 | - $registration->set_final_price($ticket->price()); |
|
| 656 | - if ($update_reg) { |
|
| 657 | - $registration->save(); |
|
| 658 | - } |
|
| 659 | - return true; |
|
| 660 | - } |
|
| 661 | - |
|
| 662 | - |
|
| 663 | - |
|
| 664 | - /** |
|
| 665 | - * generate_ONE_registration_from_line_item |
|
| 666 | - * Although a ticket line item may have a quantity greater than 1, |
|
| 667 | - * this method will ONLY CREATE ONE REGISTRATION !!! |
|
| 668 | - * Regardless of the ticket line item quantity. |
|
| 669 | - * This means that any code calling this method is responsible for ensuring |
|
| 670 | - * that the final registration count matches the ticket line item quantity. |
|
| 671 | - * This was done to make it easier to match the number of registrations |
|
| 672 | - * to the number of tickets in the cart, when the cart has been edited |
|
| 673 | - * after SPCO has already been initialized. So if an additional ticket was added to the cart, you can simply pass |
|
| 674 | - * the line item to this method to add a second ticket, and in this case, you would not want to add 2 tickets. |
|
| 675 | - * |
|
| 676 | - * @deprecated |
|
| 677 | - * @since 4.9.1 |
|
| 678 | - * @param EE_Line_Item $line_item |
|
| 679 | - * @param \EE_Transaction $transaction |
|
| 680 | - * @param int $att_nmbr |
|
| 681 | - * @param int $total_ticket_count |
|
| 682 | - * @return EE_Registration | null |
|
| 683 | - * @throws \OutOfRangeException |
|
| 684 | - * @throws \EventEspresso\core\exceptions\UnexpectedEntityException |
|
| 685 | - * @throws \EE_Error |
|
| 686 | - */ |
|
| 687 | - public function generate_ONE_registration_from_line_item( |
|
| 688 | - EE_Line_Item $line_item, |
|
| 689 | - EE_Transaction $transaction, |
|
| 690 | - $att_nmbr = 1, |
|
| 691 | - $total_ticket_count = 1 |
|
| 692 | - ) { |
|
| 693 | - EE_Error::doing_it_wrong( |
|
| 694 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 695 | - sprintf( |
|
| 696 | - esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
| 697 | - '\EventEspresso\core\domain\services\registration\CreateRegistrationService::create()' |
|
| 698 | - ), |
|
| 699 | - '4.9.1', |
|
| 700 | - '5.0.0' |
|
| 701 | - ); |
|
| 702 | - // grab the related ticket object for this line_item |
|
| 703 | - $ticket = $line_item->ticket(); |
|
| 704 | - if (! $ticket instanceof EE_Ticket) { |
|
| 705 | - EE_Error::add_error( |
|
| 706 | - sprintf( |
|
| 707 | - esc_html__('Line item %s did not contain a valid ticket', 'event_espresso'), |
|
| 708 | - $line_item->ID() |
|
| 709 | - ), |
|
| 710 | - __FILE__, |
|
| 711 | - __FUNCTION__, |
|
| 712 | - __LINE__ |
|
| 713 | - ); |
|
| 714 | - return null; |
|
| 715 | - } |
|
| 716 | - $registration_service = new CreateRegistrationService(); |
|
| 717 | - // then generate a new registration from that |
|
| 718 | - return $registration_service->create( |
|
| 719 | - $ticket->get_related_event(), |
|
| 720 | - $transaction, |
|
| 721 | - $ticket, |
|
| 722 | - $line_item, |
|
| 723 | - $att_nmbr, |
|
| 724 | - $total_ticket_count |
|
| 725 | - ); |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - |
|
| 729 | - |
|
| 730 | - /** |
|
| 731 | - * generates reg_url_link |
|
| 732 | - * |
|
| 733 | - * @deprecated |
|
| 734 | - * @since 4.9.1 |
|
| 735 | - * @param int $att_nmbr |
|
| 736 | - * @param EE_Line_Item | string $item |
|
| 737 | - * @return string |
|
| 738 | - * @throws InvalidArgumentException |
|
| 739 | - */ |
|
| 740 | - public function generate_reg_url_link($att_nmbr, $item) |
|
| 741 | - { |
|
| 742 | - EE_Error::doing_it_wrong( |
|
| 743 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 744 | - sprintf( |
|
| 745 | - esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
| 746 | - 'EventEspresso\core\domain\entities\RegUrlLink' |
|
| 747 | - ), |
|
| 748 | - '4.9.1', |
|
| 749 | - '5.0.0' |
|
| 750 | - ); |
|
| 751 | - return new RegUrlLink($att_nmbr, $item); |
|
| 752 | - } |
|
| 753 | - |
|
| 754 | - |
|
| 755 | - |
|
| 756 | - /** |
|
| 757 | - * generates reg code |
|
| 758 | - * |
|
| 759 | - * @deprecated |
|
| 760 | - * @since 4.9.1 |
|
| 761 | - * @param EE_Registration $registration |
|
| 762 | - * @return string |
|
| 763 | - * @throws EE_Error |
|
| 764 | - * @throws EntityNotFoundException |
|
| 765 | - * @throws InvalidArgumentException |
|
| 766 | - */ |
|
| 767 | - public function generate_reg_code(EE_Registration $registration) |
|
| 768 | - { |
|
| 769 | - EE_Error::doing_it_wrong( |
|
| 770 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 771 | - sprintf( |
|
| 772 | - esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
| 773 | - 'EventEspresso\core\domain\entities\RegCode' |
|
| 774 | - ), |
|
| 775 | - '4.9.1', |
|
| 776 | - '5.0.0' |
|
| 777 | - ); |
|
| 778 | - return apply_filters( |
|
| 779 | - 'FHEE__EE_Registration_Processor___generate_reg_code__new_reg_code', |
|
| 780 | - new RegCode( |
|
| 781 | - RegUrlLink::fromRegistration($registration), |
|
| 782 | - $registration->transaction(), |
|
| 783 | - $registration->ticket() |
|
| 784 | - ), |
|
| 785 | - $registration |
|
| 786 | - ); |
|
| 787 | - } |
|
| 29 | + /** |
|
| 30 | + * @var EE_Registration_Processor $_instance |
|
| 31 | + * @access private |
|
| 32 | + */ |
|
| 33 | + private static $_instance; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * initial reg status at the beginning of this request. |
|
| 37 | + * indexed by registration ID |
|
| 38 | + * |
|
| 39 | + * @var array |
|
| 40 | + */ |
|
| 41 | + protected $_old_reg_status = array(); |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * reg status at the end of the request after all processing. |
|
| 45 | + * indexed by registration ID |
|
| 46 | + * |
|
| 47 | + * @var array |
|
| 48 | + */ |
|
| 49 | + protected $_new_reg_status = array(); |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * amounts paid at the end of the request after all processing. |
|
| 53 | + * indexed by registration ID |
|
| 54 | + * |
|
| 55 | + * @var array |
|
| 56 | + */ |
|
| 57 | + protected static $_amount_paid = array(); |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Cache of the reg final price for registrations corresponding to a ticket line item |
|
| 61 | + * |
|
| 62 | + * @deprecated |
|
| 63 | + * @var array @see EEH_Line_Item::calculate_reg_final_prices_per_line_item()'s return value |
|
| 64 | + */ |
|
| 65 | + protected $_reg_final_price_per_tkt_line_item; |
|
| 66 | + |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @singleton method used to instantiate class object |
|
| 71 | + * @access public |
|
| 72 | + * @return EE_Registration_Processor instance |
|
| 73 | + */ |
|
| 74 | + public static function instance() |
|
| 75 | + { |
|
| 76 | + // check if class object is instantiated |
|
| 77 | + if (! self::$_instance instanceof EE_Registration_Processor) { |
|
| 78 | + self::$_instance = new self(); |
|
| 79 | + } |
|
| 80 | + return self::$_instance; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * EE_Registration_Processor constructor |
|
| 87 | + */ |
|
| 88 | + private function __construct() |
|
| 89 | + { |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * @param int $REG_ID |
|
| 96 | + * @return string |
|
| 97 | + */ |
|
| 98 | + public function old_reg_status($REG_ID) |
|
| 99 | + { |
|
| 100 | + return isset($this->_old_reg_status[$REG_ID]) ? $this->_old_reg_status[$REG_ID] : null; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * @param int $REG_ID |
|
| 107 | + * @param string $old_reg_status |
|
| 108 | + */ |
|
| 109 | + public function set_old_reg_status($REG_ID, $old_reg_status) |
|
| 110 | + { |
|
| 111 | + // only set the first time |
|
| 112 | + if (! isset($this->_old_reg_status[$REG_ID])) { |
|
| 113 | + $this->_old_reg_status[$REG_ID] = $old_reg_status; |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * @param int $REG_ID |
|
| 121 | + * @return string |
|
| 122 | + */ |
|
| 123 | + public function new_reg_status($REG_ID) |
|
| 124 | + { |
|
| 125 | + return isset($this->_new_reg_status[$REG_ID]) ? $this->_new_reg_status[$REG_ID] : null; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @param int $REG_ID |
|
| 132 | + * @param string $new_reg_status |
|
| 133 | + */ |
|
| 134 | + public function set_new_reg_status($REG_ID, $new_reg_status) |
|
| 135 | + { |
|
| 136 | + $this->_new_reg_status[$REG_ID] = $new_reg_status; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * reg_status_updated |
|
| 143 | + * |
|
| 144 | + * @param int $REG_ID |
|
| 145 | + * @return bool |
|
| 146 | + */ |
|
| 147 | + public function reg_status_updated($REG_ID) |
|
| 148 | + { |
|
| 149 | + return $this->new_reg_status($REG_ID) !== $this->old_reg_status($REG_ID); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * @param EE_Registration $registration |
|
| 156 | + * @throws EE_Error |
|
| 157 | + * @throws EntityNotFoundException |
|
| 158 | + * @throws InvalidArgumentException |
|
| 159 | + * @throws InvalidDataTypeException |
|
| 160 | + * @throws InvalidInterfaceException |
|
| 161 | + * @throws ReflectionException |
|
| 162 | + * @throws RuntimeException |
|
| 163 | + */ |
|
| 164 | + public function update_registration_status_and_trigger_notifications(EE_Registration $registration) |
|
| 165 | + { |
|
| 166 | + $this->toggle_incomplete_registration_status_to_default($registration, false); |
|
| 167 | + $this->toggle_registration_status_for_default_approved_events($registration, false); |
|
| 168 | + $this->toggle_registration_status_if_no_monies_owing($registration, false); |
|
| 169 | + $registration->save(); |
|
| 170 | + // trigger notifications |
|
| 171 | + $this->trigger_registration_update_notifications($registration); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * manually_update_registration_status |
|
| 178 | + * |
|
| 179 | + * @access public |
|
| 180 | + * @param EE_Registration $registration |
|
| 181 | + * @param string $new_reg_status |
|
| 182 | + * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave that up |
|
| 183 | + * to client code |
|
| 184 | + * @return bool |
|
| 185 | + * @throws EE_Error |
|
| 186 | + * @throws EntityNotFoundException |
|
| 187 | + * @throws InvalidArgumentException |
|
| 188 | + * @throws InvalidDataTypeException |
|
| 189 | + * @throws InvalidInterfaceException |
|
| 190 | + * @throws ReflectionException |
|
| 191 | + * @throws RuntimeException |
|
| 192 | + */ |
|
| 193 | + public function manually_update_registration_status( |
|
| 194 | + EE_Registration $registration, |
|
| 195 | + $new_reg_status = '', |
|
| 196 | + $save = true |
|
| 197 | + ) { |
|
| 198 | + // set initial REG_Status |
|
| 199 | + $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
| 200 | + // set incoming REG_Status |
|
| 201 | + $this->set_new_reg_status($registration->ID(), $new_reg_status); |
|
| 202 | + // toggle reg status but only if it has changed and the user can do so |
|
| 203 | + if ( |
|
| 204 | + $this->reg_status_updated($registration->ID()) |
|
| 205 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 206 | + 'ee_edit_registration', |
|
| 207 | + 'toggle_registration_status', |
|
| 208 | + $registration->ID() |
|
| 209 | + ) |
|
| 210 | + ) { |
|
| 211 | + // change status to new value |
|
| 212 | + $updated = $registration->set_status($this->new_reg_status($registration->ID())); |
|
| 213 | + if ($updated && $save) { |
|
| 214 | + $registration->save(); |
|
| 215 | + } |
|
| 216 | + return true; |
|
| 217 | + } |
|
| 218 | + return false; |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * toggle_incomplete_registration_status_to_default |
|
| 225 | + * changes any incomplete registrations to either the event or global default registration status |
|
| 226 | + * |
|
| 227 | + * @access public |
|
| 228 | + * @param EE_Registration $registration |
|
| 229 | + * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave that up |
|
| 230 | + * to client code |
|
| 231 | + * @param Context|null $context |
|
| 232 | + * @return void |
|
| 233 | + * @throws EE_Error |
|
| 234 | + * @throws InvalidArgumentException |
|
| 235 | + * @throws ReflectionException |
|
| 236 | + * @throws RuntimeException |
|
| 237 | + * @throws EntityNotFoundException |
|
| 238 | + * @throws InvalidDataTypeException |
|
| 239 | + * @throws InvalidInterfaceException |
|
| 240 | + */ |
|
| 241 | + public function toggle_incomplete_registration_status_to_default( |
|
| 242 | + EE_Registration $registration, |
|
| 243 | + $save = true, |
|
| 244 | + Context $context = null |
|
| 245 | + ) { |
|
| 246 | + $existing_reg_status = $registration->status_ID(); |
|
| 247 | + // set initial REG_Status |
|
| 248 | + $this->set_old_reg_status($registration->ID(), $existing_reg_status); |
|
| 249 | + // is the registration currently incomplete ? |
|
| 250 | + if ($registration->status_ID() === EEM_Registration::status_id_incomplete) { |
|
| 251 | + // grab default reg status for the event, if set |
|
| 252 | + $event_default_registration_status = $registration->event()->default_registration_status(); |
|
| 253 | + // if no default reg status is set for the event, then use the global value |
|
| 254 | + $STS_ID = ! empty($event_default_registration_status) |
|
| 255 | + ? $event_default_registration_status |
|
| 256 | + : EE_Registry::instance()->CFG->registration->default_STS_ID; |
|
| 257 | + // if the event default reg status is approved, then downgrade temporarily to payment pending to ensure that payments are triggered |
|
| 258 | + $STS_ID = $STS_ID === EEM_Registration::status_id_approved ? EEM_Registration::status_id_pending_payment |
|
| 259 | + : $STS_ID; |
|
| 260 | + // set incoming REG_Status |
|
| 261 | + $this->set_new_reg_status($registration->ID(), $STS_ID); |
|
| 262 | + $registration->set_status($STS_ID, false, $context); |
|
| 263 | + if ($save) { |
|
| 264 | + $registration->save(); |
|
| 265 | + } |
|
| 266 | + // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
|
| 267 | + if (! EE_Processor_Base::$IPN) { |
|
| 268 | + // otherwise, send out notifications |
|
| 269 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
| 270 | + } |
|
| 271 | + // DEBUG LOG |
|
| 272 | + //$this->log( |
|
| 273 | + // __CLASS__, __FUNCTION__, __LINE__, |
|
| 274 | + // $registration->transaction(), |
|
| 275 | + // array( |
|
| 276 | + // 'IPN' => EE_Processor_Base::$IPN, |
|
| 277 | + // 'deliver_notifications' => has_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications' ), |
|
| 278 | + // ) |
|
| 279 | + //); |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * toggle_registration_status_for_default_approved_events |
|
| 287 | + * |
|
| 288 | + * @access public |
|
| 289 | + * @param EE_Registration $registration |
|
| 290 | + * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave that up |
|
| 291 | + * to client code |
|
| 292 | + * @return bool |
|
| 293 | + * @throws EE_Error |
|
| 294 | + * @throws EntityNotFoundException |
|
| 295 | + * @throws InvalidArgumentException |
|
| 296 | + * @throws InvalidDataTypeException |
|
| 297 | + * @throws InvalidInterfaceException |
|
| 298 | + * @throws ReflectionException |
|
| 299 | + * @throws RuntimeException |
|
| 300 | + */ |
|
| 301 | + public function toggle_registration_status_for_default_approved_events(EE_Registration $registration, $save = true) |
|
| 302 | + { |
|
| 303 | + $reg_status = $registration->status_ID(); |
|
| 304 | + // set initial REG_Status |
|
| 305 | + $this->set_old_reg_status($registration->ID(), $reg_status); |
|
| 306 | + // if not already, toggle reg status to approved IF the event default reg status is approved |
|
| 307 | + // ( as long as the registration wasn't cancelled or declined at some point ) |
|
| 308 | + if ( |
|
| 309 | + $reg_status !== EEM_Registration::status_id_cancelled |
|
| 310 | + && $reg_status |
|
| 311 | + !== EEM_Registration::status_id_declined |
|
| 312 | + && $reg_status !== EEM_Registration::status_id_approved |
|
| 313 | + && $registration->event()->default_registration_status() === EEM_Registration::status_id_approved |
|
| 314 | + ) { |
|
| 315 | + // set incoming REG_Status |
|
| 316 | + $this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved); |
|
| 317 | + // toggle status to approved |
|
| 318 | + $registration->set_status(EEM_Registration::status_id_approved); |
|
| 319 | + if ($save) { |
|
| 320 | + $registration->save(); |
|
| 321 | + } |
|
| 322 | + // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
|
| 323 | + if (! EE_Processor_Base::$IPN) { |
|
| 324 | + // otherwise, send out notifications |
|
| 325 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
| 326 | + } |
|
| 327 | + // DEBUG LOG |
|
| 328 | + //$this->log( |
|
| 329 | + // __CLASS__, __FUNCTION__, __LINE__, |
|
| 330 | + // $registration->transaction(), |
|
| 331 | + // array( |
|
| 332 | + // 'IPN' => EE_Processor_Base::$IPN, |
|
| 333 | + // 'deliver_notifications' => has_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications' ), |
|
| 334 | + // ) |
|
| 335 | + //); |
|
| 336 | + return true; |
|
| 337 | + } |
|
| 338 | + return false; |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * toggle_registration_statuses_if_no_monies_owing |
|
| 345 | + * |
|
| 346 | + * @access public |
|
| 347 | + * @param EE_Registration $registration |
|
| 348 | + * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave that up |
|
| 349 | + * to client code |
|
| 350 | + * @param array $additional_details |
|
| 351 | + * @return bool |
|
| 352 | + * @throws EE_Error |
|
| 353 | + * @throws EntityNotFoundException |
|
| 354 | + * @throws InvalidArgumentException |
|
| 355 | + * @throws InvalidDataTypeException |
|
| 356 | + * @throws InvalidInterfaceException |
|
| 357 | + * @throws ReflectionException |
|
| 358 | + * @throws RuntimeException |
|
| 359 | + */ |
|
| 360 | + public function toggle_registration_status_if_no_monies_owing( |
|
| 361 | + EE_Registration $registration, |
|
| 362 | + $save = true, |
|
| 363 | + array $additional_details = array() |
|
| 364 | + ) { |
|
| 365 | + // set initial REG_Status |
|
| 366 | + $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
| 367 | + // was a payment just made ? |
|
| 368 | + $payment = isset($additional_details['payment_updates'], $additional_details['last_payment']) |
|
| 369 | + && $additional_details['payment_updates'] |
|
| 370 | + && $additional_details['last_payment'] instanceof EE_Payment |
|
| 371 | + ? $additional_details['last_payment'] |
|
| 372 | + : null; |
|
| 373 | + $total_paid = array_sum(self::$_amount_paid); |
|
| 374 | + // toggle reg status to approved IF |
|
| 375 | + if ( |
|
| 376 | + // REG status is pending payment |
|
| 377 | + $registration->status_ID() === EEM_Registration::status_id_pending_payment |
|
| 378 | + // AND no monies are owing |
|
| 379 | + && ( |
|
| 380 | + ( |
|
| 381 | + $registration->transaction()->is_completed() |
|
| 382 | + || $registration->transaction()->is_overpaid() |
|
| 383 | + || $registration->transaction()->is_free() |
|
| 384 | + || apply_filters( |
|
| 385 | + 'FHEE__EE_Registration_Processor__toggle_registration_status_if_no_monies_owing', |
|
| 386 | + false, |
|
| 387 | + $registration |
|
| 388 | + ) |
|
| 389 | + ) |
|
| 390 | + || ( |
|
| 391 | + $payment instanceof EE_Payment && $payment->is_approved() |
|
| 392 | + && // this specific registration has not yet been paid for |
|
| 393 | + ! isset(self::$_amount_paid[$registration->ID()]) |
|
| 394 | + && // payment amount, less what we have already attributed to other registrations, is greater than this reg's final price |
|
| 395 | + $payment->amount() - $total_paid >= $registration->final_price() |
|
| 396 | + ) |
|
| 397 | + ) |
|
| 398 | + ) { |
|
| 399 | + // mark as paid |
|
| 400 | + self::$_amount_paid[$registration->ID()] = $registration->final_price(); |
|
| 401 | + // track new REG_Status |
|
| 402 | + $this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved); |
|
| 403 | + // toggle status to approved |
|
| 404 | + $registration->set_status(EEM_Registration::status_id_approved); |
|
| 405 | + if ($save) { |
|
| 406 | + $registration->save(); |
|
| 407 | + } |
|
| 408 | + // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
|
| 409 | + if (! EE_Processor_Base::$IPN) { |
|
| 410 | + // otherwise, send out notifications |
|
| 411 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
| 412 | + } |
|
| 413 | + // DEBUG LOG |
|
| 414 | + //$this->log( |
|
| 415 | + // __CLASS__, __FUNCTION__, __LINE__, |
|
| 416 | + // $registration->transaction(), |
|
| 417 | + // array( |
|
| 418 | + // 'IPN' => EE_Processor_Base::$IPN, |
|
| 419 | + // 'deliver_notifications' => has_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications' ), |
|
| 420 | + // ) |
|
| 421 | + //); |
|
| 422 | + return true; |
|
| 423 | + } |
|
| 424 | + return false; |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + |
|
| 428 | + |
|
| 429 | + /** |
|
| 430 | + * registration_status_changed |
|
| 431 | + * |
|
| 432 | + * @access public |
|
| 433 | + * @param EE_Registration $registration |
|
| 434 | + * @param array $additional_details |
|
| 435 | + * @return void |
|
| 436 | + */ |
|
| 437 | + public function trigger_registration_update_notifications($registration, array $additional_details = array()) |
|
| 438 | + { |
|
| 439 | + try { |
|
| 440 | + if (! $registration instanceof EE_Registration) { |
|
| 441 | + throw new EE_Error( |
|
| 442 | + esc_html__('An invalid registration was received.', 'event_espresso') |
|
| 443 | + ); |
|
| 444 | + } |
|
| 445 | + // EE_Registry::instance()->load_helper( 'Debug_Tools' ); |
|
| 446 | + // EEH_Debug_Tools::log( |
|
| 447 | + // __CLASS__, |
|
| 448 | + // __FUNCTION__, |
|
| 449 | + // __LINE__, |
|
| 450 | + // array( $registration->transaction(), $additional_details ), |
|
| 451 | + // false, |
|
| 452 | + // 'EE_Transaction: ' . $registration->transaction()->ID() |
|
| 453 | + // ); |
|
| 454 | + if (! $registration->is_primary_registrant()) { |
|
| 455 | + return; |
|
| 456 | + } |
|
| 457 | + do_action( |
|
| 458 | + 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 459 | + $registration, |
|
| 460 | + $additional_details |
|
| 461 | + ); |
|
| 462 | + } catch (Exception $e) { |
|
| 463 | + EE_Error::add_error($e->getMessage(), $e->getFile(), 'unknown_function_from_exception', $e->getLine()); |
|
| 464 | + } |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + |
|
| 468 | + |
|
| 469 | + /** |
|
| 470 | + * sets reg status based either on passed param or on transaction status and event pre-approval setting |
|
| 471 | + * |
|
| 472 | + * @param EE_Registration $registration |
|
| 473 | + * @param array $additional_details |
|
| 474 | + * @return bool |
|
| 475 | + * @throws EE_Error |
|
| 476 | + * @throws EntityNotFoundException |
|
| 477 | + * @throws InvalidArgumentException |
|
| 478 | + * @throws InvalidDataTypeException |
|
| 479 | + * @throws InvalidInterfaceException |
|
| 480 | + * @throws ReflectionException |
|
| 481 | + * @throws RuntimeException |
|
| 482 | + */ |
|
| 483 | + public function update_registration_after_checkout_or_payment( |
|
| 484 | + EE_Registration $registration, |
|
| 485 | + array $additional_details = array() |
|
| 486 | + ) { |
|
| 487 | + // set initial REG_Status |
|
| 488 | + $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
| 489 | + // if the registration status gets updated, then save the registration |
|
| 490 | + if ( |
|
| 491 | + $this->toggle_registration_status_for_default_approved_events($registration, false) |
|
| 492 | + || $this->toggle_registration_status_if_no_monies_owing( |
|
| 493 | + $registration, |
|
| 494 | + false, |
|
| 495 | + $additional_details |
|
| 496 | + ) |
|
| 497 | + ) { |
|
| 498 | + $registration->save(); |
|
| 499 | + } |
|
| 500 | + // set new REG_Status |
|
| 501 | + $this->set_new_reg_status($registration->ID(), $registration->status_ID()); |
|
| 502 | + return $this->reg_status_updated($registration->ID()) |
|
| 503 | + && $this->new_reg_status($registration->ID()) === EEM_Registration::status_id_approved; |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + |
|
| 507 | + |
|
| 508 | + /** |
|
| 509 | + * Updates the registration' final prices based on the current line item tree (taking into account |
|
| 510 | + * discounts, taxes, and other line items unrelated to tickets.) |
|
| 511 | + * |
|
| 512 | + * @param EE_Transaction $transaction |
|
| 513 | + * @param boolean $save_regs whether to immediately save registrations in this function or not |
|
| 514 | + * @return void |
|
| 515 | + * @throws EE_Error |
|
| 516 | + * @throws InvalidArgumentException |
|
| 517 | + * @throws InvalidDataTypeException |
|
| 518 | + * @throws InvalidInterfaceException |
|
| 519 | + * @throws RuntimeException |
|
| 520 | + */ |
|
| 521 | + public function update_registration_final_prices($transaction, $save_regs = true) |
|
| 522 | + { |
|
| 523 | + $reg_final_price_per_ticket_line_item = EEH_Line_Item::calculate_reg_final_prices_per_line_item( |
|
| 524 | + $transaction->total_line_item() |
|
| 525 | + ); |
|
| 526 | + foreach ($transaction->registrations() as $registration) { |
|
| 527 | + /** @var EE_Line_Item $line_item */ |
|
| 528 | + $line_item = EEM_Line_Item::instance()->get_line_item_for_registration($registration); |
|
| 529 | + if (isset($reg_final_price_per_ticket_line_item[$line_item->ID()])) { |
|
| 530 | + $registration->set_final_price($reg_final_price_per_ticket_line_item[$line_item->ID()]); |
|
| 531 | + if ($save_regs) { |
|
| 532 | + $registration->save(); |
|
| 533 | + } |
|
| 534 | + } |
|
| 535 | + } |
|
| 536 | + //and make sure there's no rounding problem |
|
| 537 | + $this->fix_reg_final_price_rounding_issue($transaction); |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + |
|
| 541 | + |
|
| 542 | + /** |
|
| 543 | + * Makes sure there is no rounding errors for the REG_final_prices. |
|
| 544 | + * Eg, if we have 3 registrations for $1, and there is a $0.01 discount between the three of them, |
|
| 545 | + * they will each be for $0.99333333, which gets rounded to $1 again. |
|
| 546 | + * So the transaction total will be $2.99, but each registration will be for $1, |
|
| 547 | + * so if each registrant paid individually they will have overpaid by $0.01. |
|
| 548 | + * So in order to overcome this, we check for any difference, and if there is a difference |
|
| 549 | + * we just grab one registrant at random and make them responsible for it. |
|
| 550 | + * This should be used after setting REG_final_prices (it's done automatically as part of |
|
| 551 | + * EE_Registration_Processor::update_registration_final_prices()) |
|
| 552 | + * |
|
| 553 | + * @param EE_Transaction $transaction |
|
| 554 | + * @return bool success verifying that there is NO difference after this method is done |
|
| 555 | + * @throws EE_Error |
|
| 556 | + * @throws InvalidArgumentException |
|
| 557 | + * @throws InvalidDataTypeException |
|
| 558 | + * @throws InvalidInterfaceException |
|
| 559 | + */ |
|
| 560 | + public function fix_reg_final_price_rounding_issue($transaction) |
|
| 561 | + { |
|
| 562 | + $reg_final_price_sum = EEM_Registration::instance()->sum( |
|
| 563 | + array( |
|
| 564 | + array( |
|
| 565 | + 'TXN_ID' => $transaction->ID(), |
|
| 566 | + ), |
|
| 567 | + ), |
|
| 568 | + 'REG_final_price' |
|
| 569 | + ); |
|
| 570 | + $diff = $transaction->total() - $reg_final_price_sum; |
|
| 571 | + //ok then, just grab one of the registrations |
|
| 572 | + if ($diff !== 0) { |
|
| 573 | + $a_reg = EEM_Registration::instance()->get_one( |
|
| 574 | + array( |
|
| 575 | + array( |
|
| 576 | + 'TXN_ID' => $transaction->ID(), |
|
| 577 | + ), |
|
| 578 | + ) |
|
| 579 | + ); |
|
| 580 | + return $a_reg instanceof EE_Registration |
|
| 581 | + ? (bool) $a_reg->save(array('REG_final_price' => $a_reg->final_price() + $diff)) |
|
| 582 | + : false; |
|
| 583 | + } |
|
| 584 | + return true; |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + |
|
| 588 | + |
|
| 589 | + /** |
|
| 590 | + * update_registration_after_being_canceled_or_declined |
|
| 591 | + * |
|
| 592 | + * @param EE_Registration $registration |
|
| 593 | + * @param array $closed_reg_statuses |
|
| 594 | + * @param bool $update_reg |
|
| 595 | + * @return bool |
|
| 596 | + * @throws EE_Error |
|
| 597 | + * @throws RuntimeException |
|
| 598 | + */ |
|
| 599 | + public function update_registration_after_being_canceled_or_declined( |
|
| 600 | + EE_Registration $registration, |
|
| 601 | + array $closed_reg_statuses = array(), |
|
| 602 | + $update_reg = true |
|
| 603 | + ) { |
|
| 604 | + // these reg statuses should not be considered in any calculations involving monies owing |
|
| 605 | + $closed_reg_statuses = ! empty($closed_reg_statuses) |
|
| 606 | + ? $closed_reg_statuses |
|
| 607 | + : EEM_Registration::closed_reg_statuses(); |
|
| 608 | + if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
| 609 | + return false; |
|
| 610 | + } |
|
| 611 | + // release a reserved ticket by decrementing ticket and datetime reserved values |
|
| 612 | + $registration->release_reserved_ticket(true); |
|
| 613 | + $registration->set_final_price(0); |
|
| 614 | + if ($update_reg) { |
|
| 615 | + $registration->save(); |
|
| 616 | + } |
|
| 617 | + return true; |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + |
|
| 621 | + |
|
| 622 | + /** |
|
| 623 | + * update_canceled_or_declined_registration_after_being_reinstated |
|
| 624 | + * |
|
| 625 | + * @param EE_Registration $registration |
|
| 626 | + * @param array $closed_reg_statuses |
|
| 627 | + * @param bool $update_reg |
|
| 628 | + * @return bool |
|
| 629 | + * @throws EE_Error |
|
| 630 | + * @throws RuntimeException |
|
| 631 | + */ |
|
| 632 | + public function update_canceled_or_declined_registration_after_being_reinstated( |
|
| 633 | + EE_Registration $registration, |
|
| 634 | + array $closed_reg_statuses = array(), |
|
| 635 | + $update_reg = true |
|
| 636 | + ) { |
|
| 637 | + // these reg statuses should not be considered in any calculations involving monies owing |
|
| 638 | + $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses |
|
| 639 | + : EEM_Registration::closed_reg_statuses(); |
|
| 640 | + if (in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
| 641 | + return false; |
|
| 642 | + } |
|
| 643 | + $ticket = $registration->ticket(); |
|
| 644 | + if (! $ticket instanceof EE_Ticket) { |
|
| 645 | + throw new EE_Error( |
|
| 646 | + sprintf( |
|
| 647 | + esc_html__( |
|
| 648 | + 'The Ticket for Registration %1$d was not found or is invalid.', |
|
| 649 | + 'event_espresso' |
|
| 650 | + ), |
|
| 651 | + $registration->ticket_ID() |
|
| 652 | + ) |
|
| 653 | + ); |
|
| 654 | + } |
|
| 655 | + $registration->set_final_price($ticket->price()); |
|
| 656 | + if ($update_reg) { |
|
| 657 | + $registration->save(); |
|
| 658 | + } |
|
| 659 | + return true; |
|
| 660 | + } |
|
| 661 | + |
|
| 662 | + |
|
| 663 | + |
|
| 664 | + /** |
|
| 665 | + * generate_ONE_registration_from_line_item |
|
| 666 | + * Although a ticket line item may have a quantity greater than 1, |
|
| 667 | + * this method will ONLY CREATE ONE REGISTRATION !!! |
|
| 668 | + * Regardless of the ticket line item quantity. |
|
| 669 | + * This means that any code calling this method is responsible for ensuring |
|
| 670 | + * that the final registration count matches the ticket line item quantity. |
|
| 671 | + * This was done to make it easier to match the number of registrations |
|
| 672 | + * to the number of tickets in the cart, when the cart has been edited |
|
| 673 | + * after SPCO has already been initialized. So if an additional ticket was added to the cart, you can simply pass |
|
| 674 | + * the line item to this method to add a second ticket, and in this case, you would not want to add 2 tickets. |
|
| 675 | + * |
|
| 676 | + * @deprecated |
|
| 677 | + * @since 4.9.1 |
|
| 678 | + * @param EE_Line_Item $line_item |
|
| 679 | + * @param \EE_Transaction $transaction |
|
| 680 | + * @param int $att_nmbr |
|
| 681 | + * @param int $total_ticket_count |
|
| 682 | + * @return EE_Registration | null |
|
| 683 | + * @throws \OutOfRangeException |
|
| 684 | + * @throws \EventEspresso\core\exceptions\UnexpectedEntityException |
|
| 685 | + * @throws \EE_Error |
|
| 686 | + */ |
|
| 687 | + public function generate_ONE_registration_from_line_item( |
|
| 688 | + EE_Line_Item $line_item, |
|
| 689 | + EE_Transaction $transaction, |
|
| 690 | + $att_nmbr = 1, |
|
| 691 | + $total_ticket_count = 1 |
|
| 692 | + ) { |
|
| 693 | + EE_Error::doing_it_wrong( |
|
| 694 | + __CLASS__ . '::' . __FUNCTION__, |
|
| 695 | + sprintf( |
|
| 696 | + esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
| 697 | + '\EventEspresso\core\domain\services\registration\CreateRegistrationService::create()' |
|
| 698 | + ), |
|
| 699 | + '4.9.1', |
|
| 700 | + '5.0.0' |
|
| 701 | + ); |
|
| 702 | + // grab the related ticket object for this line_item |
|
| 703 | + $ticket = $line_item->ticket(); |
|
| 704 | + if (! $ticket instanceof EE_Ticket) { |
|
| 705 | + EE_Error::add_error( |
|
| 706 | + sprintf( |
|
| 707 | + esc_html__('Line item %s did not contain a valid ticket', 'event_espresso'), |
|
| 708 | + $line_item->ID() |
|
| 709 | + ), |
|
| 710 | + __FILE__, |
|
| 711 | + __FUNCTION__, |
|
| 712 | + __LINE__ |
|
| 713 | + ); |
|
| 714 | + return null; |
|
| 715 | + } |
|
| 716 | + $registration_service = new CreateRegistrationService(); |
|
| 717 | + // then generate a new registration from that |
|
| 718 | + return $registration_service->create( |
|
| 719 | + $ticket->get_related_event(), |
|
| 720 | + $transaction, |
|
| 721 | + $ticket, |
|
| 722 | + $line_item, |
|
| 723 | + $att_nmbr, |
|
| 724 | + $total_ticket_count |
|
| 725 | + ); |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + |
|
| 729 | + |
|
| 730 | + /** |
|
| 731 | + * generates reg_url_link |
|
| 732 | + * |
|
| 733 | + * @deprecated |
|
| 734 | + * @since 4.9.1 |
|
| 735 | + * @param int $att_nmbr |
|
| 736 | + * @param EE_Line_Item | string $item |
|
| 737 | + * @return string |
|
| 738 | + * @throws InvalidArgumentException |
|
| 739 | + */ |
|
| 740 | + public function generate_reg_url_link($att_nmbr, $item) |
|
| 741 | + { |
|
| 742 | + EE_Error::doing_it_wrong( |
|
| 743 | + __CLASS__ . '::' . __FUNCTION__, |
|
| 744 | + sprintf( |
|
| 745 | + esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
| 746 | + 'EventEspresso\core\domain\entities\RegUrlLink' |
|
| 747 | + ), |
|
| 748 | + '4.9.1', |
|
| 749 | + '5.0.0' |
|
| 750 | + ); |
|
| 751 | + return new RegUrlLink($att_nmbr, $item); |
|
| 752 | + } |
|
| 753 | + |
|
| 754 | + |
|
| 755 | + |
|
| 756 | + /** |
|
| 757 | + * generates reg code |
|
| 758 | + * |
|
| 759 | + * @deprecated |
|
| 760 | + * @since 4.9.1 |
|
| 761 | + * @param EE_Registration $registration |
|
| 762 | + * @return string |
|
| 763 | + * @throws EE_Error |
|
| 764 | + * @throws EntityNotFoundException |
|
| 765 | + * @throws InvalidArgumentException |
|
| 766 | + */ |
|
| 767 | + public function generate_reg_code(EE_Registration $registration) |
|
| 768 | + { |
|
| 769 | + EE_Error::doing_it_wrong( |
|
| 770 | + __CLASS__ . '::' . __FUNCTION__, |
|
| 771 | + sprintf( |
|
| 772 | + esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
| 773 | + 'EventEspresso\core\domain\entities\RegCode' |
|
| 774 | + ), |
|
| 775 | + '4.9.1', |
|
| 776 | + '5.0.0' |
|
| 777 | + ); |
|
| 778 | + return apply_filters( |
|
| 779 | + 'FHEE__EE_Registration_Processor___generate_reg_code__new_reg_code', |
|
| 780 | + new RegCode( |
|
| 781 | + RegUrlLink::fromRegistration($registration), |
|
| 782 | + $registration->transaction(), |
|
| 783 | + $registration->ticket() |
|
| 784 | + ), |
|
| 785 | + $registration |
|
| 786 | + ); |
|
| 787 | + } |
|
| 788 | 788 | |
| 789 | 789 | |
| 790 | 790 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | /** |
| 5 | 5 | * Event Espresso |
@@ -30,44 +30,44 @@ discard block |
||
| 30 | 30 | { |
| 31 | 31 | |
| 32 | 32 | |
| 33 | - public function do_initial_loads() |
|
| 34 | - { |
|
| 35 | - //we want to use the corresponding admin page object (but not route it!). To do this we just set _routing to false. That way this page object is being loaded on all pages to make sure we hook into admin properly. But note... we are ONLY doing this if the given page is NOT pages we WANT to load ;) |
|
| 36 | - //This is important because we have hooks that help redirect custom post type saves |
|
| 37 | - if (! isset($_REQUEST['page']) |
|
| 38 | - || (isset($_REQUEST['page']) |
|
| 39 | - && $_REQUEST['page'] |
|
| 40 | - != $this->_menu_map->menu_slug)) { |
|
| 41 | - $this->_routing = false; |
|
| 42 | - $this->_initialize_admin_page(); |
|
| 43 | - } else { |
|
| 44 | - //normal init loads |
|
| 45 | - $this->_initialize_admin_page(); |
|
| 46 | - //added for 4.1 to completely disable autosave for our pages. This can be removed once we fully enable autosave functionality |
|
| 47 | - remove_filter('wp_print_scripts', 'wp_just_in_time_script_localization'); |
|
| 48 | - add_filter('wp_print_scripts', array($this, 'wp_just_in_time_script_localization'), 100); |
|
| 49 | - //end removal of autosave functionality. |
|
| 50 | - } |
|
| 51 | - } |
|
| 33 | + public function do_initial_loads() |
|
| 34 | + { |
|
| 35 | + //we want to use the corresponding admin page object (but not route it!). To do this we just set _routing to false. That way this page object is being loaded on all pages to make sure we hook into admin properly. But note... we are ONLY doing this if the given page is NOT pages we WANT to load ;) |
|
| 36 | + //This is important because we have hooks that help redirect custom post type saves |
|
| 37 | + if (! isset($_REQUEST['page']) |
|
| 38 | + || (isset($_REQUEST['page']) |
|
| 39 | + && $_REQUEST['page'] |
|
| 40 | + != $this->_menu_map->menu_slug)) { |
|
| 41 | + $this->_routing = false; |
|
| 42 | + $this->_initialize_admin_page(); |
|
| 43 | + } else { |
|
| 44 | + //normal init loads |
|
| 45 | + $this->_initialize_admin_page(); |
|
| 46 | + //added for 4.1 to completely disable autosave for our pages. This can be removed once we fully enable autosave functionality |
|
| 47 | + remove_filter('wp_print_scripts', 'wp_just_in_time_script_localization'); |
|
| 48 | + add_filter('wp_print_scripts', array($this, 'wp_just_in_time_script_localization'), 100); |
|
| 49 | + //end removal of autosave functionality. |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | 53 | |
| 54 | - public function wp_just_in_time_script_localization() |
|
| 55 | - { |
|
| 56 | - wp_localize_script( |
|
| 57 | - 'autosave', |
|
| 58 | - 'autosaveL10n', |
|
| 59 | - array( |
|
| 60 | - 'autosaveInterval' => 172800, |
|
| 61 | - 'savingText' => __('Saving Draft…'), |
|
| 62 | - 'saveAlert' => __('The changes you made will be lost if you navigate away from this page.'), |
|
| 63 | - ) |
|
| 64 | - ); |
|
| 65 | - } |
|
| 54 | + public function wp_just_in_time_script_localization() |
|
| 55 | + { |
|
| 56 | + wp_localize_script( |
|
| 57 | + 'autosave', |
|
| 58 | + 'autosaveL10n', |
|
| 59 | + array( |
|
| 60 | + 'autosaveInterval' => 172800, |
|
| 61 | + 'savingText' => __('Saving Draft…'), |
|
| 62 | + 'saveAlert' => __('The changes you made will be lost if you navigate away from this page.'), |
|
| 63 | + ) |
|
| 64 | + ); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | 67 | |
| 68 | 68 | |
| 69 | - public function adjust_post_lock_window($interval) |
|
| 70 | - { |
|
| 71 | - return 172800; |
|
| 72 | - } |
|
| 69 | + public function adjust_post_lock_window($interval) |
|
| 70 | + { |
|
| 71 | + return 172800; |
|
| 72 | + } |
|
| 73 | 73 | } |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | 2 | exit('No direct script access allowed'); |
| 3 | 3 | } |
| 4 | 4 | /** |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | { |
| 35 | 35 | //we want to use the corresponding admin page object (but not route it!). To do this we just set _routing to false. That way this page object is being loaded on all pages to make sure we hook into admin properly. But note... we are ONLY doing this if the given page is NOT pages we WANT to load ;) |
| 36 | 36 | //This is important because we have hooks that help redirect custom post type saves |
| 37 | - if (! isset($_REQUEST['page']) |
|
| 37 | + if ( ! isset($_REQUEST['page']) |
|
| 38 | 38 | || (isset($_REQUEST['page']) |
| 39 | 39 | && $_REQUEST['page'] |
| 40 | 40 | != $this->_menu_map->menu_slug)) { |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('ABSPATH')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | /* |
| 5 | 5 | Plugin Name: Event Espresso |
@@ -40,243 +40,243 @@ discard block |
||
| 40 | 40 | * @since 4.0 |
| 41 | 41 | */ |
| 42 | 42 | if (function_exists('espresso_version')) { |
| 43 | - /** |
|
| 44 | - * espresso_duplicate_plugin_error |
|
| 45 | - * displays if more than one version of EE is activated at the same time |
|
| 46 | - */ |
|
| 47 | - function espresso_duplicate_plugin_error() |
|
| 48 | - { |
|
| 49 | - ?> |
|
| 43 | + /** |
|
| 44 | + * espresso_duplicate_plugin_error |
|
| 45 | + * displays if more than one version of EE is activated at the same time |
|
| 46 | + */ |
|
| 47 | + function espresso_duplicate_plugin_error() |
|
| 48 | + { |
|
| 49 | + ?> |
|
| 50 | 50 | <div class="error"> |
| 51 | 51 | <p> |
| 52 | 52 | <?php echo esc_html__( |
| 53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | - 'event_espresso' |
|
| 55 | - ); ?> |
|
| 53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | + 'event_espresso' |
|
| 55 | + ); ?> |
|
| 56 | 56 | </p> |
| 57 | 57 | </div> |
| 58 | 58 | <?php |
| 59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | - } |
|
| 59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 63 | 63 | } else { |
| 64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
| 65 | - if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 66 | - /** |
|
| 67 | - * espresso_minimum_php_version_error |
|
| 68 | - * |
|
| 69 | - * @return void |
|
| 70 | - */ |
|
| 71 | - function espresso_minimum_php_version_error() |
|
| 72 | - { |
|
| 73 | - ?> |
|
| 64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
| 65 | + if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 66 | + /** |
|
| 67 | + * espresso_minimum_php_version_error |
|
| 68 | + * |
|
| 69 | + * @return void |
|
| 70 | + */ |
|
| 71 | + function espresso_minimum_php_version_error() |
|
| 72 | + { |
|
| 73 | + ?> |
|
| 74 | 74 | <div class="error"> |
| 75 | 75 | <p> |
| 76 | 76 | <?php |
| 77 | - printf( |
|
| 78 | - esc_html__( |
|
| 79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | - 'event_espresso' |
|
| 81 | - ), |
|
| 82 | - EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | - PHP_VERSION, |
|
| 84 | - '<br/>', |
|
| 85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | - ); |
|
| 87 | - ?> |
|
| 77 | + printf( |
|
| 78 | + esc_html__( |
|
| 79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | + 'event_espresso' |
|
| 81 | + ), |
|
| 82 | + EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | + PHP_VERSION, |
|
| 84 | + '<br/>', |
|
| 85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | + ); |
|
| 87 | + ?> |
|
| 88 | 88 | </p> |
| 89 | 89 | </div> |
| 90 | 90 | <?php |
| 91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | - } |
|
| 91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | - } else { |
|
| 96 | - /** |
|
| 97 | - * espresso_version |
|
| 98 | - * Returns the plugin version |
|
| 99 | - * |
|
| 100 | - * @return string |
|
| 101 | - */ |
|
| 102 | - function espresso_version() |
|
| 103 | - { |
|
| 104 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.47.rc.024'); |
|
| 105 | - } |
|
| 94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | + } else { |
|
| 96 | + /** |
|
| 97 | + * espresso_version |
|
| 98 | + * Returns the plugin version |
|
| 99 | + * |
|
| 100 | + * @return string |
|
| 101 | + */ |
|
| 102 | + function espresso_version() |
|
| 103 | + { |
|
| 104 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.47.rc.024'); |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - // define versions |
|
| 108 | - define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
| 109 | - define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
| 110 | - define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
| 111 | - define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
| 112 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 113 | - //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
| 114 | - if ( ! defined('DS')) { |
|
| 115 | - define('DS', '/'); |
|
| 116 | - } |
|
| 117 | - if ( ! defined('PS')) { |
|
| 118 | - define('PS', PATH_SEPARATOR); |
|
| 119 | - } |
|
| 120 | - if ( ! defined('SP')) { |
|
| 121 | - define('SP', ' '); |
|
| 122 | - } |
|
| 123 | - if ( ! defined('EENL')) { |
|
| 124 | - define('EENL', "\n"); |
|
| 125 | - } |
|
| 126 | - define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
| 127 | - // define the plugin directory and URL |
|
| 128 | - define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 129 | - define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 130 | - define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 131 | - // main root folder paths |
|
| 132 | - define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
| 133 | - define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
| 134 | - define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
| 135 | - define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
| 136 | - define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
| 137 | - define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
| 138 | - define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
| 139 | - define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
| 140 | - // core system paths |
|
| 141 | - define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
| 142 | - define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
| 143 | - define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
| 144 | - define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
| 145 | - define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
| 146 | - define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
| 147 | - define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
| 148 | - define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
| 149 | - define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
| 150 | - define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
| 151 | - define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
| 152 | - define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
| 153 | - // gateways |
|
| 154 | - define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
| 155 | - define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
| 156 | - // asset URL paths |
|
| 157 | - define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
| 158 | - define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
| 159 | - define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
| 160 | - define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
| 161 | - define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
| 162 | - define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
| 163 | - // define upload paths |
|
| 164 | - $uploads = wp_upload_dir(); |
|
| 165 | - // define the uploads directory and URL |
|
| 166 | - define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
| 167 | - define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
| 168 | - // define the templates directory and URL |
|
| 169 | - define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
| 170 | - define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
| 171 | - // define the gateway directory and URL |
|
| 172 | - define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
| 173 | - define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
| 174 | - // languages folder/path |
|
| 175 | - define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
| 176 | - define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
| 177 | - //check for dompdf fonts in uploads |
|
| 178 | - if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
| 179 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
| 180 | - } |
|
| 181 | - //ajax constants |
|
| 182 | - define( |
|
| 183 | - 'EE_FRONT_AJAX', |
|
| 184 | - isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
| 185 | - ); |
|
| 186 | - define( |
|
| 187 | - 'EE_ADMIN_AJAX', |
|
| 188 | - isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
| 189 | - ); |
|
| 190 | - //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
| 191 | - //you're better to use this than its straight value (currently -1) in case you ever |
|
| 192 | - //want to change its default value! or find when -1 means infinity |
|
| 193 | - define('EE_INF_IN_DB', -1); |
|
| 194 | - define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
| 195 | - define('EE_DEBUG', false); |
|
| 196 | - // for older WP versions |
|
| 197 | - if ( ! defined('MONTH_IN_SECONDS')) { |
|
| 198 | - define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
| 199 | - } |
|
| 200 | - /** |
|
| 201 | - * espresso_plugin_activation |
|
| 202 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 203 | - */ |
|
| 204 | - function espresso_plugin_activation() |
|
| 205 | - { |
|
| 206 | - update_option('ee_espresso_activation', true); |
|
| 207 | - } |
|
| 107 | + // define versions |
|
| 108 | + define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
| 109 | + define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
| 110 | + define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
| 111 | + define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
| 112 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 113 | + //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
| 114 | + if ( ! defined('DS')) { |
|
| 115 | + define('DS', '/'); |
|
| 116 | + } |
|
| 117 | + if ( ! defined('PS')) { |
|
| 118 | + define('PS', PATH_SEPARATOR); |
|
| 119 | + } |
|
| 120 | + if ( ! defined('SP')) { |
|
| 121 | + define('SP', ' '); |
|
| 122 | + } |
|
| 123 | + if ( ! defined('EENL')) { |
|
| 124 | + define('EENL', "\n"); |
|
| 125 | + } |
|
| 126 | + define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
| 127 | + // define the plugin directory and URL |
|
| 128 | + define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 129 | + define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 130 | + define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 131 | + // main root folder paths |
|
| 132 | + define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
| 133 | + define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
| 134 | + define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
| 135 | + define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
| 136 | + define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
| 137 | + define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
| 138 | + define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
| 139 | + define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
| 140 | + // core system paths |
|
| 141 | + define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
| 142 | + define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
| 143 | + define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
| 144 | + define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
| 145 | + define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
| 146 | + define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
| 147 | + define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
| 148 | + define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
| 149 | + define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
| 150 | + define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
| 151 | + define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
| 152 | + define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
| 153 | + // gateways |
|
| 154 | + define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
| 155 | + define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
| 156 | + // asset URL paths |
|
| 157 | + define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
| 158 | + define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
| 159 | + define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
| 160 | + define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
| 161 | + define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
| 162 | + define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
| 163 | + // define upload paths |
|
| 164 | + $uploads = wp_upload_dir(); |
|
| 165 | + // define the uploads directory and URL |
|
| 166 | + define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
| 167 | + define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
| 168 | + // define the templates directory and URL |
|
| 169 | + define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
| 170 | + define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
| 171 | + // define the gateway directory and URL |
|
| 172 | + define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
| 173 | + define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
| 174 | + // languages folder/path |
|
| 175 | + define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
| 176 | + define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
| 177 | + //check for dompdf fonts in uploads |
|
| 178 | + if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
| 179 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
| 180 | + } |
|
| 181 | + //ajax constants |
|
| 182 | + define( |
|
| 183 | + 'EE_FRONT_AJAX', |
|
| 184 | + isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
| 185 | + ); |
|
| 186 | + define( |
|
| 187 | + 'EE_ADMIN_AJAX', |
|
| 188 | + isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
| 189 | + ); |
|
| 190 | + //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
| 191 | + //you're better to use this than its straight value (currently -1) in case you ever |
|
| 192 | + //want to change its default value! or find when -1 means infinity |
|
| 193 | + define('EE_INF_IN_DB', -1); |
|
| 194 | + define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
| 195 | + define('EE_DEBUG', false); |
|
| 196 | + // for older WP versions |
|
| 197 | + if ( ! defined('MONTH_IN_SECONDS')) { |
|
| 198 | + define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
| 199 | + } |
|
| 200 | + /** |
|
| 201 | + * espresso_plugin_activation |
|
| 202 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 203 | + */ |
|
| 204 | + function espresso_plugin_activation() |
|
| 205 | + { |
|
| 206 | + update_option('ee_espresso_activation', true); |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 210 | - /** |
|
| 211 | - * espresso_load_error_handling |
|
| 212 | - * this function loads EE's class for handling exceptions and errors |
|
| 213 | - */ |
|
| 214 | - function espresso_load_error_handling() |
|
| 215 | - { |
|
| 216 | - // load debugging tools |
|
| 217 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
| 218 | - require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
| 219 | - EEH_Debug_Tools::instance(); |
|
| 220 | - } |
|
| 221 | - // load error handling |
|
| 222 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
| 223 | - require_once(EE_CORE . 'EE_Error.core.php'); |
|
| 224 | - } else { |
|
| 225 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
| 226 | - } |
|
| 227 | - } |
|
| 209 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 210 | + /** |
|
| 211 | + * espresso_load_error_handling |
|
| 212 | + * this function loads EE's class for handling exceptions and errors |
|
| 213 | + */ |
|
| 214 | + function espresso_load_error_handling() |
|
| 215 | + { |
|
| 216 | + // load debugging tools |
|
| 217 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
| 218 | + require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
| 219 | + EEH_Debug_Tools::instance(); |
|
| 220 | + } |
|
| 221 | + // load error handling |
|
| 222 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
| 223 | + require_once(EE_CORE . 'EE_Error.core.php'); |
|
| 224 | + } else { |
|
| 225 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - /** |
|
| 230 | - * espresso_load_required |
|
| 231 | - * given a class name and path, this function will load that file or throw an exception |
|
| 232 | - * |
|
| 233 | - * @param string $classname |
|
| 234 | - * @param string $full_path_to_file |
|
| 235 | - * @throws EE_Error |
|
| 236 | - */ |
|
| 237 | - function espresso_load_required($classname, $full_path_to_file) |
|
| 238 | - { |
|
| 239 | - static $error_handling_loaded = false; |
|
| 240 | - if ( ! $error_handling_loaded) { |
|
| 241 | - espresso_load_error_handling(); |
|
| 242 | - $error_handling_loaded = true; |
|
| 243 | - } |
|
| 244 | - if (is_readable($full_path_to_file)) { |
|
| 245 | - require_once($full_path_to_file); |
|
| 246 | - } else { |
|
| 247 | - throw new EE_Error ( |
|
| 248 | - sprintf( |
|
| 249 | - esc_html__( |
|
| 250 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
| 251 | - 'event_espresso' |
|
| 252 | - ), |
|
| 253 | - $classname |
|
| 254 | - ) |
|
| 255 | - ); |
|
| 256 | - } |
|
| 257 | - } |
|
| 229 | + /** |
|
| 230 | + * espresso_load_required |
|
| 231 | + * given a class name and path, this function will load that file or throw an exception |
|
| 232 | + * |
|
| 233 | + * @param string $classname |
|
| 234 | + * @param string $full_path_to_file |
|
| 235 | + * @throws EE_Error |
|
| 236 | + */ |
|
| 237 | + function espresso_load_required($classname, $full_path_to_file) |
|
| 238 | + { |
|
| 239 | + static $error_handling_loaded = false; |
|
| 240 | + if ( ! $error_handling_loaded) { |
|
| 241 | + espresso_load_error_handling(); |
|
| 242 | + $error_handling_loaded = true; |
|
| 243 | + } |
|
| 244 | + if (is_readable($full_path_to_file)) { |
|
| 245 | + require_once($full_path_to_file); |
|
| 246 | + } else { |
|
| 247 | + throw new EE_Error ( |
|
| 248 | + sprintf( |
|
| 249 | + esc_html__( |
|
| 250 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
| 251 | + 'event_espresso' |
|
| 252 | + ), |
|
| 253 | + $classname |
|
| 254 | + ) |
|
| 255 | + ); |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | 258 | |
| 259 | - espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
| 260 | - espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
| 261 | - espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
| 262 | - new EE_Bootstrap(); |
|
| 263 | - } |
|
| 259 | + espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
| 260 | + espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
| 261 | + espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
| 262 | + new EE_Bootstrap(); |
|
| 263 | + } |
|
| 264 | 264 | } |
| 265 | 265 | if ( ! function_exists('espresso_deactivate_plugin')) { |
| 266 | - /** |
|
| 267 | - * deactivate_plugin |
|
| 268 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 269 | - * |
|
| 270 | - * @access public |
|
| 271 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 272 | - * @return void |
|
| 273 | - */ |
|
| 274 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
| 275 | - { |
|
| 276 | - if ( ! function_exists('deactivate_plugins')) { |
|
| 277 | - require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
| 278 | - } |
|
| 279 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
| 280 | - deactivate_plugins($plugin_basename); |
|
| 281 | - } |
|
| 266 | + /** |
|
| 267 | + * deactivate_plugin |
|
| 268 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 269 | + * |
|
| 270 | + * @access public |
|
| 271 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 272 | + * @return void |
|
| 273 | + */ |
|
| 274 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
| 275 | + { |
|
| 276 | + if ( ! function_exists('deactivate_plugins')) { |
|
| 277 | + require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
| 278 | + } |
|
| 279 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
| 280 | + deactivate_plugins($plugin_basename); |
|
| 281 | + } |
|
| 282 | 282 | } |
| 283 | 283 | \ No newline at end of file |
@@ -222,7 +222,7 @@ |
||
| 222 | 222 | /** |
| 223 | 223 | * constructor |
| 224 | 224 | * |
| 225 | - * @param EE_Admin_Page $admin_page the calling admin_page_object |
|
| 225 | + * @param EE_Admin_Page $adminpage the calling admin_page_object |
|
| 226 | 226 | */ |
| 227 | 227 | public function __construct(EE_Admin_Page $adminpage) |
| 228 | 228 | { |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 3 | - exit('NO direct script access allowed'); |
|
| 3 | + exit('NO direct script access allowed'); |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | |
@@ -28,729 +28,729 @@ discard block |
||
| 28 | 28 | { |
| 29 | 29 | |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * we're just going to use this to hold the name of the caller class (child class name) |
|
| 33 | - * |
|
| 34 | - * @var string |
|
| 35 | - */ |
|
| 36 | - public $caller; |
|
| 37 | - |
|
| 38 | - |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * this is just a flag set automatically to indicate whether we've got an extended hook class running (i.e. |
|
| 42 | - * espresso_events_Registration_Form_Hooks_Extend extends espresso_events_Registration_Form_Hooks). This flag is |
|
| 43 | - * used later to make sure we require the needed files. |
|
| 44 | - * |
|
| 45 | - * @var bool |
|
| 46 | - */ |
|
| 47 | - protected $_extend; |
|
| 48 | - |
|
| 49 | - |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * child classes MUST set this property so that the page object can be loaded correctly |
|
| 53 | - * |
|
| 54 | - * @var string |
|
| 55 | - */ |
|
| 56 | - protected $_name; |
|
| 57 | - |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * This is set by child classes and is an associative array of ajax hooks in the format: |
|
| 62 | - * array( |
|
| 63 | - * 'ajax_action_ref' => 'executing_method'; //must be public |
|
| 64 | - * ) |
|
| 65 | - * |
|
| 66 | - * @var array |
|
| 67 | - */ |
|
| 68 | - protected $_ajax_func; |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * This is an array of methods that get executed on a page routes admin_init hook. Use the following format: |
|
| 73 | - * array( |
|
| 74 | - * 'page_route' => 'executing_method' //must be public |
|
| 75 | - * ) |
|
| 76 | - * |
|
| 77 | - * @var array |
|
| 78 | - */ |
|
| 79 | - protected $_init_func; |
|
| 80 | - |
|
| 81 | - |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * This is an array of methods that output metabox content for the given page route. Use the following format: |
|
| 85 | - * array( |
|
| 86 | - * 0 => array( |
|
| 87 | - * 'page_route' => 'string_for_page_route', //must correspond to a page route in the class being connected |
|
| 88 | - * with (i.e. "edit_event") If this is in an array then the same params below will be used but the metabox |
|
| 89 | - * will be added to each route. |
|
| 90 | - * 'func' => 'executing_method', //must be public (i.e. public function executing_method($post, |
|
| 91 | - * $callback_args){} ). Note if you include callback args in the array then you need to declare them in the |
|
| 92 | - * method arguments. |
|
| 93 | - * 'id' => 'identifier_for_metabox', //so it can be removed by addons (optional, class will set it |
|
| 94 | - * automatically) |
|
| 95 | - * 'priority' => 'default', //default 'default' (optional) |
|
| 96 | - * 'label' => __('Localized Title', 'event_espresso'), |
|
| 97 | - * 'context' => 'advanced' //advanced is default (optional), |
|
| 98 | - * 'callback_args' => array() //any callback args to include (optional) |
|
| 99 | - * ) |
|
| 100 | - * Why are we indexing numerically? Because it's possible there may be more than one metabox per page_route. |
|
| 101 | - * |
|
| 102 | - * @var array |
|
| 103 | - */ |
|
| 104 | - protected $_metaboxes; |
|
| 105 | - |
|
| 106 | - |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * This is an array of values that indicate any metaboxes we want removed from a given page route. Usually this is |
|
| 110 | - * used when caffeinated functionality is replacing decaffeinated functionality. Use the following format for the |
|
| 111 | - * array: array( |
|
| 112 | - * 0 => array( |
|
| 113 | - * 'page_route' => 'string_for_page_route' //can be string or array of strings that match a page_route(s) |
|
| 114 | - * that are in the class being connected with (i.e. 'edit', or 'create_new'). |
|
| 115 | - * 'id' => 'identifier_for_metabox', //what the id is of the metabox being removed |
|
| 116 | - * 'context' => 'normal', //the context for the metabox being removed (has to match) |
|
| 117 | - * 'screen' => 'screen_id', //(optional), if not included then this class will attempt to remove the metabox |
|
| 118 | - * using the currently loaded screen object->id however, there may be cases where you have to specify the |
|
| 119 | - * id for the screen the metabox is on. |
|
| 120 | - * ) |
|
| 121 | - * ) |
|
| 122 | - * |
|
| 123 | - * @var array |
|
| 124 | - */ |
|
| 125 | - protected $_remove_metaboxes; |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * This parent class takes care of loading the scripts and styles if the child class has set the properties for |
|
| 131 | - * them in the following format. Note, the first array index ('register') is for defining all the registers. The |
|
| 132 | - * second array index is for indicating what routes each script/style loads on. array( |
|
| 133 | - * 'registers' => array( |
|
| 134 | - * 'script_ref' => array( // if more than one script is to be loaded its best to use the 'dependency' |
|
| 135 | - * argument to link scripts together. |
|
| 136 | - * 'type' => 'js' // 'js' or 'css' (defaults to js). This tells us what type of wp_function to use |
|
| 137 | - * 'url' => 'http://urltoscript.css.js', |
|
| 138 | - * 'depends' => array('jquery'), //an array of dependencies for the scripts. REMEMBER, if a script has |
|
| 139 | - * already been registered elsewhere in the system. You can just use the depends array to make sure it |
|
| 140 | - * gets loaded before the one you are setting here. |
|
| 141 | - * 'footer' => TRUE //defaults to true (styles don't use this parameter) |
|
| 142 | - * ), |
|
| 143 | - * 'enqueues' => array( //this time each key corresponds to the script ref followed by an array of page routes |
|
| 144 | - * the script gets enqueued on. |
|
| 145 | - * 'script_ref' => array('route_one', 'route_two') |
|
| 146 | - * ), |
|
| 147 | - * 'localize' => array( //this allows you to set a localize object. Indicate which script the object is being |
|
| 148 | - * attached to and then include an array indexed by the name of the object and the array of key/value pairs for |
|
| 149 | - * the object. |
|
| 150 | - * 'scrip_ref' => array( |
|
| 151 | - * 'NAME_OF_JS_OBJECT' => array( |
|
| 152 | - * 'translate_ref' => __('localized_string', 'event_espresso'), |
|
| 153 | - * 'some_data' => 5 |
|
| 154 | - * ) |
|
| 155 | - * ) |
|
| 156 | - * ) |
|
| 157 | - * ) |
|
| 158 | - * |
|
| 159 | - * @var array |
|
| 160 | - */ |
|
| 161 | - protected $_scripts_styles; |
|
| 162 | - |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * This is a property that will contain the current route. |
|
| 166 | - * |
|
| 167 | - * @var string; |
|
| 168 | - */ |
|
| 169 | - protected $_current_route; |
|
| 170 | - |
|
| 171 | - |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * this optional property can be set by child classes to override the priority for the automatic action/filter hook |
|
| 175 | - * loading in the `_load_routed_hooks()` method. Please follow this format: array( |
|
| 176 | - * 'wp_hook_reference' => 1 |
|
| 177 | - * ) |
|
| 178 | - * ) |
|
| 179 | - * |
|
| 180 | - * @var array |
|
| 181 | - */ |
|
| 182 | - protected $_wp_action_filters_priority; |
|
| 183 | - |
|
| 184 | - |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * This just holds a merged array of the $_POST and $_GET vars in favor of $_POST |
|
| 188 | - * |
|
| 189 | - * @var array |
|
| 190 | - */ |
|
| 191 | - protected $_req_data; |
|
| 192 | - |
|
| 193 | - |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * This just holds an instance of the page object for this hook |
|
| 197 | - * |
|
| 198 | - * @var EE_Admin_Page |
|
| 199 | - */ |
|
| 200 | - protected $_page_object; |
|
| 201 | - |
|
| 202 | - |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * This holds the EE_Admin_Page object from the calling admin page that this object hooks into. |
|
| 206 | - * |
|
| 207 | - * @var EE_Admin_Page|EE_Admin_Page_CPT |
|
| 208 | - */ |
|
| 209 | - protected $_adminpage_obj; |
|
| 210 | - |
|
| 211 | - |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * Holds EE_Registry object |
|
| 215 | - * |
|
| 216 | - * @var EE_Registry |
|
| 217 | - */ |
|
| 218 | - protected $EE = null; |
|
| 219 | - |
|
| 220 | - |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * constructor |
|
| 224 | - * |
|
| 225 | - * @param EE_Admin_Page $admin_page the calling admin_page_object |
|
| 226 | - */ |
|
| 227 | - public function __construct(EE_Admin_Page $adminpage) |
|
| 228 | - { |
|
| 229 | - |
|
| 230 | - $this->_adminpage_obj = $adminpage; |
|
| 231 | - $this->_req_data = array_merge($_GET, $_POST); |
|
| 232 | - $this->_set_defaults(); |
|
| 233 | - $this->_set_hooks_properties(); |
|
| 234 | - //first let's verify we're on the right page |
|
| 235 | - if (! isset($this->_req_data['page']) |
|
| 236 | - || (isset($this->_req_data['page']) |
|
| 237 | - && $this->_adminpage_obj->page_slug |
|
| 238 | - != $this->_req_data['page'])) { |
|
| 239 | - return; |
|
| 240 | - } //get out nothing more to be done here. |
|
| 241 | - //allow for extends to modify properties |
|
| 242 | - if (method_exists($this, '_extend_properties')) { |
|
| 243 | - $this->_extend_properties(); |
|
| 244 | - } |
|
| 245 | - $this->_set_page_object(); |
|
| 246 | - $this->_init_hooks(); |
|
| 247 | - $this->_load_custom_methods(); |
|
| 248 | - $this->_load_routed_hooks(); |
|
| 249 | - add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts_styles')); |
|
| 250 | - add_action('admin_enqueue_scripts', array($this, 'add_metaboxes'), 20); |
|
| 251 | - add_action('admin_enqueue_scripts', array($this, 'remove_metaboxes'), 15); |
|
| 252 | - $this->_ajax_hooks(); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * used by child classes to set the following properties: |
|
| 259 | - * $_ajax_func (optional) |
|
| 260 | - * $_init_func (optional) |
|
| 261 | - * $_metaboxes (optional) |
|
| 262 | - * $_scripts (optional) |
|
| 263 | - * $_styles (optional) |
|
| 264 | - * $_name (required) |
|
| 265 | - * Also in this method will be registered any scripts or styles loaded on the targeted page (as indicated in the |
|
| 266 | - * _scripts/_styles properties) Also children should place in this method any filters/actions that have to happen |
|
| 267 | - * really early on page load (just after admin_init) if they want to have them registered for handling early. |
|
| 268 | - * |
|
| 269 | - * @access protected |
|
| 270 | - * @abstract |
|
| 271 | - * @return void |
|
| 272 | - */ |
|
| 273 | - abstract protected function _set_hooks_properties(); |
|
| 274 | - |
|
| 275 | - |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * The hooks for enqueue_scripts and enqueue_styles will be run in here. Child classes need to define their |
|
| 279 | - * scripts and styles in the relevant $_scripts and $_styles properties. Child classes must have also already |
|
| 280 | - * registered the scripts and styles using wp_register_script and wp_register_style functions. |
|
| 281 | - * |
|
| 282 | - * @access public |
|
| 283 | - * @return void |
|
| 284 | - */ |
|
| 285 | - public function enqueue_scripts_styles() |
|
| 286 | - { |
|
| 287 | - |
|
| 288 | - if (! empty($this->_scripts_styles)) { |
|
| 289 | - //first let's do all the registrations |
|
| 290 | - if (! isset($this->_scripts_styles['registers'])) { |
|
| 291 | - $msg[] = __( |
|
| 292 | - 'There is no "registers" index in the <code>$this->_scripts_styles</code> property.', |
|
| 293 | - 'event_espresso' |
|
| 294 | - ); |
|
| 295 | - $msg[] = sprintf( |
|
| 296 | - __( |
|
| 297 | - 'Make sure you read the phpdoc comments above the definition of the $_scripts_styles property in the <code>EE_Admin_Hooks</code> class and modify according in the %s child', |
|
| 298 | - 'event_espresso' |
|
| 299 | - ), |
|
| 300 | - '<strong>' . $this->caller . '</strong>' |
|
| 301 | - ); |
|
| 302 | - throw new EE_Error(implode('||', $msg)); |
|
| 303 | - } |
|
| 304 | - foreach ($this->_scripts_styles['registers'] as $ref => $details) { |
|
| 305 | - $defaults = array( |
|
| 306 | - 'type' => 'js', |
|
| 307 | - 'url' => '', |
|
| 308 | - 'depends' => array(), |
|
| 309 | - 'version' => EVENT_ESPRESSO_VERSION, |
|
| 310 | - 'footer' => true, |
|
| 311 | - ); |
|
| 312 | - $details = wp_parse_args($details, $defaults); |
|
| 313 | - extract($details); |
|
| 314 | - //let's make sure that we set the 'registers' type if it's not set! We need it later to determine whhich enqueu we do |
|
| 315 | - $this->_scripts_styles['registers'][$ref]['type'] = $type; |
|
| 316 | - //let's make sure we're not missing any REQUIRED parameters |
|
| 317 | - if (empty($url)) { |
|
| 318 | - $msg[] = sprintf( |
|
| 319 | - __('Missing the url for the requested %s', 'event_espresso'), |
|
| 320 | - $type == 'js' ? 'script' : 'stylesheet' |
|
| 321 | - ); |
|
| 322 | - $msg[] = sprintf( |
|
| 323 | - __( |
|
| 324 | - 'Doublecheck your <code>$this->_scripts_styles</code> array in %s and make sure that there is a "url" set for the %s ref', |
|
| 325 | - 'event_espresso' |
|
| 326 | - ), |
|
| 327 | - '<strong>' . $this->caller . '</strong>', |
|
| 328 | - $ref |
|
| 329 | - ); |
|
| 330 | - throw new EE_Error(implode('||', $msg)); |
|
| 331 | - } |
|
| 332 | - //made it here so let's do the appropriate registration |
|
| 333 | - $type == 'js' |
|
| 334 | - ? wp_register_script($ref, $url, $depends, $version, $footer) |
|
| 335 | - : wp_register_style( |
|
| 336 | - $ref, |
|
| 337 | - $url, |
|
| 338 | - $depends, |
|
| 339 | - $version |
|
| 340 | - ); |
|
| 341 | - } |
|
| 342 | - //k now lets do the enqueues |
|
| 343 | - if (! isset($this->_scripts_styles['enqueues'])) { |
|
| 344 | - return; |
|
| 345 | - } //not sure if we should throw an error here or not. |
|
| 346 | - foreach ($this->_scripts_styles['enqueues'] as $ref => $routes) { |
|
| 347 | - //make sure $routes is an array |
|
| 348 | - $routes = (array)$routes; |
|
| 349 | - if (in_array($this->_current_route, $routes)) { |
|
| 350 | - $this->_scripts_styles['registers'][$ref]['type'] == 'js' ? wp_enqueue_script($ref) |
|
| 351 | - : wp_enqueue_style($ref); |
|
| 352 | - //if we have a localization for the script let's do that too. |
|
| 353 | - if (isset($this->_scripts_styles['localize'][$ref])) { |
|
| 354 | - foreach ($this->_scripts_styles['localize'][$ref] as $object_name => $indexes) { |
|
| 355 | - wp_localize_script( |
|
| 356 | - $ref, |
|
| 357 | - $object_name, |
|
| 358 | - $this->_scripts_styles['localize'][$ref][$object_name] |
|
| 359 | - ); |
|
| 360 | - } |
|
| 361 | - } |
|
| 362 | - } |
|
| 363 | - } |
|
| 364 | - //let's do the deregisters |
|
| 365 | - if (! isset($this->_scripts_styles['deregisters'])) { |
|
| 366 | - return; |
|
| 367 | - } |
|
| 368 | - foreach ($this->_scripts_styles['deregisters'] as $ref => $details) { |
|
| 369 | - $defaults = array( |
|
| 370 | - 'type' => 'js', |
|
| 371 | - ); |
|
| 372 | - $details = wp_parse_args($details, $defaults); |
|
| 373 | - extract($details); |
|
| 374 | - $type == 'js' ? wp_deregister_script($ref) : wp_deregister_style($ref); |
|
| 375 | - } |
|
| 376 | - } |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - |
|
| 380 | - |
|
| 381 | - /** |
|
| 382 | - * just set the defaults for the hooks properties. |
|
| 383 | - * |
|
| 384 | - * @access private |
|
| 385 | - * @return void |
|
| 386 | - */ |
|
| 387 | - private function _set_defaults() |
|
| 388 | - { |
|
| 389 | - $this->_ajax_func = $this->_init_func = $this->_metaboxes = $this->_scripts = $this->_styles = $this->_wp_action_filters_priority = array(); |
|
| 390 | - $this->_current_route = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'default'; |
|
| 391 | - $this->caller = get_class($this); |
|
| 392 | - $this->_extend = stripos($this->caller, 'Extend') ? true : false; |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * this sets the _page_object property |
|
| 399 | - * |
|
| 400 | - * @access protected |
|
| 401 | - * @return void |
|
| 402 | - */ |
|
| 403 | - protected function _set_page_object() |
|
| 404 | - { |
|
| 405 | - //first make sure $this->_name is set |
|
| 406 | - if (empty($this->_name)) { |
|
| 407 | - $msg[] = __('We can\'t load the page object', 'event_espresso'); |
|
| 408 | - $msg[] = sprintf( |
|
| 409 | - __("This is because the %s child class has not set the '_name' property", 'event_espresso'), |
|
| 410 | - $this->caller |
|
| 411 | - ); |
|
| 412 | - throw new EE_Error(implode('||', $msg)); |
|
| 413 | - } |
|
| 414 | - $ref = str_replace('_', ' ', $this->_name); //take the_message -> the message |
|
| 415 | - $ref = str_replace(' ', '_', ucwords($ref)) . '_Admin_Page'; //take the message -> The_Message |
|
| 416 | - //first default file (if exists) |
|
| 417 | - $decaf_file = EE_ADMIN_PAGES . $this->_name . DS . $ref . '.core.php'; |
|
| 418 | - if (is_readable($decaf_file)) { |
|
| 419 | - require_once($decaf_file); |
|
| 420 | - } |
|
| 421 | - //now we have to do require for extended file (if needed) |
|
| 422 | - if ($this->_extend) { |
|
| 423 | - require_once(EE_CORE_CAF_ADMIN_EXTEND . $this->_name . DS . 'Extend_' . $ref . '.core.php'); |
|
| 424 | - } |
|
| 425 | - //if we've got an extended class we use that! |
|
| 426 | - $ref = $this->_extend ? 'Extend_' . $ref : $ref; |
|
| 427 | - //let's make sure the class exists |
|
| 428 | - if (! class_exists($ref)) { |
|
| 429 | - $msg[] = __('We can\'t load the page object', 'event_espresso'); |
|
| 430 | - $msg[] = sprintf( |
|
| 431 | - __( |
|
| 432 | - 'The class name that was given is %s. Check the spelling and make sure its correct, also there needs to be an autoloader setup for the class', |
|
| 433 | - 'event_espresso' |
|
| 434 | - ), |
|
| 435 | - $ref |
|
| 436 | - ); |
|
| 437 | - throw new EE_Error(implode('||', $msg)); |
|
| 438 | - } |
|
| 439 | - $a = new ReflectionClass($ref); |
|
| 440 | - $this->_page_object = $a->newInstance(false); |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - |
|
| 444 | - /** |
|
| 445 | - * Child "hook" classes can declare any methods that they want executed when a specific page route is loaded. The |
|
| 446 | - * advantage of this is when doing things like running our own db interactions on saves etc. Remember that |
|
| 447 | - * $this->_req_data (all the _POST and _GET data) is available to your methods. |
|
| 448 | - * |
|
| 449 | - * @access private |
|
| 450 | - * @return void |
|
| 451 | - */ |
|
| 452 | - private function _load_custom_methods() |
|
| 453 | - { |
|
| 454 | - /** |
|
| 455 | - * method cannot be named 'default' (@see http://us3.php |
|
| 456 | - * .net/manual/en/reserved.keywords.php) so need to |
|
| 457 | - * handle routes that are "default" |
|
| 458 | - * |
|
| 459 | - * @since 4.3.0 |
|
| 460 | - */ |
|
| 461 | - $method_callback = $this->_current_route == 'default' ? 'default_callback' : $this->_current_route; |
|
| 462 | - //these run before the Admin_Page route executes. |
|
| 463 | - if (method_exists($this, $method_callback)) { |
|
| 464 | - call_user_func(array($this, $method_callback)); |
|
| 465 | - } |
|
| 466 | - //these run via the _redirect_after_action method in EE_Admin_Page which usually happens after non_UI methods in EE_Admin_Page classes. There are two redirect actions, the first fires before $query_args might be manipulated by "save and close" actions and the seond fires right before the actual redirect happens. |
|
| 467 | - //first the actions |
|
| 468 | - //note that these action hooks will have the $query_args value available. |
|
| 469 | - $admin_class_name = get_class($this->_adminpage_obj); |
|
| 470 | - if (method_exists($this, '_redirect_action_early_' . $this->_current_route)) { |
|
| 471 | - add_action( |
|
| 472 | - 'AHEE__' |
|
| 473 | - . $admin_class_name |
|
| 474 | - . '___redirect_after_action__before_redirect_modification_' |
|
| 475 | - . $this->_current_route, |
|
| 476 | - array($this, '_redirect_action_early_' . $this->_current_route), |
|
| 477 | - 10 |
|
| 478 | - ); |
|
| 479 | - } |
|
| 480 | - if (method_exists($this, '_redirect_action_' . $this->_current_route)) { |
|
| 481 | - add_action( |
|
| 482 | - 'AHEE_redirect_' . $admin_class_name . $this->_current_route, |
|
| 483 | - array($this, '_redirect_action_' . $this->_current_route), |
|
| 484 | - 10 |
|
| 485 | - ); |
|
| 486 | - } |
|
| 487 | - //let's hook into the _redirect itself and allow for changing where the user goes after redirect. This will have $query_args and $redirect_url available. |
|
| 488 | - if (method_exists($this, '_redirect_filter_' . $this->_current_route)) { |
|
| 489 | - add_filter( |
|
| 490 | - 'FHEE_redirect_' . $admin_class_name . $this->_current_route, |
|
| 491 | - array($this, '_redirect_filter_' . $this->_current_route), |
|
| 492 | - 10, |
|
| 493 | - 2 |
|
| 494 | - ); |
|
| 495 | - } |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - |
|
| 499 | - |
|
| 500 | - /** |
|
| 501 | - * This method will search for a corresponding method with a name matching the route and the wp_hook to run. This |
|
| 502 | - * allows child hook classes to target hooking into a specific wp action or filter hook ONLY on a certain route. |
|
| 503 | - * just remember, methods MUST be public Future hooks should be added in here to be access by child classes. |
|
| 504 | - * |
|
| 505 | - * @return void |
|
| 506 | - */ |
|
| 507 | - private function _load_routed_hooks() |
|
| 508 | - { |
|
| 509 | - |
|
| 510 | - //this array provides the hook action names that will be referenced. Key is the action. Value is an array with the type (action or filter) and the number of parameters for the hook. We'll default all priorities for automatic hooks to 10. |
|
| 511 | - $hook_filter_array = array( |
|
| 512 | - 'admin_footer' => array( |
|
| 513 | - 'type' => 'action', |
|
| 514 | - 'argnum' => 1, |
|
| 515 | - 'priority' => 10, |
|
| 516 | - ), |
|
| 517 | - 'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug . '_' . $this->_current_route => array( |
|
| 518 | - 'type' => 'filter', |
|
| 519 | - 'argnum' => 1, |
|
| 520 | - 'priority' => 10, |
|
| 521 | - ), |
|
| 522 | - 'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug => array( |
|
| 523 | - 'type' => 'filter', |
|
| 524 | - 'argnum' => 1, |
|
| 525 | - 'priority' => 10, |
|
| 526 | - ), |
|
| 527 | - 'FHEE_list_table_views' => array( |
|
| 528 | - 'type' => 'filter', |
|
| 529 | - 'argnum' => 1, |
|
| 530 | - 'priority' => 10, |
|
| 531 | - ), |
|
| 532 | - 'AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes' => array( |
|
| 533 | - 'type' => 'action', |
|
| 534 | - 'argnum' => 1, |
|
| 535 | - 'priority' => 10, |
|
| 536 | - ), |
|
| 537 | - ); |
|
| 538 | - foreach ($hook_filter_array as $hook => $args) { |
|
| 539 | - if (method_exists($this, $this->_current_route . '_' . $hook)) { |
|
| 540 | - if (isset($this->_wp_action_filters_priority[$hook])) { |
|
| 541 | - $args['priority'] = $this->_wp_action_filters_priority[$hook]; |
|
| 542 | - } |
|
| 543 | - if ($args['type'] == 'action') { |
|
| 544 | - add_action( |
|
| 545 | - $hook, |
|
| 546 | - array($this, $this->_current_route . '_' . $hook), |
|
| 547 | - $args['priority'], |
|
| 548 | - $args['argnum'] |
|
| 549 | - ); |
|
| 550 | - } else { |
|
| 551 | - add_filter( |
|
| 552 | - $hook, |
|
| 553 | - array($this, $this->_current_route . '_' . $hook), |
|
| 554 | - $args['priority'], |
|
| 555 | - $args['argnum'] |
|
| 556 | - ); |
|
| 557 | - } |
|
| 558 | - } |
|
| 559 | - } |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - |
|
| 563 | - /** |
|
| 564 | - * Loop throught the $_ajax_func array and add_actions for the array. |
|
| 565 | - * |
|
| 566 | - * @return void |
|
| 567 | - */ |
|
| 568 | - private function _ajax_hooks() |
|
| 569 | - { |
|
| 570 | - |
|
| 571 | - if (empty($this->_ajax_func)) { |
|
| 572 | - return; |
|
| 573 | - } //get out there's nothing to take care of. |
|
| 574 | - foreach ($this->_ajax_func as $action => $method) { |
|
| 575 | - //make sure method exists |
|
| 576 | - if (! method_exists($this, $method)) { |
|
| 577 | - $msg[] = __( |
|
| 578 | - 'There is no corresponding method for the hook labeled in the _ajax_func array', |
|
| 579 | - 'event_espresso' |
|
| 580 | - ) . '<br />'; |
|
| 581 | - $msg[] = sprintf( |
|
| 582 | - __( |
|
| 583 | - 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
|
| 584 | - 'event_espresso' |
|
| 585 | - ), |
|
| 586 | - $method, |
|
| 587 | - $this->caller |
|
| 588 | - ); |
|
| 589 | - throw new EE_Error(implode('||', $msg)); |
|
| 590 | - } |
|
| 591 | - add_action('wp_ajax_' . $action, array($this, $method)); |
|
| 592 | - } |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - |
|
| 596 | - |
|
| 597 | - /** |
|
| 598 | - * Loop throught the $_init_func array and add_actions for the array. |
|
| 599 | - * |
|
| 600 | - * @return void |
|
| 601 | - */ |
|
| 602 | - protected function _init_hooks() |
|
| 603 | - { |
|
| 604 | - if (empty($this->_init_func)) { |
|
| 605 | - return; |
|
| 606 | - } //get out there's nothing to take care of. |
|
| 607 | - //We need to determine what page_route we are on! |
|
| 608 | - $current_route = isset ($_REQUEST['action']) ? $_REQUEST['action'] : 'default'; |
|
| 609 | - foreach ($this->_init_func as $route => $method) { |
|
| 610 | - //make sure method exists |
|
| 611 | - if (! method_exists($this, $method)) { |
|
| 612 | - $msg[] = __( |
|
| 613 | - 'There is no corresponding method for the hook labeled in the _init_func array', |
|
| 614 | - 'event_espresso' |
|
| 615 | - ) . '<br />'; |
|
| 616 | - $msg[] = sprintf( |
|
| 617 | - __( |
|
| 618 | - 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
|
| 619 | - 'event_espresso' |
|
| 620 | - ), |
|
| 621 | - $method, |
|
| 622 | - $this->caller |
|
| 623 | - ); |
|
| 624 | - throw new EE_Error(implode('||', $msg)); |
|
| 625 | - } |
|
| 626 | - if ($route == $this->_current_route) { |
|
| 627 | - add_action('admin_init', array($this, $method)); |
|
| 628 | - } |
|
| 629 | - } |
|
| 630 | - } |
|
| 631 | - |
|
| 632 | - |
|
| 633 | - |
|
| 634 | - /** |
|
| 635 | - * Loop through the _metaboxes property and add_metaboxes accordingly |
|
| 636 | - * //todo we could eventually make this a config component class (i.e. new EE_Metabox); |
|
| 637 | - * |
|
| 638 | - * @access public |
|
| 639 | - * @return void |
|
| 640 | - */ |
|
| 641 | - public function add_metaboxes() |
|
| 642 | - { |
|
| 643 | - if (empty($this->_metaboxes)) { |
|
| 644 | - return; |
|
| 645 | - } //get out we don't have any metaboxes to set for this connection |
|
| 646 | - $this->_handle_metabox_array($this->_metaboxes); |
|
| 647 | - } |
|
| 648 | - |
|
| 649 | - |
|
| 650 | - |
|
| 651 | - private function _handle_metabox_array($boxes, $add = true) |
|
| 652 | - { |
|
| 653 | - |
|
| 654 | - foreach ($boxes as $box) { |
|
| 655 | - if (! isset($box['page_route'])) { |
|
| 656 | - continue; |
|
| 657 | - } //we dont' have a valid array |
|
| 658 | - //let's make sure $box['page_route'] is an array so the "foreach" will work. |
|
| 659 | - $box['page_route'] = (array)$box['page_route']; |
|
| 660 | - foreach ($box['page_route'] as $route) { |
|
| 661 | - if ($route != $this->_current_route) { |
|
| 662 | - continue; |
|
| 663 | - } //get out we only add metaboxes for set route. |
|
| 664 | - if ($add) { |
|
| 665 | - $this->_add_metabox($box); |
|
| 666 | - } else { |
|
| 667 | - $this->_remove_metabox($box); |
|
| 668 | - } |
|
| 669 | - } |
|
| 670 | - } |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - |
|
| 674 | - |
|
| 675 | - /** |
|
| 676 | - * Loop through the _remove_metaboxes property and remove metaboxes accordingly. |
|
| 677 | - * |
|
| 678 | - * @access public |
|
| 679 | - * @return void |
|
| 680 | - */ |
|
| 681 | - public function remove_metaboxes() |
|
| 682 | - { |
|
| 683 | - |
|
| 684 | - if (empty($this->_remove_metaboxes)) { |
|
| 685 | - return; |
|
| 686 | - } //get out there are no metaboxes to remove |
|
| 687 | - $this->_handle_metabox_array($this->_remove_metaboxes, false); |
|
| 688 | - } |
|
| 689 | - |
|
| 690 | - |
|
| 691 | - /** |
|
| 692 | - * This just handles adding a metabox |
|
| 693 | - * |
|
| 694 | - * @access private |
|
| 695 | - * @param array $args an array of args that have been set for this metabox by the child class |
|
| 696 | - */ |
|
| 697 | - private function _add_metabox($args) |
|
| 698 | - { |
|
| 699 | - $current_screen = get_current_screen(); |
|
| 700 | - $screen_id = is_object($current_screen) ? $current_screen->id : null; |
|
| 701 | - $func = isset($args['func']) ? $args['func'] : 'some_invalid_callback'; |
|
| 702 | - //set defaults |
|
| 703 | - $defaults = array( |
|
| 704 | - 'func' => $func, |
|
| 705 | - 'id' => $this->caller . '_' . $func . '_metabox', |
|
| 706 | - 'priority' => 'default', |
|
| 707 | - 'label' => $this->caller, |
|
| 708 | - 'context' => 'advanced', |
|
| 709 | - 'callback_args' => array(), |
|
| 710 | - 'page' => isset($args['page']) ? $args['page'] : $screen_id, |
|
| 711 | - ); |
|
| 712 | - $args = wp_parse_args($args, $defaults); |
|
| 713 | - extract($args); |
|
| 714 | - //make sure method exists |
|
| 715 | - if (! method_exists($this, $func)) { |
|
| 716 | - $msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso') . '<br />'; |
|
| 717 | - $msg[] = sprintf( |
|
| 718 | - __( |
|
| 719 | - 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
|
| 720 | - 'event_espresso' |
|
| 721 | - ), |
|
| 722 | - $func, |
|
| 723 | - $this->caller |
|
| 724 | - ); |
|
| 725 | - throw new EE_Error(implode('||', $msg)); |
|
| 726 | - } |
|
| 727 | - //everything checks out so lets add the metabox |
|
| 728 | - add_meta_box($id, $label, array($this, $func), $page, $context, $priority, $callback_args); |
|
| 729 | - } |
|
| 730 | - |
|
| 731 | - |
|
| 732 | - |
|
| 733 | - private function _remove_metabox($args) |
|
| 734 | - { |
|
| 735 | - $current_screen = get_current_screen(); |
|
| 736 | - $screen_id = is_object($current_screen) ? $current_screen->id : null; |
|
| 737 | - $func = isset($args['func']) ? $args['func'] : 'some_invalid_callback'; |
|
| 738 | - //set defaults |
|
| 739 | - $defaults = array( |
|
| 740 | - 'id' => isset($args['id']) |
|
| 741 | - ? $args['id'] |
|
| 742 | - : $this->_current_route |
|
| 743 | - . '_' |
|
| 744 | - . $this->caller |
|
| 745 | - . '_' |
|
| 746 | - . $func |
|
| 747 | - . '_metabox', |
|
| 748 | - 'context' => 'default', |
|
| 749 | - 'screen' => isset($args['screen']) ? $args['screen'] : $screen_id |
|
| 750 | - ); |
|
| 751 | - $args = wp_parse_args($args, $defaults); |
|
| 752 | - extract($args); |
|
| 753 | - //everything checks out so lets remove the box! |
|
| 754 | - remove_meta_box($id, $screen, $context); |
|
| 755 | - } |
|
| 31 | + /** |
|
| 32 | + * we're just going to use this to hold the name of the caller class (child class name) |
|
| 33 | + * |
|
| 34 | + * @var string |
|
| 35 | + */ |
|
| 36 | + public $caller; |
|
| 37 | + |
|
| 38 | + |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * this is just a flag set automatically to indicate whether we've got an extended hook class running (i.e. |
|
| 42 | + * espresso_events_Registration_Form_Hooks_Extend extends espresso_events_Registration_Form_Hooks). This flag is |
|
| 43 | + * used later to make sure we require the needed files. |
|
| 44 | + * |
|
| 45 | + * @var bool |
|
| 46 | + */ |
|
| 47 | + protected $_extend; |
|
| 48 | + |
|
| 49 | + |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * child classes MUST set this property so that the page object can be loaded correctly |
|
| 53 | + * |
|
| 54 | + * @var string |
|
| 55 | + */ |
|
| 56 | + protected $_name; |
|
| 57 | + |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * This is set by child classes and is an associative array of ajax hooks in the format: |
|
| 62 | + * array( |
|
| 63 | + * 'ajax_action_ref' => 'executing_method'; //must be public |
|
| 64 | + * ) |
|
| 65 | + * |
|
| 66 | + * @var array |
|
| 67 | + */ |
|
| 68 | + protected $_ajax_func; |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * This is an array of methods that get executed on a page routes admin_init hook. Use the following format: |
|
| 73 | + * array( |
|
| 74 | + * 'page_route' => 'executing_method' //must be public |
|
| 75 | + * ) |
|
| 76 | + * |
|
| 77 | + * @var array |
|
| 78 | + */ |
|
| 79 | + protected $_init_func; |
|
| 80 | + |
|
| 81 | + |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * This is an array of methods that output metabox content for the given page route. Use the following format: |
|
| 85 | + * array( |
|
| 86 | + * 0 => array( |
|
| 87 | + * 'page_route' => 'string_for_page_route', //must correspond to a page route in the class being connected |
|
| 88 | + * with (i.e. "edit_event") If this is in an array then the same params below will be used but the metabox |
|
| 89 | + * will be added to each route. |
|
| 90 | + * 'func' => 'executing_method', //must be public (i.e. public function executing_method($post, |
|
| 91 | + * $callback_args){} ). Note if you include callback args in the array then you need to declare them in the |
|
| 92 | + * method arguments. |
|
| 93 | + * 'id' => 'identifier_for_metabox', //so it can be removed by addons (optional, class will set it |
|
| 94 | + * automatically) |
|
| 95 | + * 'priority' => 'default', //default 'default' (optional) |
|
| 96 | + * 'label' => __('Localized Title', 'event_espresso'), |
|
| 97 | + * 'context' => 'advanced' //advanced is default (optional), |
|
| 98 | + * 'callback_args' => array() //any callback args to include (optional) |
|
| 99 | + * ) |
|
| 100 | + * Why are we indexing numerically? Because it's possible there may be more than one metabox per page_route. |
|
| 101 | + * |
|
| 102 | + * @var array |
|
| 103 | + */ |
|
| 104 | + protected $_metaboxes; |
|
| 105 | + |
|
| 106 | + |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * This is an array of values that indicate any metaboxes we want removed from a given page route. Usually this is |
|
| 110 | + * used when caffeinated functionality is replacing decaffeinated functionality. Use the following format for the |
|
| 111 | + * array: array( |
|
| 112 | + * 0 => array( |
|
| 113 | + * 'page_route' => 'string_for_page_route' //can be string or array of strings that match a page_route(s) |
|
| 114 | + * that are in the class being connected with (i.e. 'edit', or 'create_new'). |
|
| 115 | + * 'id' => 'identifier_for_metabox', //what the id is of the metabox being removed |
|
| 116 | + * 'context' => 'normal', //the context for the metabox being removed (has to match) |
|
| 117 | + * 'screen' => 'screen_id', //(optional), if not included then this class will attempt to remove the metabox |
|
| 118 | + * using the currently loaded screen object->id however, there may be cases where you have to specify the |
|
| 119 | + * id for the screen the metabox is on. |
|
| 120 | + * ) |
|
| 121 | + * ) |
|
| 122 | + * |
|
| 123 | + * @var array |
|
| 124 | + */ |
|
| 125 | + protected $_remove_metaboxes; |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * This parent class takes care of loading the scripts and styles if the child class has set the properties for |
|
| 131 | + * them in the following format. Note, the first array index ('register') is for defining all the registers. The |
|
| 132 | + * second array index is for indicating what routes each script/style loads on. array( |
|
| 133 | + * 'registers' => array( |
|
| 134 | + * 'script_ref' => array( // if more than one script is to be loaded its best to use the 'dependency' |
|
| 135 | + * argument to link scripts together. |
|
| 136 | + * 'type' => 'js' // 'js' or 'css' (defaults to js). This tells us what type of wp_function to use |
|
| 137 | + * 'url' => 'http://urltoscript.css.js', |
|
| 138 | + * 'depends' => array('jquery'), //an array of dependencies for the scripts. REMEMBER, if a script has |
|
| 139 | + * already been registered elsewhere in the system. You can just use the depends array to make sure it |
|
| 140 | + * gets loaded before the one you are setting here. |
|
| 141 | + * 'footer' => TRUE //defaults to true (styles don't use this parameter) |
|
| 142 | + * ), |
|
| 143 | + * 'enqueues' => array( //this time each key corresponds to the script ref followed by an array of page routes |
|
| 144 | + * the script gets enqueued on. |
|
| 145 | + * 'script_ref' => array('route_one', 'route_two') |
|
| 146 | + * ), |
|
| 147 | + * 'localize' => array( //this allows you to set a localize object. Indicate which script the object is being |
|
| 148 | + * attached to and then include an array indexed by the name of the object and the array of key/value pairs for |
|
| 149 | + * the object. |
|
| 150 | + * 'scrip_ref' => array( |
|
| 151 | + * 'NAME_OF_JS_OBJECT' => array( |
|
| 152 | + * 'translate_ref' => __('localized_string', 'event_espresso'), |
|
| 153 | + * 'some_data' => 5 |
|
| 154 | + * ) |
|
| 155 | + * ) |
|
| 156 | + * ) |
|
| 157 | + * ) |
|
| 158 | + * |
|
| 159 | + * @var array |
|
| 160 | + */ |
|
| 161 | + protected $_scripts_styles; |
|
| 162 | + |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * This is a property that will contain the current route. |
|
| 166 | + * |
|
| 167 | + * @var string; |
|
| 168 | + */ |
|
| 169 | + protected $_current_route; |
|
| 170 | + |
|
| 171 | + |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * this optional property can be set by child classes to override the priority for the automatic action/filter hook |
|
| 175 | + * loading in the `_load_routed_hooks()` method. Please follow this format: array( |
|
| 176 | + * 'wp_hook_reference' => 1 |
|
| 177 | + * ) |
|
| 178 | + * ) |
|
| 179 | + * |
|
| 180 | + * @var array |
|
| 181 | + */ |
|
| 182 | + protected $_wp_action_filters_priority; |
|
| 183 | + |
|
| 184 | + |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * This just holds a merged array of the $_POST and $_GET vars in favor of $_POST |
|
| 188 | + * |
|
| 189 | + * @var array |
|
| 190 | + */ |
|
| 191 | + protected $_req_data; |
|
| 192 | + |
|
| 193 | + |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * This just holds an instance of the page object for this hook |
|
| 197 | + * |
|
| 198 | + * @var EE_Admin_Page |
|
| 199 | + */ |
|
| 200 | + protected $_page_object; |
|
| 201 | + |
|
| 202 | + |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * This holds the EE_Admin_Page object from the calling admin page that this object hooks into. |
|
| 206 | + * |
|
| 207 | + * @var EE_Admin_Page|EE_Admin_Page_CPT |
|
| 208 | + */ |
|
| 209 | + protected $_adminpage_obj; |
|
| 210 | + |
|
| 211 | + |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * Holds EE_Registry object |
|
| 215 | + * |
|
| 216 | + * @var EE_Registry |
|
| 217 | + */ |
|
| 218 | + protected $EE = null; |
|
| 219 | + |
|
| 220 | + |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * constructor |
|
| 224 | + * |
|
| 225 | + * @param EE_Admin_Page $admin_page the calling admin_page_object |
|
| 226 | + */ |
|
| 227 | + public function __construct(EE_Admin_Page $adminpage) |
|
| 228 | + { |
|
| 229 | + |
|
| 230 | + $this->_adminpage_obj = $adminpage; |
|
| 231 | + $this->_req_data = array_merge($_GET, $_POST); |
|
| 232 | + $this->_set_defaults(); |
|
| 233 | + $this->_set_hooks_properties(); |
|
| 234 | + //first let's verify we're on the right page |
|
| 235 | + if (! isset($this->_req_data['page']) |
|
| 236 | + || (isset($this->_req_data['page']) |
|
| 237 | + && $this->_adminpage_obj->page_slug |
|
| 238 | + != $this->_req_data['page'])) { |
|
| 239 | + return; |
|
| 240 | + } //get out nothing more to be done here. |
|
| 241 | + //allow for extends to modify properties |
|
| 242 | + if (method_exists($this, '_extend_properties')) { |
|
| 243 | + $this->_extend_properties(); |
|
| 244 | + } |
|
| 245 | + $this->_set_page_object(); |
|
| 246 | + $this->_init_hooks(); |
|
| 247 | + $this->_load_custom_methods(); |
|
| 248 | + $this->_load_routed_hooks(); |
|
| 249 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts_styles')); |
|
| 250 | + add_action('admin_enqueue_scripts', array($this, 'add_metaboxes'), 20); |
|
| 251 | + add_action('admin_enqueue_scripts', array($this, 'remove_metaboxes'), 15); |
|
| 252 | + $this->_ajax_hooks(); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * used by child classes to set the following properties: |
|
| 259 | + * $_ajax_func (optional) |
|
| 260 | + * $_init_func (optional) |
|
| 261 | + * $_metaboxes (optional) |
|
| 262 | + * $_scripts (optional) |
|
| 263 | + * $_styles (optional) |
|
| 264 | + * $_name (required) |
|
| 265 | + * Also in this method will be registered any scripts or styles loaded on the targeted page (as indicated in the |
|
| 266 | + * _scripts/_styles properties) Also children should place in this method any filters/actions that have to happen |
|
| 267 | + * really early on page load (just after admin_init) if they want to have them registered for handling early. |
|
| 268 | + * |
|
| 269 | + * @access protected |
|
| 270 | + * @abstract |
|
| 271 | + * @return void |
|
| 272 | + */ |
|
| 273 | + abstract protected function _set_hooks_properties(); |
|
| 274 | + |
|
| 275 | + |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * The hooks for enqueue_scripts and enqueue_styles will be run in here. Child classes need to define their |
|
| 279 | + * scripts and styles in the relevant $_scripts and $_styles properties. Child classes must have also already |
|
| 280 | + * registered the scripts and styles using wp_register_script and wp_register_style functions. |
|
| 281 | + * |
|
| 282 | + * @access public |
|
| 283 | + * @return void |
|
| 284 | + */ |
|
| 285 | + public function enqueue_scripts_styles() |
|
| 286 | + { |
|
| 287 | + |
|
| 288 | + if (! empty($this->_scripts_styles)) { |
|
| 289 | + //first let's do all the registrations |
|
| 290 | + if (! isset($this->_scripts_styles['registers'])) { |
|
| 291 | + $msg[] = __( |
|
| 292 | + 'There is no "registers" index in the <code>$this->_scripts_styles</code> property.', |
|
| 293 | + 'event_espresso' |
|
| 294 | + ); |
|
| 295 | + $msg[] = sprintf( |
|
| 296 | + __( |
|
| 297 | + 'Make sure you read the phpdoc comments above the definition of the $_scripts_styles property in the <code>EE_Admin_Hooks</code> class and modify according in the %s child', |
|
| 298 | + 'event_espresso' |
|
| 299 | + ), |
|
| 300 | + '<strong>' . $this->caller . '</strong>' |
|
| 301 | + ); |
|
| 302 | + throw new EE_Error(implode('||', $msg)); |
|
| 303 | + } |
|
| 304 | + foreach ($this->_scripts_styles['registers'] as $ref => $details) { |
|
| 305 | + $defaults = array( |
|
| 306 | + 'type' => 'js', |
|
| 307 | + 'url' => '', |
|
| 308 | + 'depends' => array(), |
|
| 309 | + 'version' => EVENT_ESPRESSO_VERSION, |
|
| 310 | + 'footer' => true, |
|
| 311 | + ); |
|
| 312 | + $details = wp_parse_args($details, $defaults); |
|
| 313 | + extract($details); |
|
| 314 | + //let's make sure that we set the 'registers' type if it's not set! We need it later to determine whhich enqueu we do |
|
| 315 | + $this->_scripts_styles['registers'][$ref]['type'] = $type; |
|
| 316 | + //let's make sure we're not missing any REQUIRED parameters |
|
| 317 | + if (empty($url)) { |
|
| 318 | + $msg[] = sprintf( |
|
| 319 | + __('Missing the url for the requested %s', 'event_espresso'), |
|
| 320 | + $type == 'js' ? 'script' : 'stylesheet' |
|
| 321 | + ); |
|
| 322 | + $msg[] = sprintf( |
|
| 323 | + __( |
|
| 324 | + 'Doublecheck your <code>$this->_scripts_styles</code> array in %s and make sure that there is a "url" set for the %s ref', |
|
| 325 | + 'event_espresso' |
|
| 326 | + ), |
|
| 327 | + '<strong>' . $this->caller . '</strong>', |
|
| 328 | + $ref |
|
| 329 | + ); |
|
| 330 | + throw new EE_Error(implode('||', $msg)); |
|
| 331 | + } |
|
| 332 | + //made it here so let's do the appropriate registration |
|
| 333 | + $type == 'js' |
|
| 334 | + ? wp_register_script($ref, $url, $depends, $version, $footer) |
|
| 335 | + : wp_register_style( |
|
| 336 | + $ref, |
|
| 337 | + $url, |
|
| 338 | + $depends, |
|
| 339 | + $version |
|
| 340 | + ); |
|
| 341 | + } |
|
| 342 | + //k now lets do the enqueues |
|
| 343 | + if (! isset($this->_scripts_styles['enqueues'])) { |
|
| 344 | + return; |
|
| 345 | + } //not sure if we should throw an error here or not. |
|
| 346 | + foreach ($this->_scripts_styles['enqueues'] as $ref => $routes) { |
|
| 347 | + //make sure $routes is an array |
|
| 348 | + $routes = (array)$routes; |
|
| 349 | + if (in_array($this->_current_route, $routes)) { |
|
| 350 | + $this->_scripts_styles['registers'][$ref]['type'] == 'js' ? wp_enqueue_script($ref) |
|
| 351 | + : wp_enqueue_style($ref); |
|
| 352 | + //if we have a localization for the script let's do that too. |
|
| 353 | + if (isset($this->_scripts_styles['localize'][$ref])) { |
|
| 354 | + foreach ($this->_scripts_styles['localize'][$ref] as $object_name => $indexes) { |
|
| 355 | + wp_localize_script( |
|
| 356 | + $ref, |
|
| 357 | + $object_name, |
|
| 358 | + $this->_scripts_styles['localize'][$ref][$object_name] |
|
| 359 | + ); |
|
| 360 | + } |
|
| 361 | + } |
|
| 362 | + } |
|
| 363 | + } |
|
| 364 | + //let's do the deregisters |
|
| 365 | + if (! isset($this->_scripts_styles['deregisters'])) { |
|
| 366 | + return; |
|
| 367 | + } |
|
| 368 | + foreach ($this->_scripts_styles['deregisters'] as $ref => $details) { |
|
| 369 | + $defaults = array( |
|
| 370 | + 'type' => 'js', |
|
| 371 | + ); |
|
| 372 | + $details = wp_parse_args($details, $defaults); |
|
| 373 | + extract($details); |
|
| 374 | + $type == 'js' ? wp_deregister_script($ref) : wp_deregister_style($ref); |
|
| 375 | + } |
|
| 376 | + } |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + |
|
| 380 | + |
|
| 381 | + /** |
|
| 382 | + * just set the defaults for the hooks properties. |
|
| 383 | + * |
|
| 384 | + * @access private |
|
| 385 | + * @return void |
|
| 386 | + */ |
|
| 387 | + private function _set_defaults() |
|
| 388 | + { |
|
| 389 | + $this->_ajax_func = $this->_init_func = $this->_metaboxes = $this->_scripts = $this->_styles = $this->_wp_action_filters_priority = array(); |
|
| 390 | + $this->_current_route = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'default'; |
|
| 391 | + $this->caller = get_class($this); |
|
| 392 | + $this->_extend = stripos($this->caller, 'Extend') ? true : false; |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * this sets the _page_object property |
|
| 399 | + * |
|
| 400 | + * @access protected |
|
| 401 | + * @return void |
|
| 402 | + */ |
|
| 403 | + protected function _set_page_object() |
|
| 404 | + { |
|
| 405 | + //first make sure $this->_name is set |
|
| 406 | + if (empty($this->_name)) { |
|
| 407 | + $msg[] = __('We can\'t load the page object', 'event_espresso'); |
|
| 408 | + $msg[] = sprintf( |
|
| 409 | + __("This is because the %s child class has not set the '_name' property", 'event_espresso'), |
|
| 410 | + $this->caller |
|
| 411 | + ); |
|
| 412 | + throw new EE_Error(implode('||', $msg)); |
|
| 413 | + } |
|
| 414 | + $ref = str_replace('_', ' ', $this->_name); //take the_message -> the message |
|
| 415 | + $ref = str_replace(' ', '_', ucwords($ref)) . '_Admin_Page'; //take the message -> The_Message |
|
| 416 | + //first default file (if exists) |
|
| 417 | + $decaf_file = EE_ADMIN_PAGES . $this->_name . DS . $ref . '.core.php'; |
|
| 418 | + if (is_readable($decaf_file)) { |
|
| 419 | + require_once($decaf_file); |
|
| 420 | + } |
|
| 421 | + //now we have to do require for extended file (if needed) |
|
| 422 | + if ($this->_extend) { |
|
| 423 | + require_once(EE_CORE_CAF_ADMIN_EXTEND . $this->_name . DS . 'Extend_' . $ref . '.core.php'); |
|
| 424 | + } |
|
| 425 | + //if we've got an extended class we use that! |
|
| 426 | + $ref = $this->_extend ? 'Extend_' . $ref : $ref; |
|
| 427 | + //let's make sure the class exists |
|
| 428 | + if (! class_exists($ref)) { |
|
| 429 | + $msg[] = __('We can\'t load the page object', 'event_espresso'); |
|
| 430 | + $msg[] = sprintf( |
|
| 431 | + __( |
|
| 432 | + 'The class name that was given is %s. Check the spelling and make sure its correct, also there needs to be an autoloader setup for the class', |
|
| 433 | + 'event_espresso' |
|
| 434 | + ), |
|
| 435 | + $ref |
|
| 436 | + ); |
|
| 437 | + throw new EE_Error(implode('||', $msg)); |
|
| 438 | + } |
|
| 439 | + $a = new ReflectionClass($ref); |
|
| 440 | + $this->_page_object = $a->newInstance(false); |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + |
|
| 444 | + /** |
|
| 445 | + * Child "hook" classes can declare any methods that they want executed when a specific page route is loaded. The |
|
| 446 | + * advantage of this is when doing things like running our own db interactions on saves etc. Remember that |
|
| 447 | + * $this->_req_data (all the _POST and _GET data) is available to your methods. |
|
| 448 | + * |
|
| 449 | + * @access private |
|
| 450 | + * @return void |
|
| 451 | + */ |
|
| 452 | + private function _load_custom_methods() |
|
| 453 | + { |
|
| 454 | + /** |
|
| 455 | + * method cannot be named 'default' (@see http://us3.php |
|
| 456 | + * .net/manual/en/reserved.keywords.php) so need to |
|
| 457 | + * handle routes that are "default" |
|
| 458 | + * |
|
| 459 | + * @since 4.3.0 |
|
| 460 | + */ |
|
| 461 | + $method_callback = $this->_current_route == 'default' ? 'default_callback' : $this->_current_route; |
|
| 462 | + //these run before the Admin_Page route executes. |
|
| 463 | + if (method_exists($this, $method_callback)) { |
|
| 464 | + call_user_func(array($this, $method_callback)); |
|
| 465 | + } |
|
| 466 | + //these run via the _redirect_after_action method in EE_Admin_Page which usually happens after non_UI methods in EE_Admin_Page classes. There are two redirect actions, the first fires before $query_args might be manipulated by "save and close" actions and the seond fires right before the actual redirect happens. |
|
| 467 | + //first the actions |
|
| 468 | + //note that these action hooks will have the $query_args value available. |
|
| 469 | + $admin_class_name = get_class($this->_adminpage_obj); |
|
| 470 | + if (method_exists($this, '_redirect_action_early_' . $this->_current_route)) { |
|
| 471 | + add_action( |
|
| 472 | + 'AHEE__' |
|
| 473 | + . $admin_class_name |
|
| 474 | + . '___redirect_after_action__before_redirect_modification_' |
|
| 475 | + . $this->_current_route, |
|
| 476 | + array($this, '_redirect_action_early_' . $this->_current_route), |
|
| 477 | + 10 |
|
| 478 | + ); |
|
| 479 | + } |
|
| 480 | + if (method_exists($this, '_redirect_action_' . $this->_current_route)) { |
|
| 481 | + add_action( |
|
| 482 | + 'AHEE_redirect_' . $admin_class_name . $this->_current_route, |
|
| 483 | + array($this, '_redirect_action_' . $this->_current_route), |
|
| 484 | + 10 |
|
| 485 | + ); |
|
| 486 | + } |
|
| 487 | + //let's hook into the _redirect itself and allow for changing where the user goes after redirect. This will have $query_args and $redirect_url available. |
|
| 488 | + if (method_exists($this, '_redirect_filter_' . $this->_current_route)) { |
|
| 489 | + add_filter( |
|
| 490 | + 'FHEE_redirect_' . $admin_class_name . $this->_current_route, |
|
| 491 | + array($this, '_redirect_filter_' . $this->_current_route), |
|
| 492 | + 10, |
|
| 493 | + 2 |
|
| 494 | + ); |
|
| 495 | + } |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + |
|
| 499 | + |
|
| 500 | + /** |
|
| 501 | + * This method will search for a corresponding method with a name matching the route and the wp_hook to run. This |
|
| 502 | + * allows child hook classes to target hooking into a specific wp action or filter hook ONLY on a certain route. |
|
| 503 | + * just remember, methods MUST be public Future hooks should be added in here to be access by child classes. |
|
| 504 | + * |
|
| 505 | + * @return void |
|
| 506 | + */ |
|
| 507 | + private function _load_routed_hooks() |
|
| 508 | + { |
|
| 509 | + |
|
| 510 | + //this array provides the hook action names that will be referenced. Key is the action. Value is an array with the type (action or filter) and the number of parameters for the hook. We'll default all priorities for automatic hooks to 10. |
|
| 511 | + $hook_filter_array = array( |
|
| 512 | + 'admin_footer' => array( |
|
| 513 | + 'type' => 'action', |
|
| 514 | + 'argnum' => 1, |
|
| 515 | + 'priority' => 10, |
|
| 516 | + ), |
|
| 517 | + 'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug . '_' . $this->_current_route => array( |
|
| 518 | + 'type' => 'filter', |
|
| 519 | + 'argnum' => 1, |
|
| 520 | + 'priority' => 10, |
|
| 521 | + ), |
|
| 522 | + 'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug => array( |
|
| 523 | + 'type' => 'filter', |
|
| 524 | + 'argnum' => 1, |
|
| 525 | + 'priority' => 10, |
|
| 526 | + ), |
|
| 527 | + 'FHEE_list_table_views' => array( |
|
| 528 | + 'type' => 'filter', |
|
| 529 | + 'argnum' => 1, |
|
| 530 | + 'priority' => 10, |
|
| 531 | + ), |
|
| 532 | + 'AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes' => array( |
|
| 533 | + 'type' => 'action', |
|
| 534 | + 'argnum' => 1, |
|
| 535 | + 'priority' => 10, |
|
| 536 | + ), |
|
| 537 | + ); |
|
| 538 | + foreach ($hook_filter_array as $hook => $args) { |
|
| 539 | + if (method_exists($this, $this->_current_route . '_' . $hook)) { |
|
| 540 | + if (isset($this->_wp_action_filters_priority[$hook])) { |
|
| 541 | + $args['priority'] = $this->_wp_action_filters_priority[$hook]; |
|
| 542 | + } |
|
| 543 | + if ($args['type'] == 'action') { |
|
| 544 | + add_action( |
|
| 545 | + $hook, |
|
| 546 | + array($this, $this->_current_route . '_' . $hook), |
|
| 547 | + $args['priority'], |
|
| 548 | + $args['argnum'] |
|
| 549 | + ); |
|
| 550 | + } else { |
|
| 551 | + add_filter( |
|
| 552 | + $hook, |
|
| 553 | + array($this, $this->_current_route . '_' . $hook), |
|
| 554 | + $args['priority'], |
|
| 555 | + $args['argnum'] |
|
| 556 | + ); |
|
| 557 | + } |
|
| 558 | + } |
|
| 559 | + } |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + |
|
| 563 | + /** |
|
| 564 | + * Loop throught the $_ajax_func array and add_actions for the array. |
|
| 565 | + * |
|
| 566 | + * @return void |
|
| 567 | + */ |
|
| 568 | + private function _ajax_hooks() |
|
| 569 | + { |
|
| 570 | + |
|
| 571 | + if (empty($this->_ajax_func)) { |
|
| 572 | + return; |
|
| 573 | + } //get out there's nothing to take care of. |
|
| 574 | + foreach ($this->_ajax_func as $action => $method) { |
|
| 575 | + //make sure method exists |
|
| 576 | + if (! method_exists($this, $method)) { |
|
| 577 | + $msg[] = __( |
|
| 578 | + 'There is no corresponding method for the hook labeled in the _ajax_func array', |
|
| 579 | + 'event_espresso' |
|
| 580 | + ) . '<br />'; |
|
| 581 | + $msg[] = sprintf( |
|
| 582 | + __( |
|
| 583 | + 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
|
| 584 | + 'event_espresso' |
|
| 585 | + ), |
|
| 586 | + $method, |
|
| 587 | + $this->caller |
|
| 588 | + ); |
|
| 589 | + throw new EE_Error(implode('||', $msg)); |
|
| 590 | + } |
|
| 591 | + add_action('wp_ajax_' . $action, array($this, $method)); |
|
| 592 | + } |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + |
|
| 596 | + |
|
| 597 | + /** |
|
| 598 | + * Loop throught the $_init_func array and add_actions for the array. |
|
| 599 | + * |
|
| 600 | + * @return void |
|
| 601 | + */ |
|
| 602 | + protected function _init_hooks() |
|
| 603 | + { |
|
| 604 | + if (empty($this->_init_func)) { |
|
| 605 | + return; |
|
| 606 | + } //get out there's nothing to take care of. |
|
| 607 | + //We need to determine what page_route we are on! |
|
| 608 | + $current_route = isset ($_REQUEST['action']) ? $_REQUEST['action'] : 'default'; |
|
| 609 | + foreach ($this->_init_func as $route => $method) { |
|
| 610 | + //make sure method exists |
|
| 611 | + if (! method_exists($this, $method)) { |
|
| 612 | + $msg[] = __( |
|
| 613 | + 'There is no corresponding method for the hook labeled in the _init_func array', |
|
| 614 | + 'event_espresso' |
|
| 615 | + ) . '<br />'; |
|
| 616 | + $msg[] = sprintf( |
|
| 617 | + __( |
|
| 618 | + 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
|
| 619 | + 'event_espresso' |
|
| 620 | + ), |
|
| 621 | + $method, |
|
| 622 | + $this->caller |
|
| 623 | + ); |
|
| 624 | + throw new EE_Error(implode('||', $msg)); |
|
| 625 | + } |
|
| 626 | + if ($route == $this->_current_route) { |
|
| 627 | + add_action('admin_init', array($this, $method)); |
|
| 628 | + } |
|
| 629 | + } |
|
| 630 | + } |
|
| 631 | + |
|
| 632 | + |
|
| 633 | + |
|
| 634 | + /** |
|
| 635 | + * Loop through the _metaboxes property and add_metaboxes accordingly |
|
| 636 | + * //todo we could eventually make this a config component class (i.e. new EE_Metabox); |
|
| 637 | + * |
|
| 638 | + * @access public |
|
| 639 | + * @return void |
|
| 640 | + */ |
|
| 641 | + public function add_metaboxes() |
|
| 642 | + { |
|
| 643 | + if (empty($this->_metaboxes)) { |
|
| 644 | + return; |
|
| 645 | + } //get out we don't have any metaboxes to set for this connection |
|
| 646 | + $this->_handle_metabox_array($this->_metaboxes); |
|
| 647 | + } |
|
| 648 | + |
|
| 649 | + |
|
| 650 | + |
|
| 651 | + private function _handle_metabox_array($boxes, $add = true) |
|
| 652 | + { |
|
| 653 | + |
|
| 654 | + foreach ($boxes as $box) { |
|
| 655 | + if (! isset($box['page_route'])) { |
|
| 656 | + continue; |
|
| 657 | + } //we dont' have a valid array |
|
| 658 | + //let's make sure $box['page_route'] is an array so the "foreach" will work. |
|
| 659 | + $box['page_route'] = (array)$box['page_route']; |
|
| 660 | + foreach ($box['page_route'] as $route) { |
|
| 661 | + if ($route != $this->_current_route) { |
|
| 662 | + continue; |
|
| 663 | + } //get out we only add metaboxes for set route. |
|
| 664 | + if ($add) { |
|
| 665 | + $this->_add_metabox($box); |
|
| 666 | + } else { |
|
| 667 | + $this->_remove_metabox($box); |
|
| 668 | + } |
|
| 669 | + } |
|
| 670 | + } |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + |
|
| 674 | + |
|
| 675 | + /** |
|
| 676 | + * Loop through the _remove_metaboxes property and remove metaboxes accordingly. |
|
| 677 | + * |
|
| 678 | + * @access public |
|
| 679 | + * @return void |
|
| 680 | + */ |
|
| 681 | + public function remove_metaboxes() |
|
| 682 | + { |
|
| 683 | + |
|
| 684 | + if (empty($this->_remove_metaboxes)) { |
|
| 685 | + return; |
|
| 686 | + } //get out there are no metaboxes to remove |
|
| 687 | + $this->_handle_metabox_array($this->_remove_metaboxes, false); |
|
| 688 | + } |
|
| 689 | + |
|
| 690 | + |
|
| 691 | + /** |
|
| 692 | + * This just handles adding a metabox |
|
| 693 | + * |
|
| 694 | + * @access private |
|
| 695 | + * @param array $args an array of args that have been set for this metabox by the child class |
|
| 696 | + */ |
|
| 697 | + private function _add_metabox($args) |
|
| 698 | + { |
|
| 699 | + $current_screen = get_current_screen(); |
|
| 700 | + $screen_id = is_object($current_screen) ? $current_screen->id : null; |
|
| 701 | + $func = isset($args['func']) ? $args['func'] : 'some_invalid_callback'; |
|
| 702 | + //set defaults |
|
| 703 | + $defaults = array( |
|
| 704 | + 'func' => $func, |
|
| 705 | + 'id' => $this->caller . '_' . $func . '_metabox', |
|
| 706 | + 'priority' => 'default', |
|
| 707 | + 'label' => $this->caller, |
|
| 708 | + 'context' => 'advanced', |
|
| 709 | + 'callback_args' => array(), |
|
| 710 | + 'page' => isset($args['page']) ? $args['page'] : $screen_id, |
|
| 711 | + ); |
|
| 712 | + $args = wp_parse_args($args, $defaults); |
|
| 713 | + extract($args); |
|
| 714 | + //make sure method exists |
|
| 715 | + if (! method_exists($this, $func)) { |
|
| 716 | + $msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso') . '<br />'; |
|
| 717 | + $msg[] = sprintf( |
|
| 718 | + __( |
|
| 719 | + 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
|
| 720 | + 'event_espresso' |
|
| 721 | + ), |
|
| 722 | + $func, |
|
| 723 | + $this->caller |
|
| 724 | + ); |
|
| 725 | + throw new EE_Error(implode('||', $msg)); |
|
| 726 | + } |
|
| 727 | + //everything checks out so lets add the metabox |
|
| 728 | + add_meta_box($id, $label, array($this, $func), $page, $context, $priority, $callback_args); |
|
| 729 | + } |
|
| 730 | + |
|
| 731 | + |
|
| 732 | + |
|
| 733 | + private function _remove_metabox($args) |
|
| 734 | + { |
|
| 735 | + $current_screen = get_current_screen(); |
|
| 736 | + $screen_id = is_object($current_screen) ? $current_screen->id : null; |
|
| 737 | + $func = isset($args['func']) ? $args['func'] : 'some_invalid_callback'; |
|
| 738 | + //set defaults |
|
| 739 | + $defaults = array( |
|
| 740 | + 'id' => isset($args['id']) |
|
| 741 | + ? $args['id'] |
|
| 742 | + : $this->_current_route |
|
| 743 | + . '_' |
|
| 744 | + . $this->caller |
|
| 745 | + . '_' |
|
| 746 | + . $func |
|
| 747 | + . '_metabox', |
|
| 748 | + 'context' => 'default', |
|
| 749 | + 'screen' => isset($args['screen']) ? $args['screen'] : $screen_id |
|
| 750 | + ); |
|
| 751 | + $args = wp_parse_args($args, $defaults); |
|
| 752 | + extract($args); |
|
| 753 | + //everything checks out so lets remove the box! |
|
| 754 | + remove_meta_box($id, $screen, $context); |
|
| 755 | + } |
|
| 756 | 756 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 3 | 3 | exit('NO direct script access allowed'); |
| 4 | 4 | } |
| 5 | 5 | |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | $this->_set_defaults(); |
| 233 | 233 | $this->_set_hooks_properties(); |
| 234 | 234 | //first let's verify we're on the right page |
| 235 | - if (! isset($this->_req_data['page']) |
|
| 235 | + if ( ! isset($this->_req_data['page']) |
|
| 236 | 236 | || (isset($this->_req_data['page']) |
| 237 | 237 | && $this->_adminpage_obj->page_slug |
| 238 | 238 | != $this->_req_data['page'])) { |
@@ -285,9 +285,9 @@ discard block |
||
| 285 | 285 | public function enqueue_scripts_styles() |
| 286 | 286 | { |
| 287 | 287 | |
| 288 | - if (! empty($this->_scripts_styles)) { |
|
| 288 | + if ( ! empty($this->_scripts_styles)) { |
|
| 289 | 289 | //first let's do all the registrations |
| 290 | - if (! isset($this->_scripts_styles['registers'])) { |
|
| 290 | + if ( ! isset($this->_scripts_styles['registers'])) { |
|
| 291 | 291 | $msg[] = __( |
| 292 | 292 | 'There is no "registers" index in the <code>$this->_scripts_styles</code> property.', |
| 293 | 293 | 'event_espresso' |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | 'Make sure you read the phpdoc comments above the definition of the $_scripts_styles property in the <code>EE_Admin_Hooks</code> class and modify according in the %s child', |
| 298 | 298 | 'event_espresso' |
| 299 | 299 | ), |
| 300 | - '<strong>' . $this->caller . '</strong>' |
|
| 300 | + '<strong>'.$this->caller.'</strong>' |
|
| 301 | 301 | ); |
| 302 | 302 | throw new EE_Error(implode('||', $msg)); |
| 303 | 303 | } |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | 'version' => EVENT_ESPRESSO_VERSION, |
| 310 | 310 | 'footer' => true, |
| 311 | 311 | ); |
| 312 | - $details = wp_parse_args($details, $defaults); |
|
| 312 | + $details = wp_parse_args($details, $defaults); |
|
| 313 | 313 | extract($details); |
| 314 | 314 | //let's make sure that we set the 'registers' type if it's not set! We need it later to determine whhich enqueu we do |
| 315 | 315 | $this->_scripts_styles['registers'][$ref]['type'] = $type; |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | 'Doublecheck your <code>$this->_scripts_styles</code> array in %s and make sure that there is a "url" set for the %s ref', |
| 325 | 325 | 'event_espresso' |
| 326 | 326 | ), |
| 327 | - '<strong>' . $this->caller . '</strong>', |
|
| 327 | + '<strong>'.$this->caller.'</strong>', |
|
| 328 | 328 | $ref |
| 329 | 329 | ); |
| 330 | 330 | throw new EE_Error(implode('||', $msg)); |
@@ -340,12 +340,12 @@ discard block |
||
| 340 | 340 | ); |
| 341 | 341 | } |
| 342 | 342 | //k now lets do the enqueues |
| 343 | - if (! isset($this->_scripts_styles['enqueues'])) { |
|
| 343 | + if ( ! isset($this->_scripts_styles['enqueues'])) { |
|
| 344 | 344 | return; |
| 345 | 345 | } //not sure if we should throw an error here or not. |
| 346 | 346 | foreach ($this->_scripts_styles['enqueues'] as $ref => $routes) { |
| 347 | 347 | //make sure $routes is an array |
| 348 | - $routes = (array)$routes; |
|
| 348 | + $routes = (array) $routes; |
|
| 349 | 349 | if (in_array($this->_current_route, $routes)) { |
| 350 | 350 | $this->_scripts_styles['registers'][$ref]['type'] == 'js' ? wp_enqueue_script($ref) |
| 351 | 351 | : wp_enqueue_style($ref); |
@@ -362,7 +362,7 @@ discard block |
||
| 362 | 362 | } |
| 363 | 363 | } |
| 364 | 364 | //let's do the deregisters |
| 365 | - if (! isset($this->_scripts_styles['deregisters'])) { |
|
| 365 | + if ( ! isset($this->_scripts_styles['deregisters'])) { |
|
| 366 | 366 | return; |
| 367 | 367 | } |
| 368 | 368 | foreach ($this->_scripts_styles['deregisters'] as $ref => $details) { |
@@ -412,20 +412,20 @@ discard block |
||
| 412 | 412 | throw new EE_Error(implode('||', $msg)); |
| 413 | 413 | } |
| 414 | 414 | $ref = str_replace('_', ' ', $this->_name); //take the_message -> the message |
| 415 | - $ref = str_replace(' ', '_', ucwords($ref)) . '_Admin_Page'; //take the message -> The_Message |
|
| 415 | + $ref = str_replace(' ', '_', ucwords($ref)).'_Admin_Page'; //take the message -> The_Message |
|
| 416 | 416 | //first default file (if exists) |
| 417 | - $decaf_file = EE_ADMIN_PAGES . $this->_name . DS . $ref . '.core.php'; |
|
| 417 | + $decaf_file = EE_ADMIN_PAGES.$this->_name.DS.$ref.'.core.php'; |
|
| 418 | 418 | if (is_readable($decaf_file)) { |
| 419 | 419 | require_once($decaf_file); |
| 420 | 420 | } |
| 421 | 421 | //now we have to do require for extended file (if needed) |
| 422 | 422 | if ($this->_extend) { |
| 423 | - require_once(EE_CORE_CAF_ADMIN_EXTEND . $this->_name . DS . 'Extend_' . $ref . '.core.php'); |
|
| 423 | + require_once(EE_CORE_CAF_ADMIN_EXTEND.$this->_name.DS.'Extend_'.$ref.'.core.php'); |
|
| 424 | 424 | } |
| 425 | 425 | //if we've got an extended class we use that! |
| 426 | - $ref = $this->_extend ? 'Extend_' . $ref : $ref; |
|
| 426 | + $ref = $this->_extend ? 'Extend_'.$ref : $ref; |
|
| 427 | 427 | //let's make sure the class exists |
| 428 | - if (! class_exists($ref)) { |
|
| 428 | + if ( ! class_exists($ref)) { |
|
| 429 | 429 | $msg[] = __('We can\'t load the page object', 'event_espresso'); |
| 430 | 430 | $msg[] = sprintf( |
| 431 | 431 | __( |
@@ -467,28 +467,28 @@ discard block |
||
| 467 | 467 | //first the actions |
| 468 | 468 | //note that these action hooks will have the $query_args value available. |
| 469 | 469 | $admin_class_name = get_class($this->_adminpage_obj); |
| 470 | - if (method_exists($this, '_redirect_action_early_' . $this->_current_route)) { |
|
| 470 | + if (method_exists($this, '_redirect_action_early_'.$this->_current_route)) { |
|
| 471 | 471 | add_action( |
| 472 | 472 | 'AHEE__' |
| 473 | 473 | . $admin_class_name |
| 474 | 474 | . '___redirect_after_action__before_redirect_modification_' |
| 475 | 475 | . $this->_current_route, |
| 476 | - array($this, '_redirect_action_early_' . $this->_current_route), |
|
| 476 | + array($this, '_redirect_action_early_'.$this->_current_route), |
|
| 477 | 477 | 10 |
| 478 | 478 | ); |
| 479 | 479 | } |
| 480 | - if (method_exists($this, '_redirect_action_' . $this->_current_route)) { |
|
| 480 | + if (method_exists($this, '_redirect_action_'.$this->_current_route)) { |
|
| 481 | 481 | add_action( |
| 482 | - 'AHEE_redirect_' . $admin_class_name . $this->_current_route, |
|
| 483 | - array($this, '_redirect_action_' . $this->_current_route), |
|
| 482 | + 'AHEE_redirect_'.$admin_class_name.$this->_current_route, |
|
| 483 | + array($this, '_redirect_action_'.$this->_current_route), |
|
| 484 | 484 | 10 |
| 485 | 485 | ); |
| 486 | 486 | } |
| 487 | 487 | //let's hook into the _redirect itself and allow for changing where the user goes after redirect. This will have $query_args and $redirect_url available. |
| 488 | - if (method_exists($this, '_redirect_filter_' . $this->_current_route)) { |
|
| 488 | + if (method_exists($this, '_redirect_filter_'.$this->_current_route)) { |
|
| 489 | 489 | add_filter( |
| 490 | - 'FHEE_redirect_' . $admin_class_name . $this->_current_route, |
|
| 491 | - array($this, '_redirect_filter_' . $this->_current_route), |
|
| 490 | + 'FHEE_redirect_'.$admin_class_name.$this->_current_route, |
|
| 491 | + array($this, '_redirect_filter_'.$this->_current_route), |
|
| 492 | 492 | 10, |
| 493 | 493 | 2 |
| 494 | 494 | ); |
@@ -514,12 +514,12 @@ discard block |
||
| 514 | 514 | 'argnum' => 1, |
| 515 | 515 | 'priority' => 10, |
| 516 | 516 | ), |
| 517 | - 'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug . '_' . $this->_current_route => array( |
|
| 517 | + 'FHEE_list_table_views_'.$this->_adminpage_obj->page_slug.'_'.$this->_current_route => array( |
|
| 518 | 518 | 'type' => 'filter', |
| 519 | 519 | 'argnum' => 1, |
| 520 | 520 | 'priority' => 10, |
| 521 | 521 | ), |
| 522 | - 'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug => array( |
|
| 522 | + 'FHEE_list_table_views_'.$this->_adminpage_obj->page_slug => array( |
|
| 523 | 523 | 'type' => 'filter', |
| 524 | 524 | 'argnum' => 1, |
| 525 | 525 | 'priority' => 10, |
@@ -536,21 +536,21 @@ discard block |
||
| 536 | 536 | ), |
| 537 | 537 | ); |
| 538 | 538 | foreach ($hook_filter_array as $hook => $args) { |
| 539 | - if (method_exists($this, $this->_current_route . '_' . $hook)) { |
|
| 539 | + if (method_exists($this, $this->_current_route.'_'.$hook)) { |
|
| 540 | 540 | if (isset($this->_wp_action_filters_priority[$hook])) { |
| 541 | 541 | $args['priority'] = $this->_wp_action_filters_priority[$hook]; |
| 542 | 542 | } |
| 543 | 543 | if ($args['type'] == 'action') { |
| 544 | 544 | add_action( |
| 545 | 545 | $hook, |
| 546 | - array($this, $this->_current_route . '_' . $hook), |
|
| 546 | + array($this, $this->_current_route.'_'.$hook), |
|
| 547 | 547 | $args['priority'], |
| 548 | 548 | $args['argnum'] |
| 549 | 549 | ); |
| 550 | 550 | } else { |
| 551 | 551 | add_filter( |
| 552 | 552 | $hook, |
| 553 | - array($this, $this->_current_route . '_' . $hook), |
|
| 553 | + array($this, $this->_current_route.'_'.$hook), |
|
| 554 | 554 | $args['priority'], |
| 555 | 555 | $args['argnum'] |
| 556 | 556 | ); |
@@ -573,11 +573,11 @@ discard block |
||
| 573 | 573 | } //get out there's nothing to take care of. |
| 574 | 574 | foreach ($this->_ajax_func as $action => $method) { |
| 575 | 575 | //make sure method exists |
| 576 | - if (! method_exists($this, $method)) { |
|
| 576 | + if ( ! method_exists($this, $method)) { |
|
| 577 | 577 | $msg[] = __( |
| 578 | 578 | 'There is no corresponding method for the hook labeled in the _ajax_func array', |
| 579 | 579 | 'event_espresso' |
| 580 | - ) . '<br />'; |
|
| 580 | + ).'<br />'; |
|
| 581 | 581 | $msg[] = sprintf( |
| 582 | 582 | __( |
| 583 | 583 | 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
@@ -588,7 +588,7 @@ discard block |
||
| 588 | 588 | ); |
| 589 | 589 | throw new EE_Error(implode('||', $msg)); |
| 590 | 590 | } |
| 591 | - add_action('wp_ajax_' . $action, array($this, $method)); |
|
| 591 | + add_action('wp_ajax_'.$action, array($this, $method)); |
|
| 592 | 592 | } |
| 593 | 593 | } |
| 594 | 594 | |
@@ -608,11 +608,11 @@ discard block |
||
| 608 | 608 | $current_route = isset ($_REQUEST['action']) ? $_REQUEST['action'] : 'default'; |
| 609 | 609 | foreach ($this->_init_func as $route => $method) { |
| 610 | 610 | //make sure method exists |
| 611 | - if (! method_exists($this, $method)) { |
|
| 611 | + if ( ! method_exists($this, $method)) { |
|
| 612 | 612 | $msg[] = __( |
| 613 | 613 | 'There is no corresponding method for the hook labeled in the _init_func array', |
| 614 | 614 | 'event_espresso' |
| 615 | - ) . '<br />'; |
|
| 615 | + ).'<br />'; |
|
| 616 | 616 | $msg[] = sprintf( |
| 617 | 617 | __( |
| 618 | 618 | 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
@@ -652,11 +652,11 @@ discard block |
||
| 652 | 652 | { |
| 653 | 653 | |
| 654 | 654 | foreach ($boxes as $box) { |
| 655 | - if (! isset($box['page_route'])) { |
|
| 655 | + if ( ! isset($box['page_route'])) { |
|
| 656 | 656 | continue; |
| 657 | 657 | } //we dont' have a valid array |
| 658 | 658 | //let's make sure $box['page_route'] is an array so the "foreach" will work. |
| 659 | - $box['page_route'] = (array)$box['page_route']; |
|
| 659 | + $box['page_route'] = (array) $box['page_route']; |
|
| 660 | 660 | foreach ($box['page_route'] as $route) { |
| 661 | 661 | if ($route != $this->_current_route) { |
| 662 | 662 | continue; |
@@ -702,7 +702,7 @@ discard block |
||
| 702 | 702 | //set defaults |
| 703 | 703 | $defaults = array( |
| 704 | 704 | 'func' => $func, |
| 705 | - 'id' => $this->caller . '_' . $func . '_metabox', |
|
| 705 | + 'id' => $this->caller.'_'.$func.'_metabox', |
|
| 706 | 706 | 'priority' => 'default', |
| 707 | 707 | 'label' => $this->caller, |
| 708 | 708 | 'context' => 'advanced', |
@@ -712,8 +712,8 @@ discard block |
||
| 712 | 712 | $args = wp_parse_args($args, $defaults); |
| 713 | 713 | extract($args); |
| 714 | 714 | //make sure method exists |
| 715 | - if (! method_exists($this, $func)) { |
|
| 716 | - $msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso') . '<br />'; |
|
| 715 | + if ( ! method_exists($this, $func)) { |
|
| 716 | + $msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso').'<br />'; |
|
| 717 | 717 | $msg[] = sprintf( |
| 718 | 718 | __( |
| 719 | 719 | 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
@@ -205,7 +205,6 @@ discard block |
||
| 205 | 205 | * |
| 206 | 206 | * @access public |
| 207 | 207 | * @uses _initialize_admin_page() |
| 208 | - * @param string $dir_name directory name for specific admin_page being loaded. |
|
| 209 | 208 | * @return void |
| 210 | 209 | */ |
| 211 | 210 | public function initialize_admin_page() |
@@ -221,6 +220,9 @@ discard block |
||
| 221 | 220 | |
| 222 | 221 | |
| 223 | 222 | |
| 223 | + /** |
|
| 224 | + * @param string $wp_page_slug |
|
| 225 | + */ |
|
| 224 | 226 | public function set_page_dependencies($wp_page_slug) |
| 225 | 227 | { |
| 226 | 228 | if (! $this->_load_page) { |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | /** |
| 5 | 5 | * Event Espresso |
@@ -28,443 +28,443 @@ discard block |
||
| 28 | 28 | abstract class EE_Admin_Page_Init extends EE_Base |
| 29 | 29 | { |
| 30 | 30 | |
| 31 | - //identity properties (set in _set_defaults and _set_init_properties) |
|
| 32 | - public $label; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Menu map has a capability. However, this allows admin pages to have separate capability requirements for menus |
|
| 36 | - * and accessing pages. If capability is NOT set, then it defaults to the menu_map capability. |
|
| 37 | - * |
|
| 38 | - * @var string |
|
| 39 | - */ |
|
| 40 | - public $capability; |
|
| 41 | - |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * This holds the menu map object for this admin page. |
|
| 45 | - * |
|
| 46 | - * @var EE_Admin_Page_Menu_Map |
|
| 47 | - */ |
|
| 48 | - protected $_menu_map; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * deprecated |
|
| 52 | - */ |
|
| 53 | - public $menu_label; |
|
| 54 | - public $menu_slug; |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - //set in _set_defaults |
|
| 59 | - protected $_folder_name; |
|
| 60 | - protected $_folder_path; |
|
| 61 | - protected $_file_name; |
|
| 62 | - public $hook_file; |
|
| 63 | - protected $_wp_page_slug; |
|
| 64 | - protected $_routing; |
|
| 65 | - |
|
| 66 | - |
|
| 67 | - //will hold page object. |
|
| 68 | - protected $_loaded_page_object; |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - //for caf |
|
| 72 | - protected $_files_hooked; |
|
| 73 | - protected $_hook_paths; |
|
| 74 | - |
|
| 75 | - //load_page? |
|
| 76 | - private $_load_page; |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @Constructor |
|
| 82 | - * @access public |
|
| 83 | - * @return void |
|
| 84 | - */ |
|
| 85 | - public function __construct() |
|
| 86 | - { |
|
| 87 | - //set global defaults |
|
| 88 | - $this->_set_defaults(); |
|
| 89 | - //set properties that are always available with objects. |
|
| 90 | - $this->_set_init_properties(); |
|
| 91 | - //global styles/scripts across all wp admin pages |
|
| 92 | - add_action('admin_enqueue_scripts', array($this, 'load_wp_global_scripts_styles'), 5); |
|
| 93 | - //load initial stuff. |
|
| 94 | - $this->_set_file_and_folder_name(); |
|
| 95 | - $this->_set_menu_map(); |
|
| 96 | - if (empty($this->_menu_map) || is_array($this->_menu_map)) { |
|
| 97 | - EE_Error::doing_it_wrong( |
|
| 98 | - get_class($this) . '::$_menu_map', |
|
| 99 | - sprintf( |
|
| 100 | - __( |
|
| 101 | - 'The EE4 addon with the class %s is setting up the _menu_map property incorrectly for this version of EE core. Please see Admin_Page_Init class examples in core for the new way of setting this property up.', |
|
| 102 | - 'event_espresso' |
|
| 103 | - ), |
|
| 104 | - get_class($this) |
|
| 105 | - ), |
|
| 106 | - '4.4.0' |
|
| 107 | - ); |
|
| 108 | - return; |
|
| 109 | - } |
|
| 110 | - //set default capability |
|
| 111 | - $this->_set_capability(); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * _set_init_properties |
|
| 118 | - * Child classes use to set the following properties: |
|
| 119 | - * $label |
|
| 120 | - * |
|
| 121 | - * @abstract |
|
| 122 | - * @access protected |
|
| 123 | - * @return void |
|
| 124 | - */ |
|
| 125 | - abstract protected function _set_init_properties(); |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * _set_menu_map is a function that child classes use to set the menu_map property (which should be an instance of |
|
| 131 | - * EE_Admin_Page_Menu_Map. Their menu can either be EE_Admin_Page_Main_Menu or EE_Admin_Page_Sub_Menu. |
|
| 132 | - * |
|
| 133 | - * @since 4.4.0 |
|
| 134 | - * @ return void. |
|
| 135 | - */ |
|
| 136 | - protected function _set_menu_map() |
|
| 137 | - { |
|
| 138 | - return array(); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * returns the menu map for this admin page |
|
| 145 | - * |
|
| 146 | - * @since 4.4.0 |
|
| 147 | - * @return EE_Admin_Page_Menu_Map |
|
| 148 | - */ |
|
| 149 | - public function get_menu_map() |
|
| 150 | - { |
|
| 151 | - return $this->_menu_map; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * This loads scripts and styles for the EE_Admin system |
|
| 158 | - * that must be available on ALL WP admin pages (i.e. EE_menu items) |
|
| 159 | - * |
|
| 160 | - * @return void |
|
| 161 | - */ |
|
| 162 | - public function load_wp_global_scripts_styles() |
|
| 163 | - { |
|
| 164 | - wp_register_style( |
|
| 165 | - 'espresso_menu', |
|
| 166 | - EE_ADMIN_URL . 'assets/admin-menu-styles.css', |
|
| 167 | - array('dashicons'), |
|
| 168 | - EVENT_ESPRESSO_VERSION |
|
| 169 | - ); |
|
| 170 | - wp_enqueue_style('espresso_menu'); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * this sets default properties (might be overridden in _set_init_properties); |
|
| 177 | - * |
|
| 178 | - * @access private |
|
| 179 | - * @return void |
|
| 180 | - */ |
|
| 181 | - private function _set_defaults() |
|
| 182 | - { |
|
| 183 | - $this->_file_name = $this->_folder_name = $this->_wp_page_slug = $this->capability = null; |
|
| 184 | - $this->_routing = true; |
|
| 185 | - $this->_load_page = false; |
|
| 186 | - $this->_files_hooked = $this->_hook_paths = array(); |
|
| 187 | - //menu_map |
|
| 188 | - $this->_menu_map = $this->get_menu_map(); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - |
|
| 192 | - |
|
| 193 | - protected function _set_capability() |
|
| 194 | - { |
|
| 195 | - $capability = empty($this->capability) ? $this->_menu_map->capability : $this->capability; |
|
| 196 | - $this->capability = apply_filters('FHEE_' . $this->_menu_map->menu_slug . '_capability', $capability); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * initialize_admin_page |
|
| 203 | - * This method is what executes the loading of the specific page class for the given dir_name as called by the |
|
| 204 | - * EE_Admin_Init class. |
|
| 205 | - * |
|
| 206 | - * @access public |
|
| 207 | - * @uses _initialize_admin_page() |
|
| 208 | - * @param string $dir_name directory name for specific admin_page being loaded. |
|
| 209 | - * @return void |
|
| 210 | - */ |
|
| 211 | - public function initialize_admin_page() |
|
| 212 | - { |
|
| 213 | - //let's check user access first |
|
| 214 | - $this->_check_user_access(); |
|
| 215 | - if (! is_object($this->_loaded_page_object)) { |
|
| 216 | - return; |
|
| 217 | - } |
|
| 218 | - $this->_loaded_page_object->route_admin_request(); |
|
| 219 | - return; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - |
|
| 223 | - |
|
| 224 | - public function set_page_dependencies($wp_page_slug) |
|
| 225 | - { |
|
| 226 | - if (! $this->_load_page) { |
|
| 227 | - return; |
|
| 228 | - } |
|
| 229 | - if (! is_object($this->_loaded_page_object)) { |
|
| 230 | - $msg[] = __( |
|
| 231 | - 'We can\'t load the page because we\'re missing a valid page object that tells us what to load', |
|
| 232 | - 'event_espresso' |
|
| 233 | - ); |
|
| 234 | - $msg[] = $msg[0] . "\r\n" . sprintf( |
|
| 235 | - __( |
|
| 236 | - 'The custom slug you have set for this page is %s. This means we\'re looking for the class %s_Admin_Page (found in %s_Admin_Page.core.php) within your %s directory', |
|
| 237 | - 'event_espresso' |
|
| 238 | - ), |
|
| 239 | - $this->_file_name, |
|
| 240 | - $this->_file_name, |
|
| 241 | - $this->_folder_path . $this->_file_name, |
|
| 242 | - $this->_menu_map->menu_slug |
|
| 243 | - ); |
|
| 244 | - throw new EE_Error(implode('||', $msg)); |
|
| 245 | - } |
|
| 246 | - $this->_loaded_page_object->set_wp_page_slug($wp_page_slug); |
|
| 247 | - $page_hook = 'load-' . $wp_page_slug; |
|
| 248 | - //hook into page load hook so all page specific stuff get's loaded. |
|
| 249 | - if (! empty($wp_page_slug)) { |
|
| 250 | - add_action($page_hook, array($this->_loaded_page_object, 'load_page_dependencies')); |
|
| 251 | - } |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * This executes the intial page loads for EE_Admin pages to take care of any ajax or other code needing to run |
|
| 257 | - * before the load-page... hook. Note, the page loads are happening around the wp_init hook. |
|
| 258 | - * |
|
| 259 | - * @return void |
|
| 260 | - */ |
|
| 261 | - public function do_initial_loads() |
|
| 262 | - { |
|
| 263 | - //no loading or initializing if menu map is setup incorrectly. |
|
| 264 | - if (empty($this->_menu_map) || is_array($this->_menu_map)) { |
|
| 265 | - return; |
|
| 266 | - } |
|
| 267 | - $this->_initialize_admin_page(); |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * all we're doing here is setting the $_file_name property for later use. |
|
| 273 | - * |
|
| 274 | - * @access private |
|
| 275 | - * @return void |
|
| 276 | - */ |
|
| 277 | - private function _set_file_and_folder_name() |
|
| 278 | - { |
|
| 279 | - $bt = debug_backtrace(); |
|
| 280 | - //for more reliable determination of folder name |
|
| 281 | - //we're using this to get the actual folder name of the CALLING class (i.e. the child class that extends this). Why? Because $this->menu_slug may be different than the folder name (to avoid conflicts with other plugins) |
|
| 282 | - $class = get_class($this); |
|
| 283 | - foreach ($bt as $index => $values) { |
|
| 284 | - if (isset($values['class']) && $values['class'] == $class) { |
|
| 285 | - $file_index = $index - 1; |
|
| 286 | - $this->_folder_name = basename(dirname($bt[$file_index]['file'])); |
|
| 287 | - if (! empty($this->_folder_name)) { |
|
| 288 | - break; |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - } |
|
| 292 | - $this->_folder_path = EE_ADMIN_PAGES . $this->_folder_name . DS; |
|
| 293 | - $this->_file_name = preg_replace('/^ee/', 'EE', $this->_folder_name); |
|
| 294 | - $this->_file_name = ucwords(str_replace('_', ' ', $this->_file_name)); |
|
| 295 | - $this->_file_name = str_replace(' ', '_', $this->_file_name); |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - |
|
| 299 | - /** |
|
| 300 | - * This automatically checks if we have a hook class in the loaded child directory. If we DO then we will register |
|
| 301 | - * it with the appropriate pages. That way all we have to do is make sure the file is named correctly and |
|
| 302 | - * "dropped" in. Example: if we wanted to set this up for Messages hooking into Events then we would do: |
|
| 303 | - * events_Messages_Hooks.class.php |
|
| 304 | - * |
|
| 305 | - * @param bool $extend This indicates whether we're checking the extend directory for any register_hooks |
|
| 306 | - * files/classes |
|
| 307 | - * @return array |
|
| 308 | - */ |
|
| 309 | - public function register_hooks($extend = false) |
|
| 310 | - { |
|
| 311 | - |
|
| 312 | - //get a list of files in the directory that have the "Hook" in their name an |
|
| 313 | - //if this is an extended check (i.e. caf is active) then we will scan the caffeinated/extend directory first and any hook files that are found will be have their reference added to the $_files_hook array property. Then, we make sure that when we loop through the core decaf directories to find hook files that we skip over any hooks files that have already been set by caf. |
|
| 314 | - if ($extend) { |
|
| 315 | - $hook_files_glob_path = apply_filters( |
|
| 316 | - 'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path__extend', |
|
| 317 | - EE_CORE_CAF_ADMIN_EXTEND |
|
| 318 | - . $this->_folder_name |
|
| 319 | - . DS |
|
| 320 | - . '*' |
|
| 321 | - . $this->_file_name |
|
| 322 | - . '_Hooks_Extend.class.php' |
|
| 323 | - ); |
|
| 324 | - $this->_hook_paths = $this->_register_hook_files($hook_files_glob_path, $extend); |
|
| 325 | - } |
|
| 326 | - //loop through decaf folders |
|
| 327 | - $hook_files_glob_path = apply_filters( |
|
| 328 | - 'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path', |
|
| 329 | - $this->_folder_path . '*' . $this->_file_name . '_Hooks.class.php' |
|
| 330 | - ); |
|
| 331 | - $this->_hook_paths = array_merge( |
|
| 332 | - $this->_register_hook_files($hook_files_glob_path), |
|
| 333 | - $this->_hook_paths |
|
| 334 | - ); //making sure any extended hook paths are later in the array than the core hook paths! |
|
| 335 | - return $this->_hook_paths; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - |
|
| 339 | - |
|
| 340 | - protected function _register_hook_files($hook_files_glob_path, $extend = false) |
|
| 341 | - { |
|
| 342 | - $hook_paths = array(); |
|
| 343 | - if ($hook_files = glob($hook_files_glob_path)) { |
|
| 344 | - if (empty($hook_files)) { |
|
| 345 | - return array(); |
|
| 346 | - } |
|
| 347 | - foreach ($hook_files as $file) { |
|
| 348 | - //lets get the linked admin. |
|
| 349 | - $hook_file = $extend ? str_replace(EE_CORE_CAF_ADMIN_EXTEND . $this->_folder_name . DS, '', $file) |
|
| 350 | - : str_replace($this->_folder_path, '', $file); |
|
| 351 | - $replace = $extend |
|
| 352 | - ? '_' . $this->_file_name . '_Hooks_Extend.class.php' |
|
| 353 | - : '_' |
|
| 354 | - . $this->_file_name |
|
| 355 | - . '_Hooks.class.php'; |
|
| 356 | - $rel_admin = str_replace($replace, '', $hook_file); |
|
| 357 | - $rel_admin = strtolower($rel_admin); |
|
| 358 | - $hook_paths[] = $file; |
|
| 359 | - //make sure we haven't already got a hook setup for this page path |
|
| 360 | - if (in_array($rel_admin, $this->_files_hooked)) { |
|
| 361 | - continue; |
|
| 362 | - } |
|
| 363 | - $this->hook_file = $hook_file; |
|
| 364 | - $rel_admin_hook = 'FHEE_do_other_page_hooks_' . $rel_admin; |
|
| 365 | - $filter = add_filter($rel_admin_hook, array($this, 'load_admin_hook')); |
|
| 366 | - $this->_files_hooked[] = $rel_admin; |
|
| 367 | - } |
|
| 368 | - } |
|
| 369 | - return $hook_paths; |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - |
|
| 373 | - |
|
| 374 | - public function load_admin_hook($registered_pages) |
|
| 375 | - { |
|
| 376 | - $this->hook_file; |
|
| 377 | - $hook_file = (array)$this->hook_file; |
|
| 378 | - return array_merge($hook_file, $registered_pages); |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * _initialize_admin_page |
|
| 384 | - * |
|
| 385 | - * @see initialize_admin_page() for info |
|
| 386 | - */ |
|
| 387 | - protected function _initialize_admin_page() |
|
| 388 | - { |
|
| 389 | - |
|
| 390 | - //JUST CHECK WE'RE ON RIGHT PAGE. |
|
| 391 | - if ((! isset($_REQUEST['page']) || $_REQUEST['page'] != $this->_menu_map->menu_slug) && $this->_routing) { |
|
| 392 | - return; |
|
| 393 | - } //not on the right page so let's get out. |
|
| 394 | - $this->_load_page = true; |
|
| 395 | - //let's set page specific autoloaders. Note that this just sets autoloaders for THIS set of admin pages. |
|
| 396 | - // spl_autoload_register(array( $this, 'set_autoloaders') ); |
|
| 397 | - //we don't need to do a page_request check here because it's only called via WP menu system. |
|
| 398 | - $admin_page = $this->_file_name . '_Admin_Page'; |
|
| 399 | - $hook_suffix = $this->_menu_map->menu_slug . '_' . $admin_page; |
|
| 400 | - $admin_page = apply_filters( |
|
| 401 | - "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$hook_suffix}", |
|
| 402 | - $admin_page |
|
| 403 | - ); |
|
| 404 | - // define requested admin page class name then load the file and instantiate |
|
| 405 | - $path_to_file = str_replace(array('\\', '/'), DS, $this->_folder_path . $admin_page . '.core.php'); |
|
| 406 | - $path_to_file = apply_filters( |
|
| 407 | - "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$hook_suffix}", |
|
| 408 | - $path_to_file |
|
| 409 | - );//so if the file would be in EE_ADMIN/attendees/Attendee_Admin_Page.core.php, the filter would be FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__attendees_Attendee_Admin_Page |
|
| 410 | - if (is_readable($path_to_file)) { |
|
| 411 | - // This is a place where EE plugins can hook in to make sure their own files are required in the appropriate place |
|
| 412 | - do_action('AHEE__EE_Admin_Page___initialize_admin_page__before_initialization'); |
|
| 413 | - do_action( |
|
| 414 | - 'AHEE__EE_Admin_Page___initialize_admin_page__before_initialization_' . $this->_menu_map->menu_slug |
|
| 415 | - ); |
|
| 416 | - require_once($path_to_file); |
|
| 417 | - $a = new ReflectionClass($admin_page); |
|
| 418 | - $this->_loaded_page_object = $a->newInstance($this->_routing); |
|
| 419 | - } |
|
| 420 | - do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization'); |
|
| 421 | - do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization_' . $this->_menu_map->menu_slug); |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - |
|
| 425 | - |
|
| 426 | - public function get_admin_page_name() |
|
| 427 | - { |
|
| 428 | - return $this->_file_name . '_Admin_Page'; |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - |
|
| 432 | - |
|
| 433 | - /** |
|
| 434 | - * @return mixed |
|
| 435 | - */ |
|
| 436 | - public function loaded_page_object() |
|
| 437 | - { |
|
| 438 | - return $this->_loaded_page_object; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - |
|
| 442 | - |
|
| 443 | - |
|
| 444 | - |
|
| 445 | - // public function set_autoloaders( $className ) { |
|
| 446 | - // $dir_ref = array( |
|
| 447 | - // $this->_folder_path => array('core','class') |
|
| 448 | - // ); |
|
| 449 | - // EEH_Autoloader::try_autoload($dir_ref, $className ); |
|
| 450 | - // } |
|
| 451 | - /** |
|
| 452 | - * _check_user_access |
|
| 453 | - * verifies user access for this admin page. If no user access is available then let's gracefully exit with a |
|
| 454 | - * WordPress die message. |
|
| 455 | - * |
|
| 456 | - * @return bool|die true if pass (or admin) wp_die if fail |
|
| 457 | - */ |
|
| 458 | - private function _check_user_access() |
|
| 459 | - { |
|
| 460 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
| 461 | - $this->_menu_map->capability, |
|
| 462 | - $this->_menu_map->menu_slug |
|
| 463 | - )) { |
|
| 464 | - wp_die(__('You don\'t have access to this page.'), '', array('back_link' => true)); |
|
| 465 | - } |
|
| 466 | - return true; |
|
| 467 | - } |
|
| 31 | + //identity properties (set in _set_defaults and _set_init_properties) |
|
| 32 | + public $label; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Menu map has a capability. However, this allows admin pages to have separate capability requirements for menus |
|
| 36 | + * and accessing pages. If capability is NOT set, then it defaults to the menu_map capability. |
|
| 37 | + * |
|
| 38 | + * @var string |
|
| 39 | + */ |
|
| 40 | + public $capability; |
|
| 41 | + |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * This holds the menu map object for this admin page. |
|
| 45 | + * |
|
| 46 | + * @var EE_Admin_Page_Menu_Map |
|
| 47 | + */ |
|
| 48 | + protected $_menu_map; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * deprecated |
|
| 52 | + */ |
|
| 53 | + public $menu_label; |
|
| 54 | + public $menu_slug; |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + //set in _set_defaults |
|
| 59 | + protected $_folder_name; |
|
| 60 | + protected $_folder_path; |
|
| 61 | + protected $_file_name; |
|
| 62 | + public $hook_file; |
|
| 63 | + protected $_wp_page_slug; |
|
| 64 | + protected $_routing; |
|
| 65 | + |
|
| 66 | + |
|
| 67 | + //will hold page object. |
|
| 68 | + protected $_loaded_page_object; |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + //for caf |
|
| 72 | + protected $_files_hooked; |
|
| 73 | + protected $_hook_paths; |
|
| 74 | + |
|
| 75 | + //load_page? |
|
| 76 | + private $_load_page; |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @Constructor |
|
| 82 | + * @access public |
|
| 83 | + * @return void |
|
| 84 | + */ |
|
| 85 | + public function __construct() |
|
| 86 | + { |
|
| 87 | + //set global defaults |
|
| 88 | + $this->_set_defaults(); |
|
| 89 | + //set properties that are always available with objects. |
|
| 90 | + $this->_set_init_properties(); |
|
| 91 | + //global styles/scripts across all wp admin pages |
|
| 92 | + add_action('admin_enqueue_scripts', array($this, 'load_wp_global_scripts_styles'), 5); |
|
| 93 | + //load initial stuff. |
|
| 94 | + $this->_set_file_and_folder_name(); |
|
| 95 | + $this->_set_menu_map(); |
|
| 96 | + if (empty($this->_menu_map) || is_array($this->_menu_map)) { |
|
| 97 | + EE_Error::doing_it_wrong( |
|
| 98 | + get_class($this) . '::$_menu_map', |
|
| 99 | + sprintf( |
|
| 100 | + __( |
|
| 101 | + 'The EE4 addon with the class %s is setting up the _menu_map property incorrectly for this version of EE core. Please see Admin_Page_Init class examples in core for the new way of setting this property up.', |
|
| 102 | + 'event_espresso' |
|
| 103 | + ), |
|
| 104 | + get_class($this) |
|
| 105 | + ), |
|
| 106 | + '4.4.0' |
|
| 107 | + ); |
|
| 108 | + return; |
|
| 109 | + } |
|
| 110 | + //set default capability |
|
| 111 | + $this->_set_capability(); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * _set_init_properties |
|
| 118 | + * Child classes use to set the following properties: |
|
| 119 | + * $label |
|
| 120 | + * |
|
| 121 | + * @abstract |
|
| 122 | + * @access protected |
|
| 123 | + * @return void |
|
| 124 | + */ |
|
| 125 | + abstract protected function _set_init_properties(); |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * _set_menu_map is a function that child classes use to set the menu_map property (which should be an instance of |
|
| 131 | + * EE_Admin_Page_Menu_Map. Their menu can either be EE_Admin_Page_Main_Menu or EE_Admin_Page_Sub_Menu. |
|
| 132 | + * |
|
| 133 | + * @since 4.4.0 |
|
| 134 | + * @ return void. |
|
| 135 | + */ |
|
| 136 | + protected function _set_menu_map() |
|
| 137 | + { |
|
| 138 | + return array(); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * returns the menu map for this admin page |
|
| 145 | + * |
|
| 146 | + * @since 4.4.0 |
|
| 147 | + * @return EE_Admin_Page_Menu_Map |
|
| 148 | + */ |
|
| 149 | + public function get_menu_map() |
|
| 150 | + { |
|
| 151 | + return $this->_menu_map; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * This loads scripts and styles for the EE_Admin system |
|
| 158 | + * that must be available on ALL WP admin pages (i.e. EE_menu items) |
|
| 159 | + * |
|
| 160 | + * @return void |
|
| 161 | + */ |
|
| 162 | + public function load_wp_global_scripts_styles() |
|
| 163 | + { |
|
| 164 | + wp_register_style( |
|
| 165 | + 'espresso_menu', |
|
| 166 | + EE_ADMIN_URL . 'assets/admin-menu-styles.css', |
|
| 167 | + array('dashicons'), |
|
| 168 | + EVENT_ESPRESSO_VERSION |
|
| 169 | + ); |
|
| 170 | + wp_enqueue_style('espresso_menu'); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * this sets default properties (might be overridden in _set_init_properties); |
|
| 177 | + * |
|
| 178 | + * @access private |
|
| 179 | + * @return void |
|
| 180 | + */ |
|
| 181 | + private function _set_defaults() |
|
| 182 | + { |
|
| 183 | + $this->_file_name = $this->_folder_name = $this->_wp_page_slug = $this->capability = null; |
|
| 184 | + $this->_routing = true; |
|
| 185 | + $this->_load_page = false; |
|
| 186 | + $this->_files_hooked = $this->_hook_paths = array(); |
|
| 187 | + //menu_map |
|
| 188 | + $this->_menu_map = $this->get_menu_map(); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + |
|
| 192 | + |
|
| 193 | + protected function _set_capability() |
|
| 194 | + { |
|
| 195 | + $capability = empty($this->capability) ? $this->_menu_map->capability : $this->capability; |
|
| 196 | + $this->capability = apply_filters('FHEE_' . $this->_menu_map->menu_slug . '_capability', $capability); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * initialize_admin_page |
|
| 203 | + * This method is what executes the loading of the specific page class for the given dir_name as called by the |
|
| 204 | + * EE_Admin_Init class. |
|
| 205 | + * |
|
| 206 | + * @access public |
|
| 207 | + * @uses _initialize_admin_page() |
|
| 208 | + * @param string $dir_name directory name for specific admin_page being loaded. |
|
| 209 | + * @return void |
|
| 210 | + */ |
|
| 211 | + public function initialize_admin_page() |
|
| 212 | + { |
|
| 213 | + //let's check user access first |
|
| 214 | + $this->_check_user_access(); |
|
| 215 | + if (! is_object($this->_loaded_page_object)) { |
|
| 216 | + return; |
|
| 217 | + } |
|
| 218 | + $this->_loaded_page_object->route_admin_request(); |
|
| 219 | + return; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + |
|
| 223 | + |
|
| 224 | + public function set_page_dependencies($wp_page_slug) |
|
| 225 | + { |
|
| 226 | + if (! $this->_load_page) { |
|
| 227 | + return; |
|
| 228 | + } |
|
| 229 | + if (! is_object($this->_loaded_page_object)) { |
|
| 230 | + $msg[] = __( |
|
| 231 | + 'We can\'t load the page because we\'re missing a valid page object that tells us what to load', |
|
| 232 | + 'event_espresso' |
|
| 233 | + ); |
|
| 234 | + $msg[] = $msg[0] . "\r\n" . sprintf( |
|
| 235 | + __( |
|
| 236 | + 'The custom slug you have set for this page is %s. This means we\'re looking for the class %s_Admin_Page (found in %s_Admin_Page.core.php) within your %s directory', |
|
| 237 | + 'event_espresso' |
|
| 238 | + ), |
|
| 239 | + $this->_file_name, |
|
| 240 | + $this->_file_name, |
|
| 241 | + $this->_folder_path . $this->_file_name, |
|
| 242 | + $this->_menu_map->menu_slug |
|
| 243 | + ); |
|
| 244 | + throw new EE_Error(implode('||', $msg)); |
|
| 245 | + } |
|
| 246 | + $this->_loaded_page_object->set_wp_page_slug($wp_page_slug); |
|
| 247 | + $page_hook = 'load-' . $wp_page_slug; |
|
| 248 | + //hook into page load hook so all page specific stuff get's loaded. |
|
| 249 | + if (! empty($wp_page_slug)) { |
|
| 250 | + add_action($page_hook, array($this->_loaded_page_object, 'load_page_dependencies')); |
|
| 251 | + } |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * This executes the intial page loads for EE_Admin pages to take care of any ajax or other code needing to run |
|
| 257 | + * before the load-page... hook. Note, the page loads are happening around the wp_init hook. |
|
| 258 | + * |
|
| 259 | + * @return void |
|
| 260 | + */ |
|
| 261 | + public function do_initial_loads() |
|
| 262 | + { |
|
| 263 | + //no loading or initializing if menu map is setup incorrectly. |
|
| 264 | + if (empty($this->_menu_map) || is_array($this->_menu_map)) { |
|
| 265 | + return; |
|
| 266 | + } |
|
| 267 | + $this->_initialize_admin_page(); |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * all we're doing here is setting the $_file_name property for later use. |
|
| 273 | + * |
|
| 274 | + * @access private |
|
| 275 | + * @return void |
|
| 276 | + */ |
|
| 277 | + private function _set_file_and_folder_name() |
|
| 278 | + { |
|
| 279 | + $bt = debug_backtrace(); |
|
| 280 | + //for more reliable determination of folder name |
|
| 281 | + //we're using this to get the actual folder name of the CALLING class (i.e. the child class that extends this). Why? Because $this->menu_slug may be different than the folder name (to avoid conflicts with other plugins) |
|
| 282 | + $class = get_class($this); |
|
| 283 | + foreach ($bt as $index => $values) { |
|
| 284 | + if (isset($values['class']) && $values['class'] == $class) { |
|
| 285 | + $file_index = $index - 1; |
|
| 286 | + $this->_folder_name = basename(dirname($bt[$file_index]['file'])); |
|
| 287 | + if (! empty($this->_folder_name)) { |
|
| 288 | + break; |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + } |
|
| 292 | + $this->_folder_path = EE_ADMIN_PAGES . $this->_folder_name . DS; |
|
| 293 | + $this->_file_name = preg_replace('/^ee/', 'EE', $this->_folder_name); |
|
| 294 | + $this->_file_name = ucwords(str_replace('_', ' ', $this->_file_name)); |
|
| 295 | + $this->_file_name = str_replace(' ', '_', $this->_file_name); |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + |
|
| 299 | + /** |
|
| 300 | + * This automatically checks if we have a hook class in the loaded child directory. If we DO then we will register |
|
| 301 | + * it with the appropriate pages. That way all we have to do is make sure the file is named correctly and |
|
| 302 | + * "dropped" in. Example: if we wanted to set this up for Messages hooking into Events then we would do: |
|
| 303 | + * events_Messages_Hooks.class.php |
|
| 304 | + * |
|
| 305 | + * @param bool $extend This indicates whether we're checking the extend directory for any register_hooks |
|
| 306 | + * files/classes |
|
| 307 | + * @return array |
|
| 308 | + */ |
|
| 309 | + public function register_hooks($extend = false) |
|
| 310 | + { |
|
| 311 | + |
|
| 312 | + //get a list of files in the directory that have the "Hook" in their name an |
|
| 313 | + //if this is an extended check (i.e. caf is active) then we will scan the caffeinated/extend directory first and any hook files that are found will be have their reference added to the $_files_hook array property. Then, we make sure that when we loop through the core decaf directories to find hook files that we skip over any hooks files that have already been set by caf. |
|
| 314 | + if ($extend) { |
|
| 315 | + $hook_files_glob_path = apply_filters( |
|
| 316 | + 'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path__extend', |
|
| 317 | + EE_CORE_CAF_ADMIN_EXTEND |
|
| 318 | + . $this->_folder_name |
|
| 319 | + . DS |
|
| 320 | + . '*' |
|
| 321 | + . $this->_file_name |
|
| 322 | + . '_Hooks_Extend.class.php' |
|
| 323 | + ); |
|
| 324 | + $this->_hook_paths = $this->_register_hook_files($hook_files_glob_path, $extend); |
|
| 325 | + } |
|
| 326 | + //loop through decaf folders |
|
| 327 | + $hook_files_glob_path = apply_filters( |
|
| 328 | + 'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path', |
|
| 329 | + $this->_folder_path . '*' . $this->_file_name . '_Hooks.class.php' |
|
| 330 | + ); |
|
| 331 | + $this->_hook_paths = array_merge( |
|
| 332 | + $this->_register_hook_files($hook_files_glob_path), |
|
| 333 | + $this->_hook_paths |
|
| 334 | + ); //making sure any extended hook paths are later in the array than the core hook paths! |
|
| 335 | + return $this->_hook_paths; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + |
|
| 339 | + |
|
| 340 | + protected function _register_hook_files($hook_files_glob_path, $extend = false) |
|
| 341 | + { |
|
| 342 | + $hook_paths = array(); |
|
| 343 | + if ($hook_files = glob($hook_files_glob_path)) { |
|
| 344 | + if (empty($hook_files)) { |
|
| 345 | + return array(); |
|
| 346 | + } |
|
| 347 | + foreach ($hook_files as $file) { |
|
| 348 | + //lets get the linked admin. |
|
| 349 | + $hook_file = $extend ? str_replace(EE_CORE_CAF_ADMIN_EXTEND . $this->_folder_name . DS, '', $file) |
|
| 350 | + : str_replace($this->_folder_path, '', $file); |
|
| 351 | + $replace = $extend |
|
| 352 | + ? '_' . $this->_file_name . '_Hooks_Extend.class.php' |
|
| 353 | + : '_' |
|
| 354 | + . $this->_file_name |
|
| 355 | + . '_Hooks.class.php'; |
|
| 356 | + $rel_admin = str_replace($replace, '', $hook_file); |
|
| 357 | + $rel_admin = strtolower($rel_admin); |
|
| 358 | + $hook_paths[] = $file; |
|
| 359 | + //make sure we haven't already got a hook setup for this page path |
|
| 360 | + if (in_array($rel_admin, $this->_files_hooked)) { |
|
| 361 | + continue; |
|
| 362 | + } |
|
| 363 | + $this->hook_file = $hook_file; |
|
| 364 | + $rel_admin_hook = 'FHEE_do_other_page_hooks_' . $rel_admin; |
|
| 365 | + $filter = add_filter($rel_admin_hook, array($this, 'load_admin_hook')); |
|
| 366 | + $this->_files_hooked[] = $rel_admin; |
|
| 367 | + } |
|
| 368 | + } |
|
| 369 | + return $hook_paths; |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + |
|
| 373 | + |
|
| 374 | + public function load_admin_hook($registered_pages) |
|
| 375 | + { |
|
| 376 | + $this->hook_file; |
|
| 377 | + $hook_file = (array)$this->hook_file; |
|
| 378 | + return array_merge($hook_file, $registered_pages); |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * _initialize_admin_page |
|
| 384 | + * |
|
| 385 | + * @see initialize_admin_page() for info |
|
| 386 | + */ |
|
| 387 | + protected function _initialize_admin_page() |
|
| 388 | + { |
|
| 389 | + |
|
| 390 | + //JUST CHECK WE'RE ON RIGHT PAGE. |
|
| 391 | + if ((! isset($_REQUEST['page']) || $_REQUEST['page'] != $this->_menu_map->menu_slug) && $this->_routing) { |
|
| 392 | + return; |
|
| 393 | + } //not on the right page so let's get out. |
|
| 394 | + $this->_load_page = true; |
|
| 395 | + //let's set page specific autoloaders. Note that this just sets autoloaders for THIS set of admin pages. |
|
| 396 | + // spl_autoload_register(array( $this, 'set_autoloaders') ); |
|
| 397 | + //we don't need to do a page_request check here because it's only called via WP menu system. |
|
| 398 | + $admin_page = $this->_file_name . '_Admin_Page'; |
|
| 399 | + $hook_suffix = $this->_menu_map->menu_slug . '_' . $admin_page; |
|
| 400 | + $admin_page = apply_filters( |
|
| 401 | + "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$hook_suffix}", |
|
| 402 | + $admin_page |
|
| 403 | + ); |
|
| 404 | + // define requested admin page class name then load the file and instantiate |
|
| 405 | + $path_to_file = str_replace(array('\\', '/'), DS, $this->_folder_path . $admin_page . '.core.php'); |
|
| 406 | + $path_to_file = apply_filters( |
|
| 407 | + "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$hook_suffix}", |
|
| 408 | + $path_to_file |
|
| 409 | + );//so if the file would be in EE_ADMIN/attendees/Attendee_Admin_Page.core.php, the filter would be FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__attendees_Attendee_Admin_Page |
|
| 410 | + if (is_readable($path_to_file)) { |
|
| 411 | + // This is a place where EE plugins can hook in to make sure their own files are required in the appropriate place |
|
| 412 | + do_action('AHEE__EE_Admin_Page___initialize_admin_page__before_initialization'); |
|
| 413 | + do_action( |
|
| 414 | + 'AHEE__EE_Admin_Page___initialize_admin_page__before_initialization_' . $this->_menu_map->menu_slug |
|
| 415 | + ); |
|
| 416 | + require_once($path_to_file); |
|
| 417 | + $a = new ReflectionClass($admin_page); |
|
| 418 | + $this->_loaded_page_object = $a->newInstance($this->_routing); |
|
| 419 | + } |
|
| 420 | + do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization'); |
|
| 421 | + do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization_' . $this->_menu_map->menu_slug); |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + |
|
| 425 | + |
|
| 426 | + public function get_admin_page_name() |
|
| 427 | + { |
|
| 428 | + return $this->_file_name . '_Admin_Page'; |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + |
|
| 432 | + |
|
| 433 | + /** |
|
| 434 | + * @return mixed |
|
| 435 | + */ |
|
| 436 | + public function loaded_page_object() |
|
| 437 | + { |
|
| 438 | + return $this->_loaded_page_object; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + |
|
| 442 | + |
|
| 443 | + |
|
| 444 | + |
|
| 445 | + // public function set_autoloaders( $className ) { |
|
| 446 | + // $dir_ref = array( |
|
| 447 | + // $this->_folder_path => array('core','class') |
|
| 448 | + // ); |
|
| 449 | + // EEH_Autoloader::try_autoload($dir_ref, $className ); |
|
| 450 | + // } |
|
| 451 | + /** |
|
| 452 | + * _check_user_access |
|
| 453 | + * verifies user access for this admin page. If no user access is available then let's gracefully exit with a |
|
| 454 | + * WordPress die message. |
|
| 455 | + * |
|
| 456 | + * @return bool|die true if pass (or admin) wp_die if fail |
|
| 457 | + */ |
|
| 458 | + private function _check_user_access() |
|
| 459 | + { |
|
| 460 | + if (! EE_Registry::instance()->CAP->current_user_can( |
|
| 461 | + $this->_menu_map->capability, |
|
| 462 | + $this->_menu_map->menu_slug |
|
| 463 | + )) { |
|
| 464 | + wp_die(__('You don\'t have access to this page.'), '', array('back_link' => true)); |
|
| 465 | + } |
|
| 466 | + return true; |
|
| 467 | + } |
|
| 468 | 468 | |
| 469 | 469 | } |
| 470 | 470 | // end of file: includes/core/admin/EE_Admin_Page_Init.core.php |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | 2 | exit('No direct script access allowed'); |
| 3 | 3 | } |
| 4 | 4 | /** |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | $this->_set_menu_map(); |
| 96 | 96 | if (empty($this->_menu_map) || is_array($this->_menu_map)) { |
| 97 | 97 | EE_Error::doing_it_wrong( |
| 98 | - get_class($this) . '::$_menu_map', |
|
| 98 | + get_class($this).'::$_menu_map', |
|
| 99 | 99 | sprintf( |
| 100 | 100 | __( |
| 101 | 101 | 'The EE4 addon with the class %s is setting up the _menu_map property incorrectly for this version of EE core. Please see Admin_Page_Init class examples in core for the new way of setting this property up.', |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | { |
| 164 | 164 | wp_register_style( |
| 165 | 165 | 'espresso_menu', |
| 166 | - EE_ADMIN_URL . 'assets/admin-menu-styles.css', |
|
| 166 | + EE_ADMIN_URL.'assets/admin-menu-styles.css', |
|
| 167 | 167 | array('dashicons'), |
| 168 | 168 | EVENT_ESPRESSO_VERSION |
| 169 | 169 | ); |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | protected function _set_capability() |
| 194 | 194 | { |
| 195 | 195 | $capability = empty($this->capability) ? $this->_menu_map->capability : $this->capability; |
| 196 | - $this->capability = apply_filters('FHEE_' . $this->_menu_map->menu_slug . '_capability', $capability); |
|
| 196 | + $this->capability = apply_filters('FHEE_'.$this->_menu_map->menu_slug.'_capability', $capability); |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | { |
| 213 | 213 | //let's check user access first |
| 214 | 214 | $this->_check_user_access(); |
| 215 | - if (! is_object($this->_loaded_page_object)) { |
|
| 215 | + if ( ! is_object($this->_loaded_page_object)) { |
|
| 216 | 216 | return; |
| 217 | 217 | } |
| 218 | 218 | $this->_loaded_page_object->route_admin_request(); |
@@ -223,30 +223,30 @@ discard block |
||
| 223 | 223 | |
| 224 | 224 | public function set_page_dependencies($wp_page_slug) |
| 225 | 225 | { |
| 226 | - if (! $this->_load_page) { |
|
| 226 | + if ( ! $this->_load_page) { |
|
| 227 | 227 | return; |
| 228 | 228 | } |
| 229 | - if (! is_object($this->_loaded_page_object)) { |
|
| 229 | + if ( ! is_object($this->_loaded_page_object)) { |
|
| 230 | 230 | $msg[] = __( |
| 231 | 231 | 'We can\'t load the page because we\'re missing a valid page object that tells us what to load', |
| 232 | 232 | 'event_espresso' |
| 233 | 233 | ); |
| 234 | - $msg[] = $msg[0] . "\r\n" . sprintf( |
|
| 234 | + $msg[] = $msg[0]."\r\n".sprintf( |
|
| 235 | 235 | __( |
| 236 | 236 | 'The custom slug you have set for this page is %s. This means we\'re looking for the class %s_Admin_Page (found in %s_Admin_Page.core.php) within your %s directory', |
| 237 | 237 | 'event_espresso' |
| 238 | 238 | ), |
| 239 | 239 | $this->_file_name, |
| 240 | 240 | $this->_file_name, |
| 241 | - $this->_folder_path . $this->_file_name, |
|
| 241 | + $this->_folder_path.$this->_file_name, |
|
| 242 | 242 | $this->_menu_map->menu_slug |
| 243 | 243 | ); |
| 244 | 244 | throw new EE_Error(implode('||', $msg)); |
| 245 | 245 | } |
| 246 | 246 | $this->_loaded_page_object->set_wp_page_slug($wp_page_slug); |
| 247 | - $page_hook = 'load-' . $wp_page_slug; |
|
| 247 | + $page_hook = 'load-'.$wp_page_slug; |
|
| 248 | 248 | //hook into page load hook so all page specific stuff get's loaded. |
| 249 | - if (! empty($wp_page_slug)) { |
|
| 249 | + if ( ! empty($wp_page_slug)) { |
|
| 250 | 250 | add_action($page_hook, array($this->_loaded_page_object, 'load_page_dependencies')); |
| 251 | 251 | } |
| 252 | 252 | } |
@@ -284,12 +284,12 @@ discard block |
||
| 284 | 284 | if (isset($values['class']) && $values['class'] == $class) { |
| 285 | 285 | $file_index = $index - 1; |
| 286 | 286 | $this->_folder_name = basename(dirname($bt[$file_index]['file'])); |
| 287 | - if (! empty($this->_folder_name)) { |
|
| 287 | + if ( ! empty($this->_folder_name)) { |
|
| 288 | 288 | break; |
| 289 | 289 | } |
| 290 | 290 | } |
| 291 | 291 | } |
| 292 | - $this->_folder_path = EE_ADMIN_PAGES . $this->_folder_name . DS; |
|
| 292 | + $this->_folder_path = EE_ADMIN_PAGES.$this->_folder_name.DS; |
|
| 293 | 293 | $this->_file_name = preg_replace('/^ee/', 'EE', $this->_folder_name); |
| 294 | 294 | $this->_file_name = ucwords(str_replace('_', ' ', $this->_file_name)); |
| 295 | 295 | $this->_file_name = str_replace(' ', '_', $this->_file_name); |
@@ -321,17 +321,17 @@ discard block |
||
| 321 | 321 | . $this->_file_name |
| 322 | 322 | . '_Hooks_Extend.class.php' |
| 323 | 323 | ); |
| 324 | - $this->_hook_paths = $this->_register_hook_files($hook_files_glob_path, $extend); |
|
| 324 | + $this->_hook_paths = $this->_register_hook_files($hook_files_glob_path, $extend); |
|
| 325 | 325 | } |
| 326 | 326 | //loop through decaf folders |
| 327 | 327 | $hook_files_glob_path = apply_filters( |
| 328 | 328 | 'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path', |
| 329 | - $this->_folder_path . '*' . $this->_file_name . '_Hooks.class.php' |
|
| 329 | + $this->_folder_path.'*'.$this->_file_name.'_Hooks.class.php' |
|
| 330 | 330 | ); |
| 331 | - $this->_hook_paths = array_merge( |
|
| 331 | + $this->_hook_paths = array_merge( |
|
| 332 | 332 | $this->_register_hook_files($hook_files_glob_path), |
| 333 | 333 | $this->_hook_paths |
| 334 | - ); //making sure any extended hook paths are later in the array than the core hook paths! |
|
| 334 | + ); //making sure any extended hook paths are later in the array than the core hook paths! |
|
| 335 | 335 | return $this->_hook_paths; |
| 336 | 336 | } |
| 337 | 337 | |
@@ -346,10 +346,10 @@ discard block |
||
| 346 | 346 | } |
| 347 | 347 | foreach ($hook_files as $file) { |
| 348 | 348 | //lets get the linked admin. |
| 349 | - $hook_file = $extend ? str_replace(EE_CORE_CAF_ADMIN_EXTEND . $this->_folder_name . DS, '', $file) |
|
| 349 | + $hook_file = $extend ? str_replace(EE_CORE_CAF_ADMIN_EXTEND.$this->_folder_name.DS, '', $file) |
|
| 350 | 350 | : str_replace($this->_folder_path, '', $file); |
| 351 | 351 | $replace = $extend |
| 352 | - ? '_' . $this->_file_name . '_Hooks_Extend.class.php' |
|
| 352 | + ? '_'.$this->_file_name.'_Hooks_Extend.class.php' |
|
| 353 | 353 | : '_' |
| 354 | 354 | . $this->_file_name |
| 355 | 355 | . '_Hooks.class.php'; |
@@ -361,7 +361,7 @@ discard block |
||
| 361 | 361 | continue; |
| 362 | 362 | } |
| 363 | 363 | $this->hook_file = $hook_file; |
| 364 | - $rel_admin_hook = 'FHEE_do_other_page_hooks_' . $rel_admin; |
|
| 364 | + $rel_admin_hook = 'FHEE_do_other_page_hooks_'.$rel_admin; |
|
| 365 | 365 | $filter = add_filter($rel_admin_hook, array($this, 'load_admin_hook')); |
| 366 | 366 | $this->_files_hooked[] = $rel_admin; |
| 367 | 367 | } |
@@ -374,7 +374,7 @@ discard block |
||
| 374 | 374 | public function load_admin_hook($registered_pages) |
| 375 | 375 | { |
| 376 | 376 | $this->hook_file; |
| 377 | - $hook_file = (array)$this->hook_file; |
|
| 377 | + $hook_file = (array) $this->hook_file; |
|
| 378 | 378 | return array_merge($hook_file, $registered_pages); |
| 379 | 379 | } |
| 380 | 380 | |
@@ -388,44 +388,44 @@ discard block |
||
| 388 | 388 | { |
| 389 | 389 | |
| 390 | 390 | //JUST CHECK WE'RE ON RIGHT PAGE. |
| 391 | - if ((! isset($_REQUEST['page']) || $_REQUEST['page'] != $this->_menu_map->menu_slug) && $this->_routing) { |
|
| 391 | + if (( ! isset($_REQUEST['page']) || $_REQUEST['page'] != $this->_menu_map->menu_slug) && $this->_routing) { |
|
| 392 | 392 | return; |
| 393 | 393 | } //not on the right page so let's get out. |
| 394 | 394 | $this->_load_page = true; |
| 395 | 395 | //let's set page specific autoloaders. Note that this just sets autoloaders for THIS set of admin pages. |
| 396 | 396 | // spl_autoload_register(array( $this, 'set_autoloaders') ); |
| 397 | 397 | //we don't need to do a page_request check here because it's only called via WP menu system. |
| 398 | - $admin_page = $this->_file_name . '_Admin_Page'; |
|
| 399 | - $hook_suffix = $this->_menu_map->menu_slug . '_' . $admin_page; |
|
| 398 | + $admin_page = $this->_file_name.'_Admin_Page'; |
|
| 399 | + $hook_suffix = $this->_menu_map->menu_slug.'_'.$admin_page; |
|
| 400 | 400 | $admin_page = apply_filters( |
| 401 | 401 | "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$hook_suffix}", |
| 402 | 402 | $admin_page |
| 403 | 403 | ); |
| 404 | 404 | // define requested admin page class name then load the file and instantiate |
| 405 | - $path_to_file = str_replace(array('\\', '/'), DS, $this->_folder_path . $admin_page . '.core.php'); |
|
| 405 | + $path_to_file = str_replace(array('\\', '/'), DS, $this->_folder_path.$admin_page.'.core.php'); |
|
| 406 | 406 | $path_to_file = apply_filters( |
| 407 | 407 | "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$hook_suffix}", |
| 408 | 408 | $path_to_file |
| 409 | - );//so if the file would be in EE_ADMIN/attendees/Attendee_Admin_Page.core.php, the filter would be FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__attendees_Attendee_Admin_Page |
|
| 409 | + ); //so if the file would be in EE_ADMIN/attendees/Attendee_Admin_Page.core.php, the filter would be FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__attendees_Attendee_Admin_Page |
|
| 410 | 410 | if (is_readable($path_to_file)) { |
| 411 | 411 | // This is a place where EE plugins can hook in to make sure their own files are required in the appropriate place |
| 412 | 412 | do_action('AHEE__EE_Admin_Page___initialize_admin_page__before_initialization'); |
| 413 | 413 | do_action( |
| 414 | - 'AHEE__EE_Admin_Page___initialize_admin_page__before_initialization_' . $this->_menu_map->menu_slug |
|
| 414 | + 'AHEE__EE_Admin_Page___initialize_admin_page__before_initialization_'.$this->_menu_map->menu_slug |
|
| 415 | 415 | ); |
| 416 | 416 | require_once($path_to_file); |
| 417 | 417 | $a = new ReflectionClass($admin_page); |
| 418 | 418 | $this->_loaded_page_object = $a->newInstance($this->_routing); |
| 419 | 419 | } |
| 420 | 420 | do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization'); |
| 421 | - do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization_' . $this->_menu_map->menu_slug); |
|
| 421 | + do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization_'.$this->_menu_map->menu_slug); |
|
| 422 | 422 | } |
| 423 | 423 | |
| 424 | 424 | |
| 425 | 425 | |
| 426 | 426 | public function get_admin_page_name() |
| 427 | 427 | { |
| 428 | - return $this->_file_name . '_Admin_Page'; |
|
| 428 | + return $this->_file_name.'_Admin_Page'; |
|
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | |
@@ -457,7 +457,7 @@ discard block |
||
| 457 | 457 | */ |
| 458 | 458 | private function _check_user_access() |
| 459 | 459 | { |
| 460 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
| 460 | + if ( ! EE_Registry::instance()->CAP->current_user_can( |
|
| 461 | 461 | $this->_menu_map->capability, |
| 462 | 462 | $this->_menu_map->menu_slug |
| 463 | 463 | )) { |