diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 72f3bcd..41c3a25 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -53,7 +53,7 @@ jobs: strategy: matrix: operating-system: [ubuntu-latest] - php-versions: ["5.6", "7.0", "7.1", "7.2", "7.3", "7.4", "8.0", "8.1"] + php-versions: ["7.1", "7.2", "7.3", "7.4", "8.0", "8.1"] name: Unit Tests with PHP ${{ matrix.php-versions }} steps: - name: Checkout diff --git a/EED_Promotions.module.php b/EED_Promotions.module.php index f8536d8..3901a41 100644 --- a/EED_Promotions.module.php +++ b/EED_Promotions.module.php @@ -3,6 +3,8 @@ use \EventEspresso\core\services\loaders\LoaderFactory; use \EventEspresso\core\exceptions\InvalidDataTypeException; use \EventEspresso\core\exceptions\InvalidInterfaceException; +use EventEspresso\core\services\payment_methods\gateways\GatewayDataFormatter; +use EventEspresso\core\services\request\DataType; /** * Class EED_Promotions @@ -10,163 +12,159 @@ * @package Event Espresso * @subpackage espresso-promotions * @author Brent Christensen - * ------------------------------------------------------------------------ */ class EED_Promotions extends EED_Module { /** - * @var bool - * @access public + * @var bool */ public static $shortcode_active = false; - /** * @return EED_Promotions + * @throws EE_Error + * @throws ReflectionException */ - public static function instance() + public static function instance(): EED_Promotions { return parent::get_instance(__CLASS__); } - /** - * set_hooks - for hooking into EE Core, other modules, etc + * set_hooks - for hooking into EE Core, other modules, etc * - * @access public - * @return void + * @return void */ public static function set_hooks() { EE_Config::register_route('promotions', 'EED_Promotions', 'run'); - add_action('wp_enqueue_scripts', array( 'EED_Promotions', 'translate_js_strings' ), 1); - add_action('wp_enqueue_scripts', array( 'EED_Promotions', 'enqueue_scripts' )); + add_action('wp_enqueue_scripts', ['EED_Promotions', 'translate_js_strings'], 1); + add_action('wp_enqueue_scripts', ['EED_Promotions', 'enqueue_scripts']); add_action( 'AHEE__ticket_selector_chart__template__before_ticket_selector', - array( 'EED_Promotions', 'display_event_promotions_banner' ), + ['EED_Promotions', 'display_event_promotions_banner'], 10, 1 ); add_action( 'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout', - array( 'EED_Promotions', 'auto_process_promotions_in_cart' ), + ['EED_Promotions', 'auto_process_promotions_in_cart'], 10, 1 ); add_filter( 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__before_payment_options', - array( 'EED_Promotions', 'add_promotions_form_inputs' ) + ['EED_Promotions', 'add_promotions_form_inputs'] ); // adjust SPCO add_filter( 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', - array( 'EED_Promotions', 'adjust_SPCO_line_item_display' ), + ['EED_Promotions', 'adjust_SPCO_line_item_display'], 10, 2 ); } - /** - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc * - * @access public * @return void */ public static function set_hooks_admin() { add_filter( 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__before_payment_options', - array( 'EED_Promotions', 'add_promotions_form_inputs' ) + ['EED_Promotions', 'add_promotions_form_inputs'] ); add_action( 'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout', - array( 'EED_Promotions', 'auto_process_promotions_in_cart' ), + ['EED_Promotions', 'auto_process_promotions_in_cart'], 10, 1 ); // Enqueue scripts at Transactions page. - add_action('admin_enqueue_scripts', array( 'EED_Promotions', 'enqueueAdminScripts' )); + add_action('admin_enqueue_scripts', ['EED_Promotions', 'enqueueAdminScripts']); // _get_promotions - add_action('wp_ajax_espresso_get_promotions', array( 'EED_Promotions', '_get_promotions' )); - add_action('wp_ajax_nopriv_espresso_get_promotions', array( 'EED_Promotions', '_get_promotions' )); + add_action('wp_ajax_espresso_get_promotions', ['EED_Promotions', '_get_promotions']); + add_action('wp_ajax_nopriv_espresso_get_promotions', ['EED_Promotions', '_get_promotions']); // submit_promo_code - add_action('wp_ajax_espresso_submit_promo_code', array( 'EED_Promotions', 'submit_promo_code' )); - add_action('wp_ajax_nopriv_espresso_submit_promo_code', array( 'EED_Promotions', 'submit_promo_code' )); + add_action('wp_ajax_espresso_submit_promo_code', ['EED_Promotions', 'submit_promo_code']); + add_action('wp_ajax_nopriv_espresso_submit_promo_code', ['EED_Promotions', 'submit_promo_code']); // submit_txn_promo_code - add_action('wp_ajax_espresso_submit_txn_promo_code', array( 'EED_Promotions', 'submitTxnPromoCode' )); - add_action('wp_ajax_nopriv_espresso_submit_txn_promo_code', array( 'EED_Promotions', 'submitTxnPromoCode' )); + add_action('wp_ajax_espresso_submit_txn_promo_code', ['EED_Promotions', 'submitTxnPromoCode']); + add_action('wp_ajax_nopriv_espresso_submit_txn_promo_code', ['EED_Promotions', 'submitTxnPromoCode']); // adjust SPCO add_filter( 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', - array( 'EED_Promotions', 'adjust_SPCO_line_item_display' ), + ['EED_Promotions', 'adjust_SPCO_line_item_display'], 10, 2 ); add_filter( 'FHEE__EE_gateway___line_item_name', - array( 'EED_Promotions', 'adjust_promotion_line_item_gateway' ), + ['EED_Promotions', 'adjust_promotion_line_item_gateway'], 10, 4 ); // TXN admin add_filter( 'FHEE__EE_Admin_Transactions_List_Table__column_TXN_total__TXN_total', - array( 'EED_Promotions', 'transactions_list_table_total' ), + ['EED_Promotions', 'transactions_list_table_total'], 10, 2 ); add_filter( 'FHEE__Transactions_Admin_Page___transaction_legend_items__items', - array( 'EED_Promotions', 'transactions_list_table_legend' ), + ['EED_Promotions', 'transactions_list_table_legend'], 10, 2 ); // the filter got renamed and the old one was deprecated. - if (version_compare( - espresso_version(), - '4.9.69.p', - '>' - )) { + if ( + version_compare( + espresso_version(), + '4.9.69.p', + '>' + ) + ) { $filter_name = 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array'; } else { $filter_name = 'FHEE__EE_Export__report_registrations__reg_csv_array'; } add_filter( $filter_name, - array( 'EED_Promotions', 'add_promotions_column_to_reg_csv_report' ), + ['EED_Promotions', 'add_promotions_column_to_reg_csv_report'], 10, 2 ); // when events are deleted add_action( 'AHEE__EE_Base_Class__delete_permanently__end', - array( 'EED_Promotions', 'delete_related_promotion_on_scope_item_delete' ), + ['EED_Promotions', 'delete_related_promotion_on_scope_item_delete'], 10, 2 ); // Display button at transactions actions area. add_action( 'AHEE__txn_admin_details_main_meta_box_txn_details__after_actions_buttons', - array( 'EED_Promotions', 'displayApplyDiscountAtTransactions' ), + ['EED_Promotions', 'displayApplyDiscountAtTransactions'], 10, 1 ); } - /** * set_config * this configures this module to use the same config as the EE_Promotions class * * @return EE_Promotions_Config */ - public function set_config() + public function set_config(): EE_Promotions_Config { $this->set_config_section('addons'); $this->set_config_class('EE_Promotions_Config'); @@ -175,11 +173,10 @@ public function set_config() } - /** * @return EE_Promotions_Config */ - public function config() + public function config(): EE_Promotions_Config { if (! $this->_config instanceof EE_Promotions_Config) { return $this->set_config(); @@ -188,13 +185,13 @@ public function config() } - /** * run - initial module setup * - * @access public - * @param WP $WP + * @param WP $WP * @return void + * @throws EE_Error + * @throws ReflectionException */ public function run($WP) { @@ -202,11 +199,9 @@ public function run($WP) } - /** * translate_js_strings * - * @access public * @return void */ public static function translate_js_strings() @@ -218,11 +213,9 @@ public static function translate_js_strings() } - /** * enqueue_scripts - Load the scripts and css * - * @access public * @return void */ public static function enqueueAdminScripts() @@ -231,7 +224,7 @@ public static function enqueueAdminScripts() wp_register_script( 'eventespresso-txn-promotions-admin', EE_PROMOTIONS_URL . 'scripts' . DS . 'txn-promotions.admin.js', - array(), + [], EE_PROMOTIONS_VERSION, true ); @@ -243,11 +236,9 @@ public static function enqueueAdminScripts() } - /** * enqueue_scripts - Load the scripts and css * - * @access public * @return void */ public static function enqueue_scripts() @@ -266,7 +257,7 @@ public static function enqueue_scripts() wp_register_script( 'espresso_promotions', EE_PROMOTIONS_URL . 'scripts' . DS . 'promotions.js', - array( 'single_page_checkout' ), + ['single_page_checkout'], EE_PROMOTIONS_VERSION, true ); @@ -279,7 +270,6 @@ public static function enqueue_scripts() } - /** * @return bool * @throws InvalidArgumentException @@ -287,7 +277,7 @@ public static function enqueue_scripts() * @throws InvalidInterfaceException * @since 1.0.15.p */ - public static function loadAdminAssets() + public static function loadAdminAssets(): bool { if (is_admin()) { /** @var EventEspresso\core\services\request\RequestInterface $request */ @@ -295,20 +285,18 @@ public static function loadAdminAssets() 'EventEspresso\core\services\request\RequestInterface' ); return $request->getRequestParam('page') === 'espresso_transactions' - && $request->getRequestParam('TXN_ID') !== null; + && $request->getRequestParam('TXN_ID', 0, DataType::INT) !== 0; } return false; } - /** * load_assets * - * @access public * @return bool */ - public static function load_assets() + public static function load_assets(): bool { return ! is_admin() @@ -326,19 +314,19 @@ public static function load_assets() /** * transactions_list_table_total * - * @access public - * @param string $TXN_total - * @param EE_Transaction $transaction + * @param string $TXN_total + * @param EE_Transaction $transaction * @return string - * @throws \EE_Error + * @throws EE_Error + * @throws ReflectionException */ - public static function transactions_list_table_total($TXN_total = '', EE_Transaction $transaction) + public static function transactions_list_table_total(string $TXN_total, EE_Transaction $transaction): string { - $promotion_line_items = $transaction->line_items(array( array( 'OBJ_type' => 'Promotion' ) )); - $promotion_line_item = reset($promotion_line_items); + $promotion_line_items = $transaction->line_items([['OBJ_type' => 'Promotion']]); + $promotion_line_item = reset($promotion_line_items); if ($promotion_line_item instanceof EE_Line_Item) { $edit_link = EEH_URL::add_query_args_and_nonce( - array( 'action' => 'edit', 'PRO_ID' => $promotion_line_item->OBJ_ID() ), + ['action' => 'edit', 'PRO_ID' => $promotion_line_item->OBJ_ID()], EE_PROMOTIONS_ADMIN_URL ); $TXN_total = 'get_field_id('title'); ?>"> - +

get_field_id('yes_or_no_question'); ?> - + array( - __('upcoming', 'event_espresso'), - __('upcoming', 'event_espresso'), + esc_html__('upcoming', 'event_espresso'), + esc_html__('upcoming', 'event_espresso'), ), EE_Promotion::active => array( - __('active', 'event_espresso'), - __('active', 'event_espresso'), + esc_html__('active', 'event_espresso'), + esc_html__('active', 'event_espresso'), ), EE_Promotion::expired => array( - __('expired', 'event_espresso'), - __('expired', 'event_espresso'), + esc_html__('expired', 'event_espresso'), + esc_html__('expired', 'event_espresso'), ), EE_Promotion::unavailable => array( - __('unavailable', 'event_espresso'), - __('unavailable', 'event_espresso'), + esc_html__('unavailable', 'event_espresso'), + esc_html__('unavailable', 'event_espresso'), ), ); return array_merge($stati_translation, $promotion_stati); diff --git a/EE_Promotions_Config.php b/EE_Promotions_Config.php index 61df50a..b40ac1e 100644 --- a/EE_Promotions_Config.php +++ b/EE_Promotions_Config.php @@ -46,14 +46,9 @@ class EE_Promotions_Config extends EE_Config_Base protected $_affects_tax = false; - /** - * constructor - * - * @return EE_Promotions_Config - */ public function __construct() { - add_action('AHEE__EE_Config___load_core_config__end', array($this, 'init')); + add_action('AHEE__EE_Config___load_core_config__end', array($this, 'init'), 99); } @@ -68,15 +63,16 @@ public function init() if ($initialized) { return; } + $initialized = true; $this->scopes = $this->_get_scopes(); $this->label = new stdClass(); $this->label->singular = apply_filters( 'FHEE__EE_Promotions_Config____construct__label_singular', - __('Promotion Code', 'event_espresso') + esc_html__('Promotion Code', 'event_espresso') ); $this->label->plural = apply_filters( 'FHEE__EE_Promotions_Config____construct__label_plural', - __('Promotion Codes', 'event_espresso') + esc_html__('Promotion Codes', 'event_espresso') ); } diff --git a/admin/promotions/PromotionsDatepicker.php b/admin/promotions/PromotionsDatepicker.php new file mode 100644 index 0000000..f69418e --- /dev/null +++ b/admin/promotions/PromotionsDatepicker.php @@ -0,0 +1,102 @@ +date_string = $date_string; + $this->context = $context; + $this->container = $container; + $this->id = $id; + $this->trigger_label = $trigger_label; + $this->reset_label = esc_html__('reset date input', 'event_espresso'); + } + + + public function getHtml(): string + { + return " +
+
+ + +
+ +
"; + } +} \ No newline at end of file diff --git a/admin/promotions/Promotions_Admin_List_Table.class.php b/admin/promotions/Promotions_Admin_List_Table.class.php index 65b3ceb..d87849e 100644 --- a/admin/promotions/Promotions_Admin_List_Table.class.php +++ b/admin/promotions/Promotions_Admin_List_Table.class.php @@ -26,24 +26,24 @@ protected function _setup_data() protected function _set_properties() { $this->_wp_list_args = array( - 'singular' => __('Promotion', 'event_espresso'), - 'plural' => __('Promotion', 'event_espresso'), + 'singular' => esc_html__('Promotion', 'event_espresso'), + 'plural' => esc_html__('Promotion', 'event_espresso'), 'ajax' => true, 'screen' => $this->_admin_page->get_current_screen()->id ); $this->_columns = array( 'cb' => '', - 'id' => __('ID', 'event_espresso'), - 'name' => __('Name', 'event_espresso'), - 'code' => __('Code', 'event_espresso'), - 'applies_to' => __('Applies To', 'event_espresso'), - 'valid_from' => __('Valid From', 'event_espresso'), - 'valid_until' => __('Valid Until', 'event_espresso'), - 'amount' => __('Discount', 'event_espresso'), - 'redeemed' => __('Uses', 'event_espresso'), - 'attributes' => '' . __('Attributes', 'event_espresso') . '', - 'actions' => __('Actions', 'event_espresso') + 'id' => esc_html__('ID', 'event_espresso'), + 'name' => esc_html__('Name', 'event_espresso'), + 'code' => esc_html__('Code', 'event_espresso'), + 'applies_to' => esc_html__('Applies To', 'event_espresso'), + 'valid_from' => esc_html__('Valid From', 'event_espresso'), + 'valid_until' => esc_html__('Valid Until', 'event_espresso'), + 'amount' => esc_html__('Discount', 'event_espresso'), + 'redeemed' => esc_html__('Uses', 'event_espresso'), + 'attributes' => '' . esc_html__('Attributes', 'event_espresso') . '', + 'actions' => esc_html__('Actions', 'event_espresso') ); $this->_primary_column = 'ID'; @@ -112,7 +112,7 @@ public function column_id(EE_Promotion $item) public function column_name(EE_Promotion $item) { $edit_link = EEH_URL::add_query_args_and_nonce(array( 'action' => 'edit', 'PRO_ID' => $item->ID() ), EE_PROMOTIONS_ADMIN_URL); - $content = EE_Registry::instance()->CAP->current_user_can('ee_edit_promotion', 'espresso_promotions_edit_promotion', $item->ID()) ? '
' . $item->name() . '' : $item->name(); + $content = EE_Registry::instance()->CAP->current_user_can('ee_edit_promotion', 'espresso_promotions_edit_promotion', $item->ID()) ? '' . $item->name() . '' : $item->name(); $content .= '
' . EEH_Template::pretty_status($item->status(), false, 'sentence') . ''; return $content; } @@ -134,8 +134,8 @@ public function column_applies_to(EE_Promotion $item) public function column_attributes(EE_Promotion $item) { - echo $item->is_exclusive() ? '' : ''; - echo $item->is_global() ? '' : ''; + echo $item->is_exclusive() ? '' : ''; + echo $item->is_global() ? '' : ''; } @@ -206,11 +206,11 @@ public function column_actions(EE_Promotion $item) $edit_link = EEH_URL::add_query_args_and_nonce($edit_query_args, EE_PROMOTIONS_ADMIN_URL); $dupe_link = EEH_URL::add_query_args_and_nonce($dupe_query_args, EE_PROMOTIONS_ADMIN_URL); if (EE_Registry::instance()->CAP->current_user_can('ee_edit_promotion', 'espresso_promotions_edit_promotion', $item->ID())) { - $action_links[] = '
'; + $action_links[] = '
'; } if (EE_Registry::instance()->CAP->current_user_can('ee_edit_promotion', 'espresso_promotions_edit_promotion', $item->ID())) { - $action_links[] = '
'; + $action_links[] = '
'; } } else { $restore_query_args = array( @@ -219,7 +219,7 @@ public function column_actions(EE_Promotion $item) ); $restore_link = EEH_URL::add_query_args_and_nonce($restore_query_args, EE_PROMOTIONS_ADMIN_URL); if (EE_Registry::instance()->CAP->current_user_can('ee_delete_promotion', 'espresso_promotions_delete_promotion', $item->ID())) { - $action_links[] = '
'; + $action_links[] = '
'; } } @@ -228,7 +228,7 @@ public function column_actions(EE_Promotion $item) 'PRO_ID' => $item->ID() ); $trash_link = EEH_URL::add_query_args_and_nonce($trash_query_args, EE_PROMOTIONS_ADMIN_URL); - $trash_text = $this->_view == 'trash' ? __('Delete Promotion permanently', 'event_espresso') : __('Trash Promotion', 'event_espresso'); + $trash_text = $this->_view == 'trash' ? esc_html__('Delete Promotion permanently', 'event_espresso') : esc_html__('Trash Promotion', 'event_espresso'); $trash_class = $this->_view == 'trash' ? ' red-icon' : ''; if (EE_Registry::instance()->CAP->current_user_can('ee_delete_promotion', 'espresso_promotions_delete_promotion', $item->ID())) { $action_links[] = $this->_view == 'trash' && $item->redeemed() > 0 ? '' : '
'; diff --git a/admin/promotions/Promotions_Admin_Page.core.php b/admin/promotions/Promotions_Admin_Page.core.php index b6a765f..16b4d5f 100644 --- a/admin/promotions/Promotions_Admin_Page.core.php +++ b/admin/promotions/Promotions_Admin_Page.core.php @@ -1,12 +1,12 @@ page_slug = PROMOTIONS_PG_SLUG; - $this->page_label = PROMOTIONS_LABEL; - $this->_admin_base_url = EE_PROMOTIONS_ADMIN_URL; + $this->page_slug = PROMOTIONS_PG_SLUG; + $this->page_label = PROMOTIONS_LABEL; + $this->_admin_base_url = EE_PROMOTIONS_ADMIN_URL; $this->_admin_base_path = EE_PROMOTIONS_ADMIN; } - - protected function _ajax_hooks() { } - - - protected function _define_page_props() { $this->_admin_page_title = PROMOTIONS_LABEL; - $this->_labels = array( - 'buttons' => array( - 'add' => __('Add New Promotion', 'event_espresso'), - 'edit' => __('Edit Promotion', 'event_espresso'), - 'trash_promotion' => __('Trash Promotion', 'event_espresso'), - 'restore_promotion' => __('Restore Promotion', 'event_espresso') - ), - 'publishbox' => array( - 'create_new' => __('Save New Promotion', 'event_espresso'), - 'edit' => __('Update Promotion', 'event_espresso'), - 'promotions_settings' => __('Update Settings', 'event_espresso') - ) - ); + $this->_labels = [ + 'buttons' => [ + 'add' => esc_html__('Add New Promotion', 'event_espresso'), + 'edit' => esc_html__('Edit Promotion', 'event_espresso'), + 'trash_promotion' => esc_html__('Trash Promotion', 'event_espresso'), + 'restore_promotion' => esc_html__('Restore Promotion', 'event_espresso'), + ], + 'publishbox' => [ + 'create_new' => esc_html__('Save New Promotion', 'event_espresso'), + 'edit' => esc_html__('Update Promotion', 'event_espresso'), + 'promotions_settings' => esc_html__('Update Settings', 'event_espresso'), + ], + ]; } - - protected function _set_page_routes() { - $pro_id = ! empty($this->_req_data['PRO_ID']) && ! is_array($this->_req_data['PRO_ID']) ? $this->_req_data['PRO_ID'] : 0; - $this->_page_routes = array( - 'default' => array( - 'func' => '_list_table', - 'capability' => 'ee_read_promotions' - ), - 'create_new' => array( - 'func' => '_promotion_details', + $pro_id = + ! empty($this->_req_data['PRO_ID']) && ! is_array($this->_req_data['PRO_ID']) ? $this->_req_data['PRO_ID'] + : 0; + $this->_page_routes = [ + 'default' => [ + 'func' => '_list_table', + 'capability' => 'ee_read_promotions', + ], + 'create_new' => [ + 'func' => '_promotion_details', 'capability' => 'ee_edit_promotions', - 'args' => array(true) - ), - 'edit' => array( - 'func' => '_promotion_details', + 'args' => [true], + ], + 'edit' => [ + 'func' => '_promotion_details', 'capability' => 'ee_edit_promotion', - 'obj_id' => $pro_id - ), - 'update_promotion' => array( - 'func' => '_insert_update_promotions', + 'obj_id' => $pro_id, + ], + 'update_promotion' => [ + 'func' => '_insert_update_promotions', 'capability' => 'ee_edit_promotion', - 'obj_id' => $pro_id, - 'noheader' => true - ), - 'insert_promotion' => array( - 'func' => '_insert_update_promotions', + 'obj_id' => $pro_id, + 'noheader' => true, + ], + 'insert_promotion' => [ + 'func' => '_insert_update_promotions', 'capability' => 'ee_edit_promotions', - 'noheader' => true, - 'args' => array( true ) - ), - 'duplicate' => array( - 'func' => '_duplicate_promotion', + 'noheader' => true, + 'args' => [true], + ], + 'duplicate' => [ + 'func' => '_duplicate_promotion', 'capability' => 'ee_edit_promotion', - 'obj_id' => $pro_id, - 'noheader' => true - ), - 'trash_promotion' => array( - 'func' => '_trash_or_restore_promotion', + 'obj_id' => $pro_id, + 'noheader' => true, + ], + 'trash_promotion' => [ + 'func' => '_trash_or_restore_promotion', 'capability' => 'ee_delete_promotion', - 'obj_id' => $pro_id, - 'args' => array( true ), - 'noheader' => true - ), - 'trash_promotions' => array( - 'func' => '_trash_or_restore_promotions', + 'obj_id' => $pro_id, + 'args' => [true], + 'noheader' => true, + ], + 'trash_promotions' => [ + 'func' => '_trash_or_restore_promotions', 'capability' => 'ee_delete_promotions', - 'args' => array( true ), - 'noheader' => true - ), - 'restore_promotion' => array( - 'func' => '_trash_or_restore_promotion', + 'args' => [true], + 'noheader' => true, + ], + 'restore_promotion' => [ + 'func' => '_trash_or_restore_promotion', 'capability' => 'ee_delete_promotion', - 'obj_id' => $pro_id, - 'args' => array( false ), - 'noheader' => true - ), - 'restore_promotions' => array( - 'func' => '_trash_or_restore_promotions', + 'obj_id' => $pro_id, + 'args' => [false], + 'noheader' => true, + ], + 'restore_promotions' => [ + 'func' => '_trash_or_restore_promotions', 'capability' => 'ee_delete_promotions', - 'args' => array( false ), - 'noheader' => true - ), - 'delete_promotions' => array( - 'func' => '_delete_promotions', + 'args' => [false], + 'noheader' => true, + ], + 'delete_promotions' => [ + 'func' => '_delete_promotions', 'capability' => 'ee_delete_promotions', - 'noheader' => true - ), - 'delete_promotion' => array( - 'func' => '_delete_promotion', + 'noheader' => true, + ], + 'delete_promotion' => [ + 'func' => '_delete_promotion', 'capability' => 'ee_delete_promotion', - 'obj_id' => $pro_id, - 'noheader' => true - ), - 'promotions_settings' => array( - 'func' => '_promotions_settings', + 'obj_id' => $pro_id, + 'noheader' => true, + ], + 'promotions_settings' => [ + 'func' => '_promotions_settings', 'capability' => 'manage_options', - ), - 'update_settings' => array( - 'func' => '_update_settings', + ], + 'update_settings' => [ + 'func' => '_update_settings', 'capability' => 'manage_options', - 'noheader' => true - ), - 'usage' => array( - 'func' => '_usage', - 'capability' => 'ee_read_promotions' - ) - ); + 'noheader' => true, + ], + 'usage' => [ + 'func' => '_usage', + 'capability' => 'ee_read_promotions', + ], + ]; } - - - protected function _set_page_config() { EE_Registry::instance()->load_helper('URL'); - $this->_page_config = array( - 'default' => array( - 'nav' => array( - 'label' => __('Promotions Overview', 'event_espresso'), - 'order' => 10 + $this->_page_config = [ + 'default' => [ + 'nav' => [ + 'label' => esc_html__('Promotions Overview', 'event_espresso'), + 'order' => 10, + ], + 'qtips' => ['Promotions_List_Table_Tips'], + 'list_table' => 'Promotions_Admin_List_Table', + 'require_nonce' => false, + ], + 'create_new' => [ + 'nav' => [ + 'label' => esc_html__('Create Promotion', 'event_espresso'), + 'order' => 15, + 'url' => EEH_URL::add_query_args_and_nonce( + ['action' => 'create_new'], + EE_PROMOTIONS_ADMIN_URL ), - 'qtips' => array( 'Promotions_List_Table_Tips' ), - 'list_table' => 'Promotions_Admin_List_Table', - 'require_nonce' => false - ), - 'create_new' => array( - 'nav' => array( - 'label' => __('Create Promotion', 'event_espresso'), - 'order' => 15, - 'url' => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), EE_PROMOTIONS_ADMIN_URL), - 'persistent' => false - ), - 'metaboxes' => array( '_promotions_metaboxes', '_publish_post_box' ), - 'require_nonce' => false - ), - 'edit' => array( - 'nav' => array( - 'label' => __('Edit Promotion', 'event_espresso'), - 'order' => 15, - 'url' => EEH_URL::add_query_args_and_nonce(array('action' => 'edit', 'PRO_ID' => !empty($this->_req_data['PRO_ID']) ? $this->_req_data['PRO_ID'] : 0 ), EE_PROMOTIONS_ADMIN_URL), - 'persistent' => false - ), - 'metaboxes' => array( '_promotions_metaboxes', '_publish_post_box' ), - 'require_nonce' => false - ), - 'promotions_settings' => array( - 'nav' => array( - 'label' => __('Settings', 'event_espresso'), - 'order' => 20 - ), - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array( '_publish_post_box')), - 'require_nonce' => false - ), - 'usage' => array( - 'nav' => array( - 'label' => __('Promotions Usage', 'event_espresso'), - 'order' => 30 + 'persistent' => false, + ], + 'metaboxes' => ['_promotions_metaboxes', '_publish_post_box'], + 'require_nonce' => false, + ], + 'edit' => [ + 'nav' => [ + 'label' => esc_html__('Edit Promotion', 'event_espresso'), + 'order' => 15, + 'url' => EEH_URL::add_query_args_and_nonce( + [ + 'action' => 'edit', + 'PRO_ID' => ! empty($this->_req_data['PRO_ID']) ? $this->_req_data['PRO_ID'] : 0, + ], + EE_PROMOTIONS_ADMIN_URL ), - 'require_nonce' => false - ) - ); + 'persistent' => false, + ], + 'metaboxes' => ['_promotions_metaboxes', '_publish_post_box'], + 'require_nonce' => false, + ], + 'promotions_settings' => [ + 'nav' => [ + 'label' => esc_html__('Settings', 'event_espresso'), + 'order' => 20, + ], + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), + 'require_nonce' => false, + ], + 'usage' => [ + 'nav' => [ + 'label' => esc_html__('Promotions Usage', 'event_espresso'), + 'order' => 30, + ], + 'require_nonce' => false, + ], + ]; } protected function _add_screen_options() { } + + protected function _add_screen_options_default() { $this->_per_page_screen_option(); } + protected function _add_feature_pointers() { } - - public function load_scripts_styles() { - wp_register_style('promotions-details-css', EE_PROMOTIONS_ADMIN_ASSETS_URL . 'promotions-details.css', array('ee-admin-css','espresso-ui-theme'), EE_PROMOTIONS_VERSION); + wp_register_style( + 'promotions-details-css', + EE_PROMOTIONS_ADMIN_ASSETS_URL . 'promotions-details.css', + ['ee-admin-css', 'espresso-ui-theme'], + EE_PROMOTIONS_VERSION + ); wp_enqueue_style('promotions-details-css'); - wp_register_script('espresso_promotions_admin', EE_PROMOTIONS_ADMIN_ASSETS_URL . 'espresso_promotions_admin.js', array( 'espresso_core', 'ee-datepicker', 'ee-parse-uri' ), EE_PROMOTIONS_VERSION, true); + wp_register_script( + 'espresso_promotions_admin', + EE_PROMOTIONS_ADMIN_ASSETS_URL . 'espresso_promotions_admin.js', + ['espresso_core', 'ee-datepicker', 'ee-parse-uri'], + EE_PROMOTIONS_VERSION, + true + ); wp_enqueue_script('espresso_promotions_admin'); } + public function admin_init() { - EE_Registry::$i18n_js_strings['confirm_reset'] = __('Are you sure you want to reset ALL your Event Espresso Promotions Information? This cannot be undone.', 'event_espresso'); - EE_Registry::$i18n_js_strings['codefieldEmptyError'] = __('eePromotionsHelper.generate_code requires a selector for the codefield param. None was provided.', 'event_espresso'); - EE_Registry::$i18n_js_strings['codefieldInvalidError'] = __('The codefield parameter sent to eePromotionsHelper.generate_code is invalid. It must be a valid selector for the input field holding the generated coupon code.', 'event_espresso'); - EE_Registry::$i18n_js_strings['toggledScopeItemMissingParam'] = __('eePromotionsHelper.scopeItemToggle requires the toggled checkbox dom element to be included as the argument. Nothing was included.', 'event_espresso'); + EE_Registry::$i18n_js_strings['confirm_reset'] = esc_html__( + 'Are you sure you want to reset ALL your Event Espresso Promotions Information? This cannot be undone.', + 'event_espresso' + ); + EE_Registry::$i18n_js_strings['codefieldEmptyError'] = esc_html__( + 'eePromotionsHelper.generate_code requires a selector for the codefield param. None was provided.', + 'event_espresso' + ); + EE_Registry::$i18n_js_strings['codefieldInvalidError'] = esc_html__( + 'The codefield parameter sent to eePromotionsHelper.generate_code is invalid. It must be a valid selector for the input field holding the generated coupon code.', + 'event_espresso' + ); + EE_Registry::$i18n_js_strings['toggledScopeItemMissingParam'] = esc_html__( + 'eePromotionsHelper.scopeItemToggle requires the toggled checkbox dom element to be included as the argument. Nothing was included.', + 'event_espresso' + ); } + public function admin_notices() { // is this a non global promotion? If so, then if there are no uses then let's show a notice that the promotion is // not active until a scope item is selected. - if ($this->_promotion instanceof EE_Promotion && $this->_promotion->ID() !== 0 && ! $this->_promotion->is_global() && $this->_promotion->get_scope_object_count() === 0) { - EE_Error::add_attention(sprintf(__('This promotion is currently not active because you have selected %s as the scope for the promotion but have not applied the promotion to any %s.', 'event_espresso'), $this->_promotion->scope_obj()->label->singular, strtolower($this->_promotion->scope_obj()->label->plural))); - echo ( EE_Error::get_notices() ); + if ( + $this->_promotion instanceof EE_Promotion + && $this->_promotion->ID() !== 0 + && ! $this->_promotion->is_global() + && $this->_promotion->get_scope_object_count() === 0 + ) { + EE_Error::add_attention( + sprintf( + __( + 'This promotion is currently not active because you have selected %s as the scope for the promotion but have not applied the promotion to any %s.', + 'event_espresso' + ), + $this->_promotion->scope_obj()->label->singular, + strtolower($this->_promotion->scope_obj()->label->plural) + ) + ); + echo(EE_Error::get_notices()); } } + + public function admin_footer_scripts() { } - - /** * _set_list_table_views_default + * * @access protected */ protected function _set_list_table_views_default() { - $this->_views = array( - 'all' => array( - 'slug' => 'all', - 'label' => __('All', 'event_espresso'), - 'count' => 0, - 'bulk_action' => array() - ), - 'trash' => array( - 'slug' => 'trash', - 'label' => __('Trashed', 'event_espresso'), - 'count' => 0, - 'bulk_action' => array( - 'restore_promotions' => __('Restore from Trash', 'event_espresso'), - 'delete_promotions' => __('Delete', 'event_espresso') - ) - )/**/ - ); - - - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_promotions', 'espresso_promotions_delete_promotions')) { - $this->_views['trash'] = array( - 'slug' => 'trash', - 'label' => __('Trashed', 'event_espresso'), - 'count' => 0, - 'bulk_action' => array( + $this->_views = [ + 'all' => [ + 'slug' => 'all', + 'label' => esc_html__('All', 'event_espresso'), + 'count' => 0, + 'bulk_action' => [], + ], + 'trash' => [ + 'slug' => 'trash', + 'label' => esc_html__('Trashed', 'event_espresso'), + 'count' => 0, + 'bulk_action' => [ + 'restore_promotions' => esc_html__('Restore from Trash', 'event_espresso'), + 'delete_promotions' => esc_html__('Delete', 'event_espresso'), + ], + ]/**/ + ]; + + + if ( + EE_Registry::instance()->CAP->current_user_can( + 'ee_delete_promotions', + 'espresso_promotions_delete_promotions' + ) + ) { + $this->_views['trash'] = [ + 'slug' => 'trash', + 'label' => esc_html__('Trashed', 'event_espresso'), + 'count' => 0, + 'bulk_action' => [ 'restore_promotions' => __('Restore from Trash', 'event_espresso'), - 'delete_promotions' => __('Delete', 'event_espresso') - ) - ); - $this->_views['all']['bulk_action'] = array( - 'trash_promotions' => __('Move to Trash', 'event_espresso') - ); + 'delete_promotions' => __('Delete', 'event_espresso'), + ], + ]; + $this->_views['all']['bulk_action'] = [ + 'trash_promotions' => __('Move to Trash', 'event_espresso'), + ]; } } - /** * _list_table * * @access protected - * @throws \EE_Error + * @throws EE_Error */ protected function _list_table() { $this->_config = $this->_get_config(); - if (EE_Registry::instance()->CAP->current_user_can('ee_edit_promotions', 'esspresso_promotions_create_new_promotion')) { + if ( + EE_Registry::instance()->CAP->current_user_can( + 'ee_edit_promotions', + 'esspresso_promotions_create_new_promotion' + ) + ) { $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( - 'create_new', - 'add', - array(), - 'add-new-h2' - ); + 'create_new', + 'add', + [], + 'add-new-h2' + ); } $this->_template_args['after_list_table'] = $this->_display_legend($this->_promotion_legend_items()); $this->display_admin_list_table_page_with_no_sidebar(); } - /** * _promotion_legend_items + * * @return array + * @throws EE_Error + * @throws EE_Error */ protected function _promotion_legend_items() { - $items = array( - 'active_status' => array( + $items = [ + 'active_status' => [ 'class' => 'ee-status-legend ee-status-legend-' . EE_Promotion::active, - 'desc' => EEH_Template::pretty_status(EE_Promotion::active, false, 'sentence') - ), - 'upcoming_status' => array( + 'desc' => EEH_Template::pretty_status(EE_Promotion::active, false, 'sentence'), + ], + 'upcoming_status' => [ 'class' => 'ee-status-legend ee-status-legend-' . EE_Promotion::upcoming, - 'desc' => EEH_Template::pretty_status(EE_Promotion::upcoming, false, 'sentence') - ), - 'expired_status' => array( + 'desc' => EEH_Template::pretty_status(EE_Promotion::upcoming, false, 'sentence'), + ], + 'expired_status' => [ 'class' => 'ee-status-legend ee-status-legend-' . EE_Promotion::expired, - 'desc' => EEH_Template::pretty_status(EE_Promotion::expired, false, 'sentence') - ), - 'unavailable_status' => array( + 'desc' => EEH_Template::pretty_status(EE_Promotion::expired, false, 'sentence'), + ], + 'unavailable_status' => [ 'class' => 'ee-status-legend ee-status-legend-' . EE_Promotion::unavailable, - 'desc' => EEH_Template::pretty_status(EE_Promotion::unavailable, false, 'sentence') - ), - '' => array( - 'class' => '', - 'desc' => '' - ), - ); + 'desc' => EEH_Template::pretty_status(EE_Promotion::unavailable, false, 'sentence'), + ], + ]; foreach ($this->_config->scopes as $scope) { if ($scope instanceof EE_Promotion_Scope) { - $items[ $scope->slug ] = array( + $items[$scope->slug] = [ 'class' => $scope->get_scope_icon(true), 'desc' => sprintf( __('%1$s Scope Promotion - applies to %2$s only', 'event_espresso'), $scope->label->singular, $scope->label->plural - ) - ); + ), + ]; } } - $items['global'] = array( + $items['global'] = [ 'class' => 'dashicons dashicons-admin-site', - 'desc' => __('Global Promotion - applies to ALL scope items', 'event_espresso') - ); - $items['exclusive'] = array( + 'desc' => __('Global Promotion - applies to ALL scope items', 'event_espresso'), + ]; + $items['exclusive'] = [ 'class' => 'dashicons dashicons-awards', - 'desc' => __('Exclusive Promotion - can NOT be combined with others', 'event_espresso') - ); - $items['unlimited'] = array( - 'class' => '', - 'desc' => __('Unlimited', 'event_espresso') - ); + 'desc' => __('Exclusive Promotion - can NOT be combined with others', 'event_espresso'), + ]; + $items['unlimited'] = [ + 'class' => '', + 'desc' => __('Unlimited', 'event_espresso'), + ]; return $items; } - /** * _set_promotion_object * * @access protected - * @throws \EE_Error + * @throws EE_Error + * @throws ReflectionException */ protected function _set_promotion_object() { @@ -396,57 +446,85 @@ protected function _set_promotion_object() if ($this->_promotion instanceof EE_Promotion) { return; } - $this->_promotion = !empty($this->_req_data['PRO_ID']) ? EEM_Promotion::instance()->get_one_by_ID($this->_req_data['PRO_ID']) : EEM_Promotion::instance()->create_default_object(); + $this->_promotion = + ! empty($this->_req_data['PRO_ID']) ? EEM_Promotion::instance()->get_one_by_ID($this->_req_data['PRO_ID']) + : EEM_Promotion::instance()->create_default_object(); // verify we have a promotion object if (! $this->_promotion instanceof EE_Promotion) { - throw new EE_Error(sprintf(__('Something might be wrong with the models or the given Promotion ID in the request (%s) is not for a valid Promotion in the DB.', 'event_espresso'), $this->_req_data['PRO_ID'])); + throw new EE_Error( + sprintf( + __( + 'Something might be wrong with the models or the given Promotion ID in the request (%s) is not for a valid Promotion in the DB.', + 'event_espresso' + ), + $this->_req_data['PRO_ID'] + ) + ); } } - /** * metaboxes callback for create_new and edit promotion routes. * - * @since 1.0.0 * @return void - * @throws \EE_Error + * @throws EE_Error + * @since 1.0.0 */ protected function _promotions_metaboxes() { $this->_config = $this->_get_config(); $this->_set_promotion_object(); - add_meta_box('promotion-details-mbox', __('Promotions', 'event_espresso'), array( $this, 'promotion_details_metabox'), $this->_wp_page_slug, 'normal', 'high'); - add_meta_box('promotions-applied-to-mbox', __('Promotion applies to...', 'event_espresso'), array( $this, 'promotions_applied_to_metabox'), $this->_wp_page_slug, 'side', 'default'); + add_meta_box( + 'promotion-details-mbox', + __('Promotions', 'event_espresso'), + [$this, 'promotion_details_metabox'], + $this->_wp_page_slug, + 'normal', + 'high' + ); + add_meta_box( + 'promotions-applied-to-mbox', + __('Promotion applies to...', 'event_espresso'), + [$this, 'promotions_applied_to_metabox'], + $this->_wp_page_slug, + 'side', + 'default' + ); } - /** * Callback for the create new promotion route. * - * @since 1.0.0 * @param bool $new Whether promotion is new or not. Default TRUE. * @return void - * @throws \EE_Error + * @throws EE_Error + * @throws ReflectionException + * @since 1.0.0 */ protected function _promotion_details($new = false) { - $id = $new ? '' : $this->_promotion->ID(); - $redirect = EEH_URL::add_query_args_and_nonce(array('action' => 'default'), $this->_admin_base_url); - $view = $new ? 'insert_promotion' : 'update_promotion'; + $id = $new ? '' : $this->_promotion->ID(); + $redirect = EEH_URL::add_query_args_and_nonce(['action' => 'default'], $this->_admin_base_url); + $view = $new ? 'insert_promotion' : 'update_promotion'; $this->_set_add_edit_form_tags($view); $route = $this->_promotion->get('PRO_deleted') ? 'restore_promotion' : 'trash_promotion'; /** add new button */ - if (EE_Registry::instance()->CAP->current_user_can('ee_edit_promotions', 'espresso_promotions_create_new_promotion')) { + if ( + EE_Registry::instance()->CAP->current_user_can( + 'ee_edit_promotions', + 'espresso_promotions_create_new_promotion' + ) + ) { $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( - 'create_new', - 'add', - array(), - 'add-new-h2' - ); + 'create_new', + 'add', + [], + 'add-new-h2' + ); } $this->_set_publish_post_box_vars('PRO_ID', $id, $route, $redirect); @@ -454,32 +532,56 @@ protected function _promotion_details($new = false) } - /** * promotion_details_metabox */ public function promotion_details_metabox() { - $promotion_uses = $this->_promotion->uses(); + $promotion_uses = $this->_promotion->uses(); $promotion_global_uses = $this->_promotion->global_uses(); - $form_args = array( - 'promotion' => $this->_promotion, - 'promotion_global' => EEH_Form_Fields::select_input('PRO_global', $this->_yes_no_values, $this->_promotion->is_global()), - 'promotion_exclusive' => EEH_Form_Fields::select_input('PRO_exclusive', $this->_yes_no_values, $this->_promotion->is_exclusive()), - 'promotion_uses' => $promotion_uses !== EE_INF_IN_DB ? $promotion_uses : '', + $form_args = [ + 'promotion' => $this->_promotion, + 'promotion_global' => EEH_Form_Fields::select_input( + 'PRO_global', + $this->_yes_no_values, + $this->_promotion->is_global() + ), + 'promotion_exclusive' => EEH_Form_Fields::select_input( + 'PRO_exclusive', + $this->_yes_no_values, + $this->_promotion->is_exclusive() + ), + 'promotion_uses' => $promotion_uses !== EE_INF_IN_DB ? $promotion_uses : '', 'promotion_global_uses' => $promotion_global_uses !== EE_INF_IN_DB ? $promotion_global_uses : '', - 'price_type_selector' => $this->_get_price_type_selector(), - 'scope_selector' => $this->_get_promotion_scope_selector() - ); - EEH_Template::display_template(EE_PROMOTIONS_ADMIN_TEMPLATE_PATH . 'promotion_details_form.template.php', $form_args); + 'price_type_selector' => $this->_get_price_type_selector(), + 'scope_selector' => $this->_get_promotion_scope_selector(), + 'promo_starts_datepicker' => new PromotionsDatepicker( + $this->_promotion->start('Y-m-d', 'h:i a'), + 'start', + '#promotion-details-mbox', + 'PRO_start', + esc_html__('enter promotion start date', 'event_espresso') + ), + 'promo_ends_datepicker' => new PromotionsDatepicker( + $this->_promotion->end('Y-m-d', 'h:i a'), + 'end', + '#promotion-details-mbox', + 'PRO_end', + esc_html__('enter promotion end date', 'event_espresso') + ), + ]; + EEH_Template::display_template( + EE_PROMOTIONS_ADMIN_TEMPLATE_PATH . 'promotion_details_form.template.php', + $form_args + ); } - /** * promotions_applied_to_metabox * - * @throws \EE_Error + * @throws EE_Error + * @throws ReflectionException */ public function promotions_applied_to_metabox() { @@ -487,26 +589,29 @@ public function promotions_applied_to_metabox() $scope = $this->_promotion->scope_obj(); // if there is no scope then this is a default promotion object so the content will for promotions metabox will be generic. - $content = empty($scope) ? __('When you select a scope for the promotion this area will have options related to the selection.', 'event_espresso') : $scope->get_admin_applies_to_selector($this->_promotion->ID()); + $content = empty($scope) ? __( + 'When you select a scope for the promotion this area will have options related to the selection.', + 'event_espresso' + ) : $scope->get_admin_applies_to_selector($this->_promotion->ID()); echo $content; } - /** * _get_price_type_selector + * * @return string */ protected function _get_price_type_selector() { // get Price Types for discount base price type. - $price_types = EEM_Price_Type::instance()->get_all(array( array( 'PBT_ID' => EEM_Price_Type::base_type_discount ) )); - $values = array(); + $price_types = EEM_Price_Type::instance()->get_all([['PBT_ID' => EEM_Price_Type::base_type_discount]]); + $values = []; foreach ($price_types as $ID => $pt) { - $values[] = array( + $values[] = [ 'text' => $pt->name(), - 'id' => $ID - ); + 'id' => $ID, + ]; } $default = $this->_promotion->price_type_id(); @@ -515,26 +620,25 @@ protected function _get_price_type_selector() } - - /** * _get_promotion_scope_selector + * * @access protected */ protected function _get_promotion_scope_selector() { - $values = array(); + $values = []; foreach ($this->_config->scopes as $scope_name => $scope) { - $values[] = array( + $values[] = [ 'text' => $scope->label->singular, - 'id' => $scope_name - ); + 'id' => $scope_name, + ]; } - $redeemed = $this->_promotion->redeemed(); - $name = $redeemed > 0 ? 'PRO_scope_disabled' : 'PRO_scope'; - $default = $this->_promotion->scope(); + $redeemed = $this->_promotion->redeemed(); + $name = $redeemed > 0 ? 'PRO_scope_disabled' : 'PRO_scope'; + $default = $this->_promotion->scope(); $extra_params = $redeemed > 0 ? 'disabled="disabled"' : ''; - $content = EEH_Form_Fields::select_input($name, $values, $default, $extra_params); + $content = EEH_Form_Fields::select_input($name, $values, $default, $extra_params); if ($redeemed > 0) { $content .= ''; } @@ -542,18 +646,18 @@ protected function _get_promotion_scope_selector() } - /** * Takes care of inserting/updating promotions. * - * @since 1.0.0 * @param bool $new Default false. Whether inserting or not. * @return void - * @throws \EE_Error + * @throws EE_Error + * @throws ReflectionException + * @since 1.0.0 */ protected function _insert_update_promotions($new = false) { - $promotion_values = array( + $promotion_values = [ 'PRO_ID' => ! empty($this->_req_data['PRO_ID']) ? absint($this->_req_data['PRO_ID']) : 0, @@ -578,7 +682,7 @@ protected function _insert_update_promotions($new = false) 'PRO_uses' => ! empty($this->_req_data['PRO_uses']) ? $this->_req_data['PRO_uses'] : EE_INF_IN_DB, - 'PRO_global_uses' => ! empty($this->_req_data['PRO_global_uses']) + 'PRO_global_uses' => ! empty($this->_req_data['PRO_global_uses']) ? $this->_req_data['PRO_global_uses'] : EE_INF_IN_DB, 'PRO_accept_msg' => ! empty($this->_req_data['PRO_accept_msg']) @@ -586,9 +690,9 @@ protected function _insert_update_promotions($new = false) : '', 'PRO_decline_msg' => ! empty($this->_req_data['PRO_decline_msg']) ? $this->_req_data['PRO_decline_msg'] - : '' - ); - $promo_price_values = array( + : '', + ]; + $promo_price_values = [ 'PRC_ID' => ! empty($this->_req_data['PRC_ID']) ? $this->_req_data['PRC_ID'] : 0, @@ -606,8 +710,8 @@ protected function _insert_update_promotions($new = false) : 0, 'PRC_desc' => ! empty($this->_req_data['PRC_desc']) ? $this->_req_data['PRC_desc'] - : '' - ); + : '', + ]; // first handle the price object $price = empty($promo_price_values['PRC_ID']) ? EE_Price::new_instance($promo_price_values) @@ -622,7 +726,7 @@ protected function _insert_update_promotions($new = false) $price->save(); // next handle the promotions if (empty($promotion_values['PRO_ID'])) { - $promotion = EE_Promotion::new_instance($promotion_values, null, array( 'Y-m-d', 'g:i a' )); + $promotion = EE_Promotion::new_instance($promotion_values, null, ['Y-m-d', 'g:i a']); } else { $promotion = EEM_Promotion::instance()->get_one_by_ID($promotion_values['PRO_ID']); } @@ -658,41 +762,51 @@ protected function _insert_update_promotions($new = false) ); } - $query_args = array( + $query_args = [ 'PRO_ID' => $PRO_ID, - 'action' => 'edit' - ); + 'action' => 'edit', + ]; $this->_redirect_after_action(null, '', '', $query_args, true); } - /** * Duplicates a promotion. * - * @since 1.0.0 * @return void - * @throws \EE_Error + * @throws EE_Error + * @throws ReflectionException + * @since 1.0.0 */ protected function _duplicate_promotion() { $new_promo = null; - $success = true; + $success = true; // first verify we have a promotion id $pro_id = ! empty($this->_req_data['PRO_ID']) ? $this->_req_data['PRO_ID'] : 0; if (empty($pro_id)) { $success = false; - EE_Error::add_error(__('Unable to duplicate the promotion because there was no ID present in the request.', 'event_espresso')); + EE_Error::add_error( + __( + 'Unable to duplicate the promotion because there was no ID present in the request.', + 'event_espresso' + ) + ); } if ($success) { $orig_promo = EEM_Promotion::instance()->get_one_by_ID($pro_id); - $new_promo = $orig_promo instanceof EE_Promotion ? clone $orig_promo : null; + $new_promo = $orig_promo instanceof EE_Promotion ? clone $orig_promo : null; if (! $new_promo instanceof EE_Promotion) { $success = false; - EE_Error::add_error(__('Unable to duplicate the promotion because for some reason there isn\'t a promotion in the database for the given id.', 'event_espresso')); + EE_Error::add_error( + __( + 'Unable to duplicate the promotion because for some reason there isn\'t a promotion in the database for the given id.', + 'event_espresso' + ) + ); } if ($success) { @@ -719,56 +833,83 @@ protected function _duplicate_promotion() } if ($success) { - EE_Error::add_success(__('Promotion successfully duplicated, make any additional edits and update.', 'event_espresso')); + EE_Error::add_success( + __('Promotion successfully duplicated, make any additional edits and update.', 'event_espresso') + ); } - $query_args = array( + $query_args = [ 'PRO_ID' => $new_promo instanceof EE_Promotion ? $new_promo->ID() : 0, - 'action' => ! empty($pro_id) ? 'edit' : 'default' - ); + 'action' => ! empty($pro_id) ? 'edit' : 'default', + ]; $this->_redirect_after_action(null, '', '', $query_args, true); } - /** * Handles either trashing or restoring a given promotion. * - * @since 1.0.0 - * - * @param bool $trash if true trashing, otherwise restoring - * @param int $PRO_ID if set then this will be used for the promotion id to trash/restore. + * @param bool $trash if true trashing, otherwise restoring + * @param int $PRO_ID if set then this will be used for the promotion id to trash/restore. * @param bool $redirect if true then redirect otherwise don't * @return bool value of $success + * @since 1.0.0 + * */ protected function _trash_or_restore_promotion($trash = false, $PRO_ID = 0, $redirect = true) { $success = true; - $PRO_ID = !empty($PRO_ID) ? $PRO_ID : 0; - $PRO_ID = !empty($this->_req_data['PRO_ID']) && empty($PRO_ID) ? $this->_req_data['PRO_ID'] : $PRO_ID; + $PRO_ID = ! empty($PRO_ID) ? $PRO_ID : 0; + $PRO_ID = ! empty($this->_req_data['PRO_ID']) && empty($PRO_ID) ? $this->_req_data['PRO_ID'] : $PRO_ID; if (empty($PRO_ID)) { $success = false; if ($trash) { - EE_Error::add_error(__('Unable to trash a promotion because no promotion id is accessible.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); + EE_Error::add_error( + __('Unable to trash a promotion because no promotion id is accessible.', 'event_espresso'), + __FILE__, + __FUNCTION__, + __LINE__ + ); } else { - EE_Error::add_error(__('Unable to restore a promotion because no promotion id is accessible.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); + EE_Error::add_error( + __('Unable to restore a promotion because no promotion id is accessible.', 'event_espresso'), + __FILE__, + __FUNCTION__, + __LINE__ + ); } } if ($success) { - $success = $trash ? EEM_Promotion::instance()->delete_by_ID($PRO_ID) : EEM_Promotion::instance()->restore_by_ID($PRO_ID); + $success = $trash + ? EEM_Promotion::instance()->delete_by_ID($PRO_ID) : EEM_Promotion::instance()->restore_by_ID( + $PRO_ID + ); } if ($success) { - $trash ? EE_Error::add_success(__('Promotion successfully trashed.', 'event_espresso')) : EE_Error::add_success(__('Promotion successfully restored.', 'event_espresso')); + $trash ? EE_Error::add_success(__('Promotion successfully trashed.', 'event_espresso')) + : EE_Error::add_success(__('Promotion successfully restored.', 'event_espresso')); } else { - $trash ? EE_Error::add_error(__('Promotion did not get trashed.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__) : EE_Error::add_error(__('Promotion did not get restored.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); + $trash + ? EE_Error::add_error( + __('Promotion did not get trashed.', 'event_espresso'), + __FILE__, + __FUNCTION__, + __LINE__ + ) + : EE_Error::add_error( + __('Promotion did not get restored.', 'event_espresso'), + __FILE__, + __FUNCTION__, + __LINE__ + ); } if ($redirect) { - $query_args = array( - 'action' => !empty($this->_req_data['update_promotion_nonce']) ? 'edit' : 'default', - 'PRO_ID' => $PRO_ID - ); + $query_args = [ + 'action' => ! empty($this->_req_data['update_promotion_nonce']) ? 'edit' : 'default', + 'PRO_ID' => $PRO_ID, + ]; $this->_redirect_after_action(null, '', '', $query_args, true); } return $success; @@ -777,64 +918,112 @@ protected function _trash_or_restore_promotion($trash = false, $PRO_ID = 0, $red // phpcs:disable WordPress.WP.I18n.MissingSingularPlaceholder + + /** * Trash or restore multiple promotions. Expecting an array of promotion ids in the request. * - * @since 1.0.0 - * * @param bool $trash if true then trash otherwise restore. * @return void + * @throws EE_Error + * @throws EE_Error + * @since 1.0.0 + * */ protected function _trash_or_restore_promotions($trash = false) { $success = 0; - $pro_ids = ! empty($this->_req_data['PRO_ID']) && is_array($this->_req_data['PRO_ID']) ? $this->_req_data['PRO_ID'] : array(); + $pro_ids = + ! empty($this->_req_data['PRO_ID']) && is_array($this->_req_data['PRO_ID']) ? $this->_req_data['PRO_ID'] + : []; if (! empty($pro_ids)) { foreach ($pro_ids as $pro_id) { if ($this->_trash_or_restore_promotion($trash, $pro_id, false)) { $success++; } else { - $trash ? EE_Error::add_error(sprintf(__('Promotion (%s) did not get trashed.', 'event_espresso'), $pro_id), __FILE__, __FUNCTION__, __LINE__) : EE_Error::add_error(sprintf(__('Promotion (%s) did not get restored.', 'event_espresso'), $pro_id), __FILE__, __FUNCTION__, __LINE__); + $trash + ? EE_Error::add_error( + sprintf(__('Promotion (%s) did not get trashed.', 'event_espresso'), $pro_id), + __FILE__, + __FUNCTION__, + __LINE__ + ) + : EE_Error::add_error( + sprintf(__('Promotion (%s) did not get restored.', 'event_espresso'), $pro_id), + __FILE__, + __FUNCTION__, + __LINE__ + ); } } } else { $trash - ? EE_Error::add_error(__('Unable to trash promotions because none were selected.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__) - : EE_Error::add_error(__('Unable to restore promotions because none were selected.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); + ? EE_Error::add_error( + __('Unable to trash promotions because none were selected.', 'event_espresso'), + __FILE__, + __FUNCTION__, + __LINE__ + ) + : EE_Error::add_error( + __('Unable to restore promotions because none were selected.', 'event_espresso'), + __FILE__, + __FUNCTION__, + __LINE__ + ); } if ($success > 0) { $trash - ? EE_Error::add_success(_n('1 promotion was successfully trashed', '%s promotions were successfully trashed', $success, 'event_espresso')) - : EE_Error::add_success(_n('1 promotion was successfully restored', '%s promotions were successfully restored', $success, 'event_espresso')); + ? EE_Error::add_success( + _n( + '1 promotion was successfully trashed', + '%s promotions were successfully trashed', + $success, + 'event_espresso' + ) + ) + : EE_Error::add_success( + _n( + '1 promotion was successfully restored', + '%s promotions were successfully restored', + $success, + 'event_espresso' + ) + ); } - $this->_redirect_after_action(null, '', '', array( 'action' => 'default' ), true); + $this->_redirect_after_action(null, '', '', ['action' => 'default'], true); } // phpcs:enable - - /** * Delete permanently a promotion. * - * @since 1.0.0 - * - * @param int $PRO_ID if given this is the id for the promotion to be permanently deleted. + * @param int $PRO_ID if given this is the id for the promotion to be permanently deleted. * @param bool $redirect if true then redirect, otherwise don't * @return bool value of $success; + * @since 1.0.0 + * */ protected function _delete_promotion($PRO_ID = 0, $redirect = true) { $success = true; - $PRO_ID = !empty($PRO_ID) ? $PRO_ID : 0; - $PRO_ID = empty($PRO_ID) && ! empty($this->_req_data['PRO_ID']) ? $this->_req_data['PRO_ID'] : $PRO_ID; + $PRO_ID = ! empty($PRO_ID) ? $PRO_ID : 0; + $PRO_ID = empty($PRO_ID) && ! empty($this->_req_data['PRO_ID']) ? $this->_req_data['PRO_ID'] : $PRO_ID; if (empty($PRO_ID)) { $success = false; - EE_Error::add_error(__('Unable to delete permanently the promotion because no promotion id is accessible.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); + EE_Error::add_error( + __( + 'Unable to delete permanently the promotion because no promotion id is accessible.', + 'event_espresso' + ), + __FILE__, + __FUNCTION__, + __LINE__ + ); } @@ -846,7 +1035,10 @@ protected function _delete_promotion($PRO_ID = 0, $redirect = true) $success = false; EE_Error::add_error( sprintf( - __('Unable to delete %s because it has been redeemed. For archival and relational purposes this data must be retained in the db.', 'event_espresso'), + __( + 'Unable to delete %s because it has been redeemed. For archival and relational purposes this data must be retained in the db.', + 'event_espresso' + ), $promotion->name() ) ); @@ -860,21 +1052,33 @@ protected function _delete_promotion($PRO_ID = 0, $redirect = true) $success = $promotion->delete_permanently(); } if ($success) { - EE_Error::add_success(sprintf(__('Promotion %s has been permanently deleted.', 'event_espresso'), $promotion->name())); + EE_Error::add_success( + sprintf(__('Promotion %s has been permanently deleted.', 'event_espresso'), $promotion->name()) + ); } else { - EE_Error::add_error(sprintf(__('Unable to permanently delete the %s promotion.', 'event_espresso'), $promotion->name()), __FILE__, __FUNCTION__, __LINE__); + EE_Error::add_error( + sprintf( + __('Unable to permanently delete the %s promotion.', 'event_espresso'), + $promotion->name() + ), + __FILE__, + __FUNCTION__, + __LINE__ + ); } } else { $success = false; - EE_Error::add_error(sprintf(__('There is no promotion in the db matching the id of %s.', 'event_espresso'), $PRO_ID)); + EE_Error::add_error( + sprintf(__('There is no promotion in the db matching the id of %s.', 'event_espresso'), $PRO_ID) + ); } } if ($redirect) { - $query_args = array( + $query_args = [ 'action' => ! empty($this->_req_data['update_promotion_nonce']) ? 'edit' : 'default', - 'PRO_ID' => $PRO_ID - ); + 'PRO_ID' => $PRO_ID, + ]; $this->_redirect_after_action(null, '', '', $query_args, true); } return $success; @@ -883,17 +1087,23 @@ protected function _delete_promotion($PRO_ID = 0, $redirect = true) // phpcs:disable WordPress.WP.I18n.MissingSingularPlaceholder + + /** * Delete permanently multiple promotions. The promotion IDs are expected to be in the request. * + * @return void + * @throws EE_Error + * @throws EE_Error * @since 1.0.0 * - * @return void */ protected function _delete_promotions() { $success = 0; - $pro_ids = ! empty($this->_req_data['PRO_ID']) && is_array($this->_req_data['PRO_ID']) ? $this->_req_data['PRO_ID'] : array(); + $pro_ids = + ! empty($this->_req_data['PRO_ID']) && is_array($this->_req_data['PRO_ID']) ? $this->_req_data['PRO_ID'] + : []; if (! empty($pro_ids)) { foreach ($pro_ids as $pro_id) { if ($this->_delete_promotion($pro_id, false)) { @@ -902,21 +1112,32 @@ protected function _delete_promotions() } } else { $success = false; - EE_Error::add_error(__('Unable to permanently delete any promotions because none were selected.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); + EE_Error::add_error( + __('Unable to permanently delete any promotions because none were selected.', 'event_espresso'), + __FILE__, + __FUNCTION__, + __LINE__ + ); } if ($success > 0) { - EE_Error::add_success(_n('1 promotion was successfully deleted.', '%s promotions were successfully deleted.', $success, 'event_espresso')); + EE_Error::add_success( + _n( + '1 promotion was successfully deleted.', + '%s promotions were successfully deleted.', + $success, + 'event_espresso' + ) + ); } - $this->_redirect_after_action(null, '', '', array( 'action' => 'default' ), true); + $this->_redirect_after_action(null, '', '', ['action' => 'default'], true); } // phpcs:enable - - /** * _get_config + * * @access protected * @return EE_Promotions_Config */ @@ -926,8 +1147,6 @@ protected function _get_config() } - - /** * promotions_settings * @@ -942,90 +1161,108 @@ protected function _promotions_settings() } - /** * _generate_promo_settings_form * * @access protected * @return EE_Form_Section_Proper + * @throws EE_Error + * @throws EE_Error */ protected function _generate_promo_settings_form() { $this->_config = $this->_get_config(); return new EE_Form_Section_Proper( - array( - 'name' => 'promotions_settings', - 'html_id' => 'promotions_settings', - 'html_class' => 'form-table', + [ + 'name' => 'promotions_settings', + 'html_id' => 'promotions_settings', + 'html_class' => 'form-table', 'layout_strategy' => new EE_Admin_Two_Column_Layout(), - 'subsections' => apply_filters( + 'subsections' => apply_filters( 'FHEE__Promotions_Admin_Page___generate_promo_settings_form__form_subsections', - array( - 'affects_tax' => new EE_Yes_No_Input( - array( - 'default' => $this->_config->affects_tax(), - 'html_label_text' => __('Promotions Affect Taxes', 'event_espresso'), - 'html_help_text' => sprintf( - __('If set to "Yes" then all promotions will be applied before taxes are calculated,%1$smeaning that the taxes will be applied to the discounted total.%1$s example: $10 total - $5 discount + 10%% tax = $5.50%1$sIf set to "No" then taxes will applied to transaction totals first, followed by promotions.%1$s example: $10 total + 10%% tax - $5 discount = $6.00', 'event_espresso'), + [ + 'affects_tax' => new EE_Yes_No_Input( + [ + 'default' => $this->_config->affects_tax(), + 'html_label_text' => __('Promotions Affect Taxes', 'event_espresso'), + 'html_help_text' => sprintf( + __( + 'If set to "Yes" then all promotions will be applied before taxes are calculated,%1$smeaning that the taxes will be applied to the discounted total.%1$s example: $10 total - $5 discount + 10%% tax = $5.50%1$sIf set to "No" then taxes will applied to transaction totals first, followed by promotions.%1$s example: $10 total + 10%% tax - $5 discount = $6.00', + 'event_espresso' + ), '
' ), - ) + ] ), - 'banner_template' => new EE_Select_Input( - array( - 'promo-banner-ribbon.template.php' => __('Ribbon Banner', 'event_espresso'), + 'banner_template' => new EE_Select_Input( + [ + 'promo-banner-ribbon.template.php' => __('Ribbon Banner', 'event_espresso'), 'promo-banner-plain-text.template.php' => __('Plain Text', 'event_espresso'), - 'none' => __('Do Not Display Promotions', 'event_espresso'), - ), - array( - 'default' => isset($this->_config->banner_template) ? $this->_config->banner_template : false, - 'html_label_text' => __('Promotion Banners', 'event_espresso'), - 'html_help_text' => sprintf( - __('How Non-Code Promotions* are advertised and displayed above the Ticket Selector.%1$s* "Non-Code Promotions" are promotions that do not use a text code, and are applied automatically when all of the promotion\'s qualifying requirements are met (ie: start date, selected events, etc).%2$s', 'event_espresso'), + 'none' => __( + 'Do Not Display Promotions', + 'event_espresso' + ), + ], + [ + 'default' => isset($this->_config->banner_template) + ? $this->_config->banner_template + : false, + 'html_label_text' => __('Promotion Banners', 'event_espresso'), + 'html_help_text' => sprintf( + __( + 'How Non-Code Promotions* are advertised and displayed above the Ticket Selector.%1$s* "Non-Code Promotions" are promotions that do not use a text code, and are applied automatically when all of the promotion\'s qualifying requirements are met (ie: start date, selected events, etc).%2$s', + 'event_espresso' + ), '
', '' ), - ) + ] ), - 'ribbon_banner_color' => new EE_Select_Input( - array( - 'lite-blue' => __('lite-blue', 'event_espresso'), - 'blue' => __('blue', 'event_espresso'), - 'green' => __('green', 'event_espresso'), - 'pink' => __('pink', 'event_espresso'), - 'red' => __('red', 'event_espresso'), - ), - array( - 'default' => isset($this->_config->ribbon_banner_color) ? $this->_config->ribbon_banner_color : false, - 'html_label_text' => __('Ribbon Banner Color', 'event_espresso'), - 'html_help_text' => __('If "Ribbon Banner" is selected above, then this determines the color of the ribbon banner.', 'event_espresso'), - ) + 'ribbon_banner_color' => new EE_Select_Input( + [ + 'lite-blue' => __('lite-blue', 'event_espresso'), + 'blue' => __('blue', 'event_espresso'), + 'green' => __('green', 'event_espresso'), + 'pink' => __('pink', 'event_espresso'), + 'red' => __('red', 'event_espresso'), + ], + [ + 'default' => isset($this->_config->ribbon_banner_color) + ? $this->_config->ribbon_banner_color : false, + 'html_label_text' => __('Ribbon Banner Color', 'event_espresso'), + 'html_help_text' => __( + 'If "Ribbon Banner" is selected above, then this determines the color of the ribbon banner.', + 'event_espresso' + ), + ] ), - 'reset_promotions' => new EE_Yes_No_Input( - array( - 'default' => 0, - 'html_label_text' => __('Reset Promotions Settings?', 'event_espresso'), - 'html_help_text' => __('Set to "Yes" and then click "Save" to confirm reset all basic and advanced Event Espresso Promotions settings to their plugin defaults.', 'event_espresso'), - ) + 'reset_promotions' => new EE_Yes_No_Input( + [ + 'default' => 0, + 'html_label_text' => __('Reset Promotions Settings?', 'event_espresso'), + 'html_help_text' => __( + 'Set to "Yes" and then click "Save" to confirm reset all basic and advanced Event Espresso Promotions settings to their plugin defaults.', + 'event_espresso' + ), + ] ), - ) - ) - ) + ] + ), + ] ); } - /** * _update_settings * * @access protected - * @throws \EE_Error + * @throws EE_Error */ protected function _update_settings() { - $count = 0; - $this->_config = $this->_get_config(); + $count = 0; + $this->_config = $this->_get_config(); $promo_settings_form = $this->_generate_promo_settings_form(); if ($promo_settings_form->was_submitted()) { // capture form data @@ -1043,9 +1280,10 @@ protected function _update_settings() if (method_exists($this->_config, $setter)) { $this->_config->$setter($value); $count++; - } elseif (property_exists($this->_config, $property) - && $this->_config->{$property} - !== $value + } elseif ( + property_exists($this->_config, $property) + && $this->_config->{$property} + !== $value ) { $this->_config->$property = $value; $count++; @@ -1055,18 +1293,22 @@ protected function _update_settings() EE_Registry::instance()->CFG->update_config('addons', 'promotions', $this->_config); } } - $this->_redirect_after_action($count, 'Settings', 'updated', array( 'action' => 'promotions_settings' )); + $this->_redirect_after_action($count, 'Settings', 'updated', ['action' => 'promotions_settings']); } - /** * _usage + * * @access protected */ protected function _usage() { - $this->_template_args['admin_page_content'] = EEH_Template::display_template(EE_PROMOTIONS_ADMIN_TEMPLATE_PATH . 'promotions_usage_info.template.php', array(), true); + $this->_template_args['admin_page_content'] = EEH_Template::display_template( + EE_PROMOTIONS_ADMIN_TEMPLATE_PATH . 'promotions_usage_info.template.php', + [], + true + ); $this->display_admin_page_with_no_sidebar(); } } diff --git a/admin/promotions/Promotions_Admin_Page_Init.core.php b/admin/promotions/Promotions_Admin_Page_Init.core.php index 90328c4..eae233a 100644 --- a/admin/promotions/Promotions_Admin_Page_Init.core.php +++ b/admin/promotions/Promotions_Admin_Page_Init.core.php @@ -27,7 +27,7 @@ public function __construct() do_action('AHEE_log', __FILE__, __FUNCTION__, ''); define('PROMOTIONS_PG_SLUG', 'espresso_promotions'); - define('PROMOTIONS_LABEL', __('Promotions', 'event_espresso')); + define('PROMOTIONS_LABEL', esc_html__('Promotions', 'event_espresso')); define('EE_PROMOTIONS_ADMIN_URL', admin_url('admin.php?page=' . PROMOTIONS_PG_SLUG)); define('EE_PROMOTIONS_ADMIN_ASSETS_PATH', EE_PROMOTIONS_ADMIN . 'assets' . DS); define('EE_PROMOTIONS_ADMIN_ASSETS_URL', EE_PROMOTIONS_URL . 'admin/promotions/assets/'); diff --git a/admin/promotions/assets/espresso_promotions_admin.js b/admin/promotions/assets/espresso_promotions_admin.js index 1b3e01b..ea849f3 100644 --- a/admin/promotions/assets/espresso_promotions_admin.js +++ b/admin/promotions/assets/espresso_promotions_admin.js @@ -1,9 +1,13 @@ jQuery(document).ready(function($){ + const $postBody = $('#post-body'); + const $promosAppliedToMbox = $('#promotions-applied-to-mbox'); + const $promoDetailsForm = $('#promotion-details-form'); + /** * Object that has all the helper methods for the promotions admin requirements. */ - var eePromotionsHelper = { + const eePromotionsHelper = { /** * cache for scope slug current lin use. @@ -35,10 +39,10 @@ jQuery(document).ready(function($){ * * @param {string} codefield The class or id selector for the field referencing the * code. - * @return {eePromotionsHelper} + * @return {eePromotionsHelper|void} */ generate_code: function( codefield ) { - var code = ''; + let code = ''; //make sure we have a selector if ( typeof(codefield) === 'undefined' ) { console.log( eei18n.codefieldEmptyError ); @@ -46,18 +50,18 @@ jQuery(document).ready(function($){ } //make sure selector exists - var field = $(codefield); + const field = $(codefield); if ( field.length === 0 ) { console.log( eei18n.codefieldInvalidError ); return; } //made it here? K let's generate the code if we have a prefix we'll use it. - var prefix = $('#PRO_code_prefix' ); + const prefix = $('#PRO_code_prefix' ); if ( prefix.val() === '' && field.val().length > 0 ) { prefix.val( field.val() + '_' ); } - code = prefix.val() + this.uniqid(); + code = prefix.val() + this.uniqID(); field.val(code); return this; }, @@ -69,9 +73,12 @@ jQuery(document).ready(function($){ * * @return {string} */ - uniqid: function() { - var ts=String(new Date().getTime()), i = 0, out = '',num=0; - var host = window.location.host; + uniqID: function() { + const host = window.location.host; + let i = 0; + let num = 0; + let out = ''; + let ts=String(new Date().getTime()); //convert host to num. for ( c=0; c < host.length; c++ ) { num += host.charCodeAt(c); @@ -90,32 +97,33 @@ jQuery(document).ready(function($){ * * @param {string} selected the checkbox toggled * - * @return {eePromotionsHelper} + * @return {eePromotionsHelper|void} */ scopeItemToggle: function (selected) { if ( typeof(selected) === 'undefined' ) { console.log(eei18n.toggledScopeItemMissingParam); - return false; + return; } - var checkeditem = $(selected), curItems, itemsInput; - var currentcount = $('.ee-promotions-selected-count','.ee-promotions-selected-count-container').text(); + let curItems; + let itemsInput; + let currentCount = $('.ee-promotions-selected-count','.ee-promotions-selected-count-container').text(); //selected or deselected? - var isSelected = $(selected).is(':checked'); + const isSelected = $(selected).is(':checked'); itemsInput = $('#ee-selected-items-' + this.getScope() ); curItems = itemsInput.val().split(','); if ( isSelected ) { //adding item to hidden elements curItems.push($(selected).val()); - currentcount = parseInt( currentcount, 10) + 1; + currentCount = parseInt( currentCount, 10) + 1; } else { curItems = $().removeFromArray(curItems, $(selected).val()); - currentcount = parseInt( currentcount, 10 ) - 1; + currentCount = parseInt( currentCount, 10 ) - 1; } itemsInput.val( curItems.join(',').replace(/^,|,$/,'') ); - $('.ee-promotions-selected-count', '.ee-promotions-selected-count-container').text(currentcount); + $('.ee-promotions-selected-count', '.ee-promotions-selected-count-container').text(currentCount); return this; }, @@ -128,13 +136,14 @@ jQuery(document).ready(function($){ * @return {eePromotionsHelper} */ toggleSort: function() { - var sortClass, sortOrder, classReplace, current_sort = $('#ee-promotion-items-sort-order').text(); - sortOrder = current_sort == 'ASC' ? 'DESC' : 'ASC'; - sortClass = current_sort == 'ASC' ? 'dashicons-arrow-down' : 'dashicons-arrow-up'; - classReplace = current_sort == 'ASC' ? 'dashicons-arrow-up' : 'dashicons-arrow-down'; + const $promoSortOrder = $('#ee-promotion-items-sort-order'); + const current_sort = $promoSortOrder.text(); + const sortOrder = current_sort === 'ASC' ? 'DESC' : 'ASC'; + const sortClass = current_sort === 'ASC' ? 'dashicons-arrow-down' : 'dashicons-arrow-up'; + let classReplace = current_sort === 'ASC' ? 'dashicons-arrow-up' : 'dashicons-arrow-down'; //modify sort. - $('#ee-promotion-items-sort-order').text(sortOrder); + $promoSortOrder.text(sortOrder); classReplace = $('.dashicons', '.ee-sort-container').attr('class').replace(classReplace, sortClass); $('.dashicons', '.ee-sort-container').attr('class', classReplace); return this; @@ -151,7 +160,7 @@ jQuery(document).ready(function($){ * @return {eePromotionsHelper} */ getScopeSelectionItems: function(page) { - var data={}; + const data={}; //make sure the select all box is unchecked $('.ee-select-all-trigger', '.ee-promotions-applies-to-selector').prop('checked', false); @@ -161,7 +170,7 @@ jQuery(document).ready(function($){ }); $('input', '.ee-promotions-applies-to-filters').each( function(i) { //if item is a checkbox and its not checked, then don't include. - if ( $(this).attr('type') == 'checkbox' && ! $(this).prop('checked') ) { + if ( $(this).attr('type') === 'checkbox' && ! $(this).prop('checked') ) { return; } data[$(this).attr('name')] = $(this).val(); @@ -185,10 +194,9 @@ jQuery(document).ready(function($){ //alright all the data is setup now let's set what we want to do on ajax success. $(document).ajaxSuccess( function(event, xhr, ajaxoptions ) { //we can get the response from xhr - var ct = xhr.getResponseHeader( "content-type" ) || ""; + const ct = xhr.getResponseHeader( "content-type" ) || ""; if ( ct.indexOf('json') > -1 ) { - var resp = xhr.responseText; - resp = $.parseJSON(resp); + const resp = $.parseJSON(xhr.responseText); //let's replace the current items in the selected items window. $('.ee-promotions-applies-to-items-container', '.ee-promotions-applies-to-selector').html(resp.items_content); //update the current page @@ -238,7 +246,7 @@ jQuery(document).ready(function($){ /** * trigger for resetting coupon code prefix. */ - $('#promotion-details-form').on('click', '#reset-promo-code-prefix', function(e) { + $promoDetailsForm.on('click', '#reset-promo-code-prefix', function(e) { e.preventDefault(); e.stopPropagation(); $('#PRO_code_prefix' ).val(''); @@ -249,7 +257,7 @@ jQuery(document).ready(function($){ /** * trigger for generating coupon code. */ - $('#promotion-details-form').on('click', '#generate-promo-code', function(e) { + $promoDetailsForm.on('click', '#generate-promo-code', function(e) { e.preventDefault(); e.stopPropagation(); eePromotionsHelper.generate_code('#PRO_code'); @@ -269,15 +277,15 @@ jQuery(document).ready(function($){ /** * Date and time picker trigger */ - $('#post-body').on('focusin', '.ee-datepicker', function(e) { + $postBody.on('focusin', '.ee-datepicker', function(e) { e.preventDefault(); - var data= $(this).data(); - var container = data.container == 'main' ? '#promotion-details-mbox' : '#promotions-applied-to-mbox'; - var start = data.context == 'start' ? $(this, container) : $('[data-context="start"]', container); - var end = data.context == 'end' ? $(this, container) : $('[data-context="end"]', container ); - var next = $(data.nextField, 'container'); - var doingstart = data.context == 'start' ? true : false; - dttPickerHelper.resetpicker().setDefaultDateRange('months', 1).picker(start, end, next, doingstart); + const data= $(this).data(); + // const container = data.container === 'main' ? '#promotion-details-mbox' : '#promotions-applied-to-mbox'; + const start = data.context === 'start' ? $(this, data.container) : $('[data-context="start"]', data.container); + const end = data.context === 'end' ? $(this, data.container) : $('[data-context="end"]', data.container ); + const next = $(data.nextField, 'container'); + const doingStart = data.context === 'start'; + dttPickerHelper.resetpicker().setDefaultDateRange('months', 1).picker(start, end, next, doingStart); }); @@ -285,7 +293,7 @@ jQuery(document).ready(function($){ * trigger for toggling the selection of ALL promotion applies to items. */ $('.ee-promotions-applies-to-selector').on('click', '.ee-select-all-trigger', function(e) { - selecting = $(this).prop('checked'); + const selecting = $(this).prop('checked'); $(':checkbox', '.ee-promotions-applies-to-items-container').each( function(i) { if ( $(this).prop('checked') === false && selecting ) $(this).trigger('click'); @@ -311,7 +319,7 @@ jQuery(document).ready(function($){ /** * trigger for display only selected items filter. */ - $('#promotions-applied-to-mbox').on('click', '.ee-display-selected-only-trigger', function(e) { + $promosAppliedToMbox.on('click', '.ee-display-selected-only-trigger', function(e) { e.stopPropagation(); eePromotionsHelper.getScopeSelectionItems(); }); @@ -321,7 +329,7 @@ jQuery(document).ready(function($){ /** * trigger for sorts */ - $('#promotions-applied-to-mbox').on('click', '.ee-sort-trigger', function(e) { + $promosAppliedToMbox.on('click', '.ee-sort-trigger', function(e) { e.preventDefault(); e.stopPropagation(); eePromotionsHelper.toggleSort().getScopeSelectionItems(); @@ -331,11 +339,11 @@ jQuery(document).ready(function($){ /** * trigger for paging! */ - $('#promotions-applied-to-mbox').on('click', '.pagination-links>a', function(e) { + $promosAppliedToMbox.on('click', '.pagination-links>a', function(e) { e.preventDefault(); e.stopPropagation(); - var data = parseUri( $(this).attr('href') ); - var paged = typeof( data.queryKey.paged ) !== 'undefined' ? data.queryKey.paged : 1; + const data = parseUri( $(this).attr('href') ); + const paged = typeof( data.queryKey.paged ) !== 'undefined' ? data.queryKey.paged : 1; eePromotionsHelper.getScopeSelectionItems(paged); }); @@ -343,11 +351,11 @@ jQuery(document).ready(function($){ /** * capture enter keypress in paging input */ - $('#promotions-applied-to-mbox').on('keypress', '.current-page', function(e) { - if ( e.which == 13 ) { + $promosAppliedToMbox.on('keypress', '.current-page', function(e) { + if ( e.which === 13 ) { e.preventDefault(); e.stopPropagation(); - var paged = $(this).val(); + const paged = $(this).val(); eePromotionsHelper.getScopeSelectionItems(paged); } }); @@ -357,8 +365,8 @@ jQuery(document).ready(function($){ * capture enter keypress in any of the scope filter inputs * */ - $('#post-body').on('keypress', '.ee-promotions-applies-to-filters>input', function(e){ - if ( e.which == 13 ) { + $postBody.on('keypress', '.ee-promotions-applies-to-filters>input', function(e){ + if ( e.which === 13 ) { e.preventDefault(); e.stopPropagation(); eePromotionsHelper.getScopeSelectionItems(); @@ -369,25 +377,32 @@ jQuery(document).ready(function($){ /** * clear calendar field */ - $('#post-body').on('click', '.clear-dtt', function(e) { + $postBody.on('click', '.clear-dtt', function(e) { e.preventDefault(); e.stopPropagation(); - var data = $(this).data(); + const data = $(this).data(); $(data.field).val(''); }); - $('#post-body').on( 'click', '.ee-clear-field', function(e) { + $postBody.on( 'click', '.ee-clear-field', function(e) { e.preventDefault(); e.stopPropagation(); - var data = $(this).data(); + const data = $(this).data(); $(data.clearfield).val(''); }); - $('#post-body').on( 'click', '.ee-toggle-filters', function(e) { + $postBody.on( 'click', '.ee-toggle-filters', function(e) { e.preventDefault(); e.stopPropagation(); - var data = $(this).data(); + const data = $(this).data(); $(data.filterContainer).slideToggle(); }); + $postBody.on( 'click', '.ee-toggle-datepicker', function(e) { + e.preventDefault(); + e.stopPropagation(); + const data = $(this).data(); + $(data.target).trigger('click').focus(); + }); + }); diff --git a/admin/promotions/assets/promotions-details.css b/admin/promotions/assets/promotions-details.css index f2cf7f5..eb572bf 100644 --- a/admin/promotions/assets/promotions-details.css +++ b/admin/promotions/assets/promotions-details.css @@ -2,13 +2,9 @@ width: 100px; } -#promotions-applied-to-mbox input[type='checkbox'] { - margin-top: 1px; -} - #promotion-details-form .dashicons-tagcloud { font-size: 20px; - top: 0px; + top: 0; margin-right: 3px; } @@ -17,37 +13,121 @@ margin-right: 15px; } +#insert_promotion_event_form .ee-input-sidebar__wrapper, +#update_promotion_event_form .ee-input-sidebar__wrapper, +#insert_promotion_event_form .ee-input-sidebar, +#update_promotion_event_form .ee-input-sidebar { + align-items: center; + display: flex; + height: calc(var(--ee-button-height) + 1px); + margin-block: 0.25rem; +} + +#insert_promotion_event_form .ee-input-sidebar.ee-input-sidebar--after input, +#update_promotion_event_form .ee-input-sidebar.ee-input-sidebar--after input { + border-inline-end: none; + border-start-end-radius: 0; + border-end-end-radius: 0; + margin-inline-end: 0 !important; + height: 100% !important; + top: unset; +} + +#insert_promotion_event_form .ee-input-sidebar.ee-input-sidebar--after button, +#update_promotion_event_form .ee-input-sidebar.ee-input-sidebar--after button { + background-color: var(--ee-color-white); + border-start-start-radius: 0; + border-end-start-radius: 0; + border-color: var(--ee-btn-secondary-hover); + color: var(--ee-font-color-light); + margin-inline-start: 0 !important; + height: 100% !important; + padding-block: 0; + box-shadow: none; +} +#insert_promotion_event_form .ee-input-sidebar.ee-input-sidebar--after button:hover, +#update_promotion_event_form .ee-input-sidebar.ee-input-sidebar--after button:hover { + color: var(--ee-font-color); +} + +#insert_promotion_event_form .ee-input-sidebar:focus-within input, +#update_promotion_event_form .ee-input-sidebar:focus-within input, +#insert_promotion_event_form .ee-input-sidebar:focus-within button, +#update_promotion_event_form .ee-input-sidebar:focus-within button { + border-color: var(--ee-help-attention-hover); +} + + +.ee-sort-container { + align-items: center; + display: flex; + justify-content: space-between; + margin-block-start: 1rem; +} +.ee-sort-container h4 { + color: var(--ee-font-color-light); + font-size: 1.25rem; + font-weight: 800; + margin: 0; + margin-inline-start: 0.5rem; +} + +.espresso-admin .postbox .inside .ee-display-selected p { + margin-block-end: .5rem; +} + +.ee-display-selected-trigger-label { + text-transform: lowercase; +} + .ee-promotions-selected-count { margin: 1em 0; } .ee-promotions-applies-to-filters { - background-color: #ededed; - padding: 10px; - padding-top: 1px; + background-color: var(--ee-status-color-pale-blue); + padding-block: 1rem; + padding-inline: 1.5rem; + width: calc(100% - 1.5rem); + margin-inline-start: -0.75rem; + margin-block-start: 1rem; +} + +.ee-promotions-applies-to-filters .ee-promotions-applies-to-filters__heading { + margin: 0; } +.espresso-admin .postbox .inside .ee-promotions-filter-settings > p { + margin-block: 1rem; +} + +.espresso-admin .ee-promotions-filter-settings > div { + margin-block: 1rem; +} +.espresso-admin .ee-promotions-filter-settings > div:last-of-type { + margin-block-start: 2rem; +} + + .ee-promotions-applies-to-filters select { width: 100%; } -.ee-promotions-filter-lbl { - margin-top: 1em; - font-size: .8em; - line-height : .8em; - letter-spacing: 1px; - color: #999; +.espresso-admin .ee-promotions-filter-settings label.ee-promotions-filter-lbl:not(.ee-input-label):not(.screen-reader-text) { + margin-block: 0; } - .ee-promotions-filter-lbl.single-line-filter-label { display: block; margin-top: 10px; } -.ee-promotions-applies-to-filters .promotions-date-filter, -.ee-date-column .ee-datepicker { +.ee-promotions-applies-to-filters .promotions-date-filter { + padding-right: 2rem; position: relative; - padding-right: 25px; +} + +.espresso-admin .ee-date-column input[type="text"].ee-datepicker { + padding-inline-end: 2.5rem !important; } .ee-promotions-applies-to-filters .promotions-date-filter { @@ -62,65 +142,66 @@ margin-top: 8px; } -.ee-promotions-applies-to-filters .dashicons { - display: inline-block; - float: right; -} - -.ee-promotions-applies-to-filters .dashicons-calendar:before, .ee-promotions-applies-to-filters .dashicons-editor-removeformatting:before { - position: absolute; - font-size: 18px; - top: -22px; - left: -35px; -} - -.ee-promotions-applies-to-filters .dashicons-editor-removeformatting:before { - left: -15px; +#promotion-details-form .ee-datepicker + .dashicons-calendar { cursor: pointer; + inset-inline-start: -2rem; + position: relative; } -.ee-promotions-applies-to-filters .dashicons-admin-settings:before { - font-size: 1.5em; +.ee-promotions-applies-to-filters .dashicons-admin-settings { + color: var(--ee-font-color-light); cursor: pointer; + font-size: 2rem; } -.ee-date-column .dashicons-calendar:before { - position:absolute; - font-size: 18px; - top: -10px; - left: -40px; +.ee-display-selected, +.promotion-applies-to-items-ul { + display: flex; + flex-direction: column; } -.ee-date-column .dashicons-editor-removeformatting:before { - position:absolute; - font-size: 18px; - top: -10px; - left: -10px; +.espresso-admin .promotion-applies-to-items-ul label.pro-applied-to-selector-checkbox-label { + align-items: flex-start; + display: inline-flex; + flex-wrap: nowrap; + line-height: 1; + margin-inline-start: 0.25rem; } -.ee-promotions-applies-to-selector { - margin-top: 15px; +.espresso-admin .promotion-applies-to-items-ul .dashicons, +.espresso-admin .promotion-applies-to-items-ul input[type='checkbox'] { + margin-inline-end: 0.5rem; +} +.espresso-admin .promotion-applies-to-items-ul input[type='checkbox'] { + margin-block-start: 1px; } -.ee-sort-container, .ee-promotions-applies-to-paging { - display: inline-block; - float: right; +.espresso-admin input[type="checkbox"]:checked::before { + background-size: 0.8125rem; + background-position: 0.34375rem 0.375rem; } -.ee-promotions-applies-to-paging { - margin-bottom: 10px; +.espresso-admin .promotion-applies-to-items-ul .dashicons { + color: var(--ee-font-color-light); } -.ee-promotions-applies-to-paging .tablenav .tablenav-pages a { - font-size: 14px; - padding: 0 7px 2px; + +.ee-promotions-applies-to-selector { + margin-block: 2rem; } -.ee-promotions-applies-to-paging .tablenav .tablenav-pages .current-page { - font-size: 12px; - padding: 1px 2px; + + +.ee-promotions-applies-to-paging .pagination-links { + width: 100%; } .ee-promotions-applies-to-paging .tablenav .tablenav-pages { - font-size: 12px; - line-height: 24px; + margin-inline: 0; + padding-inline: 0; +} +.ee-promotions-applies-to-paging .tablenav .button.button--secondary { + --ee-button-height: 2.25rem; + padding: 0 !important; + padding-block: 0 !important; + padding-inline: 0 !important; } .ee-sort-container .dashicons:before { @@ -128,12 +209,13 @@ } .ee-promotions-applies-to-items-container { - margin-top: 5px; - border: 1px solid grey; - padding: 1px 10px; - min-height: 180px; - height:auto; - max-height: 640px; + border-block-start: 2px solid var(--ee-border-color); + height: auto; + min-height: 5rem; + max-height: 40rem; + margin-top: .25rem; + padding-block-start: .5rem; + overflow-y: scroll; } .ee-promotions-applies-to-filters .spinner { @@ -185,24 +267,27 @@ .wp-list-table.promotion .column-valid_from, .wp-list-table.promotion .column-valid_until { width: 9.5%; - text-align: right; } -.wp-list-table.promotion .column-amount { +.wp-list-table.promotion th.column-amount { + text-align: center; width: 6%; +} + +.wp-list-table.promotion td.column-amount { text-align: right; - line-height: 1em; + /*line-height: 1em;*/ } .wp-list-table.promotion .column-redeemed { - width: 8%; text-align: center; + width: 8%; } .wp-list-table.promotion .column-actions { width: 6%; - text-align: right; - padding-right: 10px; + /*text-align: right;*/ + /*padding-right: 10px;*/ } .wp-list-table.promotion .column-actions .dashicons { margin-right:0; @@ -213,7 +298,7 @@ .wp-list-table .ee-lock-icon:before { margin-bottom: 5px; - margin-top: 0px; + margin-top: 0; } @@ -246,25 +331,25 @@ /*upcoming*/ .pro-status-PRU, .pro-status-PRU .check-column{ - border-left-color: #00B1CA; + border-left-color: var(--ee-status-color-blue); } /*active*/ .pro-status-PRA, .pro-status-PRA .check-column{ - border-left-color: #70CC50; + border-left-color: var(--ee-status-color-green); } /*expired*/ .pro-status-PRX, .pro-status-PRX .check-column{ - border-left-color: #AC9D9C; + border-left-color: var(--ee-status-color-grey); } /*unavailable*/ .pro-status-PRN, .pro-status-PRN .check-column{ - border-left-color: #E44064; + border-left-color: var(--ee-status-color-red); } .widefat td.column-pro_status, .widefat th.column-pro_status { @@ -274,37 +359,49 @@ } .ee-status-legend-PRU { - background-color: #00B1CA; + background-color: var(--ee-status-color-blue); } .ee-status-legend-PRA { - background-color: #70CC50; + background-color: var(--ee-status-color-green); } .ee-status-legend-PRX { - background-color: #AC9D9C; + background-color: var(--ee-status-color-grey); } .ee-status-legend-PRN { - background-color: #E44064; + background-color: var(--ee-status-color-red); } /** count bubble **/ .promotion-count-bubble { - background-color: #555555; + background-color: var(--ee-status-color-blue); display: inline-block; - max-width: 40px; - min-width: 15px; - max-height: 15px; - margin-left: 1em; - padding: 2px; - line-height: 15px; + max-width: 4rem; + min-width: 1rem; + max-height: 1rem; + margin-inline-start: 1rem; + padding: .25rem; + line-height: 1rem; color: #fff; - font-size: 10px; + font-size: .9rem; text-align: center; - -webkit-border-radius: 8px; - -moz-border-radius: 8px; - border-radius: 15px; + border-radius: 1rem; +} + +.ee-promotions-selected-event { + font-size: 1.1rem; + margin-inline-start: .75rem; } #reset-promo-code-prefix { margin: 0 1em; +} + + +.espresso-admin .ui-datepicker { + border: 2px solid var(--ee-help-attention-hover); + border-radius: 0.25rem; + box-shadow: 2px 24px 12px -4px hsl(0deg 0% 0% / 50%), 0 0 32px 8px hsl(0deg 0% 0% / 20%); + padding: 1rem; + z-index: 9999 !important; } \ No newline at end of file diff --git a/admin/promotions/promotions_help.php b/admin/promotions/promotions_help.php index 7754507..c986ae8 100644 --- a/admin/promotions/promotions_help.php +++ b/admin/promotions/promotions_help.php @@ -7,13 +7,13 @@

- +

- +

- +

@@ -21,7 +25,12 @@ @@ -29,13 +38,24 @@ @@ -53,7 +73,12 @@ @@ -63,19 +88,38 @@ @@ -84,7 +128,12 @@ @@ -92,7 +141,12 @@ @@ -101,8 +155,18 @@ @@ -110,7 +174,7 @@ @@ -118,8 +182,7 @@ @@ -127,8 +190,16 @@ @@ -136,8 +207,16 @@ @@ -145,8 +224,16 @@
- +
- - - - + +

- - + + + +

- +
-

+

+ +

redeemed() > 0) : ?> -

+

+ + + +

- + -

+

+ +

-

+

+ +

- +

- -

+ +

+ +

- + getHtml(); ?>
- - + getHtml(); ?>
- -

+ +

+ +

- -

+ +

+ +

- -

+ +

+ +

diff --git a/core/data_migration_scripts/EE_DMS_Promotions_1_0_0.dms.php b/core/data_migration_scripts/EE_DMS_Promotions_1_0_0.dms.php index cf271b9..95ef973 100644 --- a/core/data_migration_scripts/EE_DMS_Promotions_1_0_0.dms.php +++ b/core/data_migration_scripts/EE_DMS_Promotions_1_0_0.dms.php @@ -17,7 +17,7 @@ class EE_DMS_Promotions_1_0_0 extends EE_Data_Migration_Script_Base public function __construct() { - $this->_pretty_name = __('Create Promotions Addon table', 'event_espresso'); + $this->_pretty_name = esc_html__('Create Promotions Addon table', 'event_espresso'); $this->_migration_stages = array(); parent::__construct(); } diff --git a/core/db_classes/EE_Promotion.class.php b/core/db_classes/EE_Promotion.class.php index c44b092..3f0c519 100644 --- a/core/db_classes/EE_Promotion.class.php +++ b/core/db_classes/EE_Promotion.class.php @@ -526,7 +526,7 @@ public function promotion_date_range() } elseif ($start_date instanceof DateTime && $end_date instanceof DateTime) { return sprintf(_x('%s - %s', 'First value is start date and second value is end date in a date range.', 'event_espresso'), $this->get_i18n_datetime('PRO_start'), $this->get_i18n_datetime('PRO_end')); } else { - return __('Ongoing Promotion', 'event_espresso'); + return esc_html__('Ongoing Promotion', 'event_espresso'); } } diff --git a/core/db_models/EEM_Promotion.model.php b/core/db_models/EEM_Promotion.model.php index 6328559..35e8581 100644 --- a/core/db_models/EEM_Promotion.model.php +++ b/core/db_models/EEM_Promotion.model.php @@ -22,8 +22,8 @@ class EEM_Promotion extends EEM_Soft_Delete_Base protected function __construct() { - $this->singular_item = __('Promotion', 'event_espresso'); - $this->plural_item = __('Promotions', 'event_espresso'); + $this->singular_item = esc_html__('Promotion', 'event_espresso'); + $this->plural_item = esc_html__('Promotions', 'event_espresso'); $this->_tables = array( 'Promotion' => new EE_Primary_Table('esp_promotion', 'PRO_ID') @@ -31,25 +31,25 @@ protected function __construct() $this->_fields = array( 'Promotion' => array( - 'PRO_ID' => new EE_Primary_Key_Int_Field('PRO_ID', __('ID', 'event_espresso')), - 'PRC_ID' => new EE_Foreign_Key_Int_Field('PRC_ID', __("Price ID", "event_espresso"), false, 0, 'Price'), - 'PRO_scope' => new EE_Plain_Text_Field('PRO_scope', __("Scope", "event_espresso"), false, ''), - 'PRO_start' => new EE_Datetime_Field('PRO_start', __("Start Date/Time", "event_espresso"), true, null), - 'PRO_end' => new EE_Datetime_Field('PRO_end', __("End Date/Time", "event_espresso"), true, null), - 'PRO_code' => new EE_Plain_Text_Field('PRO_code', __("Code", "event_espresso"), true, ''), - 'PRO_uses' => new EE_Integer_Field('PRO_uses', __("Times this can be used in a given scope", "event_espresso"), false, EE_INF_IN_DB), - 'PRO_global' => new EE_Boolean_Field('PRO_global', __("Applies to ALL Scope items", "event_espresso"), false, false), - 'PRO_global_uses' => new EE_Integer_Field('PRO_global_uses', __("Times it can be used in all scopes", "event_espresso"), false, EE_INF_IN_DB), + 'PRO_ID' => new EE_Primary_Key_Int_Field('PRO_ID', esc_html__('ID', 'event_espresso')), + 'PRC_ID' => new EE_Foreign_Key_Int_Field('PRC_ID', esc_html__("Price ID", "event_espresso"), false, 0, 'Price'), + 'PRO_scope' => new EE_Plain_Text_Field('PRO_scope', esc_html__("Scope", "event_espresso"), false, ''), + 'PRO_start' => new EE_Datetime_Field('PRO_start', esc_html__("Start Date/Time", "event_espresso"), true, null), + 'PRO_end' => new EE_Datetime_Field('PRO_end', esc_html__("End Date/Time", "event_espresso"), true, null), + 'PRO_code' => new EE_Plain_Text_Field('PRO_code', esc_html__("Code", "event_espresso"), true, ''), + 'PRO_uses' => new EE_Integer_Field('PRO_uses', esc_html__("Times this can be used in a given scope", "event_espresso"), false, EE_INF_IN_DB), + 'PRO_global' => new EE_Boolean_Field('PRO_global', esc_html__("Applies to ALL Scope items", "event_espresso"), false, false), + 'PRO_global_uses' => new EE_Integer_Field('PRO_global_uses', esc_html__("Times it can be used in all scopes", "event_espresso"), false, EE_INF_IN_DB), 'PRO_exclusive' => new EE_Boolean_Field( 'PRO_exclusive', - __("Exclusive? (ie, can't be used with other promotions)", "event_espresso"), + esc_html__("Exclusive? (ie, can't be used with other promotions)", "event_espresso"), false, apply_filters('FHEE__EEM_Promotion__promotions_exclusive_default', true) ), - 'PRO_accept_msg' => new EE_Simple_HTML_Field('PRO_accept_msg', __("Acceptance Message", "event_espresso"), false, __("Accepted", "event_espresso")), - 'PRO_decline_msg' => new EE_Simple_HTML_Field('PRO_decline_msg', __("Declined Message", "event_espresso"), false, __("Declined", "event_espresso")), - 'PRO_default' => new EE_Boolean_Field('PRO_default', __("Usable by default on all new items within promotion's scope", "event_espresso"), false, false), - 'PRO_order' => new EE_Integer_Field('PRO_order', __("Order", "event_espresso"), false, 0), + 'PRO_accept_msg' => new EE_Simple_HTML_Field('PRO_accept_msg', esc_html__("Acceptance Message", "event_espresso"), false, esc_html__("Accepted", "event_espresso")), + 'PRO_decline_msg' => new EE_Simple_HTML_Field('PRO_decline_msg', esc_html__("Declined Message", "event_espresso"), false, esc_html__("Declined", "event_espresso")), + 'PRO_default' => new EE_Boolean_Field('PRO_default', esc_html__("Usable by default on all new items within promotion's scope", "event_espresso"), false, false), + 'PRO_order' => new EE_Integer_Field('PRO_order', esc_html__("Order", "event_espresso"), false, 0), 'PRO_deleted' => new EE_Trashed_Flag_Field('PRO_deleted', __("Deleted", 'event_espresso'), false, false), 'PRO_wp_user' => new EE_WP_User_Field('PRO_wp_user', __('Promotion Creator', 'event_espresso'), false), ) diff --git a/eea-promotions.php b/eea-promotions.php index d3bde79..283160e 100644 --- a/eea-promotions.php +++ b/eea-promotions.php @@ -75,7 +75,7 @@ function espresso_promotions_activation_error()

label->singular = __('Event', 'event_espresso'); - $this->label->plural = __('Events', 'event_espresso'); - $this->slug = 'Event'; + $this->label->singular = esc_html__('Event', 'event_espresso'); + $this->label->plural = esc_html__('Events', 'event_espresso'); + $this->slug = 'Event'; // filter for get_events on admin list table to only show events attached to specific promotion. - add_filter('FHEE__Events_Admin_Page__get_events__where', array( $this, 'event_list_query_params' ), 10, 2); + add_filter('FHEE__Events_Admin_Page__get_events__where', [$this, 'event_list_query_params'], 10, 2); // filter to show a helpful title on events list table when displaying events filtered by promotion - add_filter('FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg', array( $this, 'before_events_list_table_content' ), 10, 4); + add_filter( + 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg', + [$this, 'before_events_list_table_content'], + 10, + 4 + ); // control which events have promotions applied to them - add_filter('FHEE__EE_Promotion_Scope__get_object_line_items_from_cart__is_applicable_item', array( $this, 'is_applicable_item' ), 10, 2); + add_filter( + 'FHEE__EE_Promotion_Scope__get_object_line_items_from_cart__is_applicable_item', + [$this, 'is_applicable_item'], + 10, + 2 + ); } - /** * Callback for FHEE__Events_Admin_Page__get_events__where. Event Scope adds * additional query params to the query retrieving the events in certain conditions. * + * @param array $where current query where params for event query + * @param array $req_data incoming request data. + * @return array where query_args for get_events query. * @since 1.0.0 * - * @param array $where current query where params for event query - * @param array $req_data incoming request data. - * @return array where query_args for get_events query. */ public function event_list_query_params($where, $req_data) { - if (!empty($req_data['EVT_IDs'])) { - $evt_ids = explode(',', $req_data['EVT_IDs']); - $where['EVT_ID'] = array('IN', $evt_ids); + if (! empty($req_data['EVT_IDs'])) { + $evt_ids = explode(',', $req_data['EVT_IDs']); + $where['EVT_ID'] = ['IN', $evt_ids]; } return $where; } - - /** - * callback for the FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg filter so if displaying events filtered by promotion we add helpful title for viewer. - * - * @since 1.0.0 + * callback for the FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg filter so + * if displaying events filtered by promotion we add helpful title for viewer. * - * @param string $content Any current content. + * @param string $content Any current content. * @param string $page_slug Page slug of page - * @param array $req_data Incoming request data. + * @param array $req_data Incoming request data. * @param string $req_action 'action' value for page * * @return string If correct page then and conditions are met the new string. Otherwise existing. + * @since 1.0.0 + * */ public function before_events_list_table_content($content, $page_slug, $req_data, $req_action) { @@ -70,39 +78,47 @@ public function before_events_list_table_content($content, $page_slug, $req_data } $promotion = EEM_Promotion::instance()->get_one_by_ID($req_data['PRO_ID']); if ($promotion instanceof EE_Promotion) { - $query_args = array( + $query_args = [ 'action' => 'edit', - 'PRO_ID' => $promotion->ID() - ); - EE_Registry::instance()->load_helper('URL'); - $url = EEH_URL::add_query_args_and_nonce($query_args, admin_url('admin.php?page=espresso_promotions')); - $pro_linked = '' . $promotion->name() . ''; - $content .= '

' . sprintf(__('Viewing Events that the %s promotion applies to.', 'event_espresso'), $pro_linked) . '

'; + 'PRO_ID' => $promotion->ID(), + ]; + $url = + EEH_URL::add_query_args_and_nonce($query_args, admin_url('admin.php?page=espresso_promotions')); + $pro_linked = '' + . $promotion->name() + . ''; + $content .= '

' . sprintf( + __('Viewing Events that the %s promotion applies to.', 'event_espresso'), + $pro_linked + ) . '

'; } return $content; } - /** * Child scope classes indicate what gets returned when a "name" is requested. * - * @since 1.0.0 - * @param int | EE_Event | EE_Event[] $EVT_ID + * @param int | EE_Event | EE_Event[] $EVT_ID * Event ID (or array of IDs) or EE_Event object for the EE_Event object being utilized. - * @param bool | string $link + * @param bool | string $link * if FALSE then just return name, * otherwise 'front' wraps name in link to frontend details, * 'admin' wraps name in link to backend details. - * @param int $PRO_ID + * @param int $PRO_ID * Optional. Providing the Promotion ID allows identification in downstream code * for what promotion is being handled. (i.e. adding it to the query_args for the links). * @return string + * @since 1.0.0 */ public function name($EVT_ID, $link = false, $PRO_ID = 0) { - if (empty($EVT_ID) || ( is_array($EVT_ID) && count($EVT_ID) > 1 )) { + if (empty($EVT_ID) || (is_array($EVT_ID) && count($EVT_ID) > 1)) { switch ($link) { case 'front': // @todo eventually a filter could be added here so that the link goes to a filtered archive view of the events JUST for this promotion in the frontend. For now we won't do anything (cause I doubt this will be used much). @@ -110,18 +126,21 @@ public function name($EVT_ID, $link = false, $PRO_ID = 0) break; case 'admin': - $EVT_IDs = is_array($EVT_ID) && !empty($EVT_ID) ? implode(',', $EVT_ID) : ''; - $query_args = !empty($EVT_IDs) ? array( 'EVT_IDs' =>$EVT_IDs, 'PRO_ID' => $PRO_ID ) : array(); - $url = add_query_arg($query_args, $this->get_admin_url(null)); - $prepend = ''; - $append = ''; + $EVT_IDs = is_array($EVT_ID) && ! empty($EVT_ID) ? implode(',', $EVT_ID) : ''; + $query_args = ! empty($EVT_IDs) ? ['EVT_IDs' => $EVT_IDs, 'PRO_ID' => $PRO_ID] : []; + $url = add_query_arg($query_args, $this->get_admin_url(null)); + $prepend = ''; + $append = ''; break; default: $prepend = $append = ''; break; } - $count = is_array($EVT_ID) ? count($EVT_ID) : 0; + $count = is_array($EVT_ID) ? count($EVT_ID) : 0; $promo_count = $this->get_promo_count_display($count); return $this->get_scope_icon() . $prepend . $this->label->plural . $append . $promo_count; } @@ -130,54 +149,62 @@ public function name($EVT_ID, $link = false, $PRO_ID = 0) switch ($link) { case 'front': - $url = $this->get_frontend_url($evt->ID()); - $prepend = ''; - $append = ''; + $url = $this->get_frontend_url($evt->ID()); + $prepend = ''; + $append = ''; break; case 'admin': - $url = $this->get_admin_url($evt->ID()); - $prepend = ''; - $append = ''; + $url = $this->get_admin_url($evt->ID()); + $prepend = + ''; + $append = ''; break; default: $prepend = $append = ''; break; } - return $this->get_scope_icon() . $prepend . $evt->name() . $append; + $event_name = '' . $evt->name() . ''; + return $this->get_scope_icon() . $prepend . $event_name . $append; } - /** * This returns a html span string for the event scope icon. * - * @since 1.0.0 - * @param bool $class_only used to indicate if we only want to return the icon class - * or the entire html string. + * @param bool $class_only used to indicate if we only want to return the icon class + * or the entire html string. * @return string + * @since 1.0.0 */ public function get_scope_icon($class_only = false) { return $class_only ? 'dashicons dashicons-flag' - : ''; + : ''; } - /** * Child scope classes indicate what gets returned when a "description" is requested. * - * @since 1.0.0 - * @param int | EE_Event | EE_Event[] $EVT_ID (or array of IDS) or EE_Event object for the EE_Event object being utilized + * @param int | EE_Event | EE_Event[] $EVT_ID (or array of IDS) or EE_Event object for the EE_Event object being + * utilized * @return string + * @since 1.0.0 */ public function description($EVT_ID) { if (empty($EVT_ID) || is_array($EVT_ID)) { - return __('Applied to all events.', 'event_espresso'); + return esc_html__('Applied to all events.', 'event_espresso'); } $evt = $EVT_ID instanceof EE_Event ? $EVT_ID : $this->_get_model_object($EVT_ID); @@ -185,14 +212,13 @@ public function description($EVT_ID) } - /** * Child scope classes indicate what gets returned when the admin_url is requested. * Admin url usually points to the details page for the given id. * - * @since 1.0.0 - * @param int | EE_Event[] $EVT_ID ID or array of ids for the EE_Event object being utilized + * @param int | EE_Event[] $EVT_ID ID or array of ids for the EE_Event object being utilized * @return string + * @since 1.0.0 */ public function get_admin_url($EVT_ID) { @@ -201,27 +227,24 @@ public function get_admin_url($EVT_ID) return $base_url; } - $query_args = array( + $query_args = [ 'action' => 'edit', - 'post' => $EVT_ID - ); - EE_Registry::instance()->load_helper('URL'); + 'post' => $EVT_ID, + ]; return EEH_URL::add_query_args_and_nonce($query_args, $base_url); } - /** * Child scope classes indicate what gets returned when the frontend_url is requested. * Frontend url usually points to the single page view for the given id. * - * @since 1.0.0 - * @param int | EE_Event[] $EVT_ID ID or array of ids for the EE_Event object being utilized + * @param int | EE_Event[] $EVT_ID ID or array of ids for the EE_Event object being utilized * @return string + * @since 1.0.0 */ public function get_frontend_url($EVT_ID) { - EE_Registry::instance()->load_helper('Event_View'); if (empty($EVT_ID) || is_array($EVT_ID)) { return EEH_Event_View::event_archive_url(); } @@ -230,74 +253,84 @@ public function get_frontend_url($EVT_ID) } - - - /** * Generate the html for selecting events that a promotion applies to. * - * @since 1.0.0 - * * @param integer $PRO_ID The promotion ID for the applies to selector we are retrieving. * @return string html + * @since 1.0.0 + * */ public function get_admin_applies_to_selector($PRO_ID) { - - $applied_filters = $this->_maybe_overload_request_with_saved_filters($PRO_ID); - $total_items = $this->_get_total_items(); + $show_filters = $this->_maybe_overload_request_with_saved_filters($PRO_ID); + $total_items = $this->_get_total_items(); $items_to_select = $this->get_scope_items(); - $selected_items = $this->_get_applied_to_item_ids($PRO_ID); - $template_args = array( - 'scope_slug' => $this->slug, - 'scope' => $this, - 'header_content' => sprintf(__('%sCheck off the specific events that this promotion will be applied to.%s', 'event_espresso'), '

', '

'), - 'filters' => $this->_get_applies_to_filters(), - 'show_filters' => $applied_filters, - 'items_to_select' => $this->_get_applies_to_items_to_select($items_to_select, $selected_items, $PRO_ID), - 'items_paging' => $this->_get_applies_to_items_paging($total_items), - 'selected_items' => $selected_items, + $selected_items = $this->_get_applied_to_item_ids($PRO_ID); + $template_args = [ + 'scope_slug' => $this->slug, + 'scope' => $this, + 'header_content' => sprintf( + __('%sCheck off the specific events that this promotion will be applied to.%s', 'event_espresso'), + '

', + '

' + ), + 'filters' => $this->_get_applies_to_filters($show_filters), + 'show_filters' => $show_filters, + 'items_to_select' => $this->_get_applies_to_items_to_select( + $items_to_select, + $selected_items, + $PRO_ID + ), + 'items_paging' => $this->_get_applies_to_items_paging($total_items), + 'selected_items' => $selected_items, 'number_of_selected_items' => count($selected_items), - 'display_selected_label' => __('Display only selected Events', 'event_espresso'), - 'footer_content' => '' - ); - return EEH_Template::display_template(EE_PROMOTIONS_PATH . '/lib/scopes/templates/promotion_applies_to_wrapper.template.php', $template_args, true); + 'display_selected_label' => esc_html__('Display only selected Events', 'event_espresso'), + 'footer_content' => '', + ]; + return EEH_Template::display_template( + EE_PROMOTIONS_PATH . '/lib/scopes/templates/promotion_applies_to_wrapper.template.php', + $template_args, + true + ); } - /** * Returns query args for use in model queries on the * EEM model related to scope. Note this also should * consider any filters present * + * @return array * @since 1.0.0 * - * @return array */ public function get_query_args() { - EE_Registry::instance()->load_helper('DTT_Helper'); // $month_increment = apply_filters( 'FHEE__EE_Promotion_Event_Scope__get_query_args__month_increment', 1 ); // check for any existing dtt queries $DTT_EVT_start = ! empty($_REQUEST['EVT_start_date_filter']) ? $_REQUEST['EVT_start_date_filter'] : null; - $DTT_EVT_end = ! empty($_REQUEST['EVT_end_date_filter']) ? $_REQUEST['EVT_end_date_filter'] : null; + $DTT_EVT_end = ! empty($_REQUEST['EVT_end_date_filter']) ? $_REQUEST['EVT_end_date_filter'] : null; - $_where = array( - 'status' => array( 'NOT IN', array( EEM_Event::cancelled, 'trash' ) ) - ); + $_where = [ + 'status' => ['NOT IN', [EEM_Event::cancelled, 'trash']], + ]; if (! empty($DTT_EVT_start)) { - $_where['Datetime.DTT_EVT_start'] = array( '>', EEM_datetime::instance()->convert_datetime_for_query('DTT_EVT_start', $DTT_EVT_start, 'Y-m-d g:i a') ); + $_where['Datetime.DTT_EVT_start'] = [ + '>', + EEM_datetime::instance()->convert_datetime_for_query('DTT_EVT_start', $DTT_EVT_start, 'Y-m-d g:i a'), + ]; } if (! empty($DTT_EVT_end)) { - $_where['Datetime.DTT_EVT_end'] = array( '<', EEM_Datetime::instance()->convert_datetime_for_query('DTT_EVT_end', $DTT_EVT_end, 'Y-m-d g:i a') ); + $_where['Datetime.DTT_EVT_end'] = + ['<', EEM_Datetime::instance()->convert_datetime_for_query('DTT_EVT_end', $DTT_EVT_end, 'Y-m-d g:i a')]; } // exclude expired events by default unless include_expiry is checked. if (! isset($_REQUEST['include_expired_events_filter'])) { - $_where['Datetime.DTT_EVT_end**exclude_expired_events_query'] = array( '>', time() ); + $_where['Datetime.DTT_EVT_end**exclude_expired_events_query'] = ['>', time()]; } // category filters? @@ -307,12 +340,12 @@ public function get_query_args() // event title? if (! empty($_REQUEST['EVT_title_filter'])) { - $_where['EVT_name'] = array( 'LIKE', '%' . $_REQUEST['EVT_title_filter'] . '%' ); + $_where['EVT_name'] = ['LIKE', '%' . $_REQUEST['EVT_title_filter'] . '%']; } - $orderby= ! empty($_REQUEST['PRO_scope_sort']) ? $_REQUEST['PRO_scope_sort'] : 'DESC'; + $orderby = ! empty($_REQUEST['PRO_scope_sort']) ? $_REQUEST['PRO_scope_sort'] : 'DESC'; - $query_params = array( '0' => $_where, 'order_by' => array( 'EVT_created' => $orderby ), 'group_by' => 'EVT_ID' ); + $query_params = ['0' => $_where, 'order_by' => ['EVT_created' => $orderby], 'group_by' => 'EVT_ID']; // apply caps if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events_for_promotions')) { @@ -323,72 +356,87 @@ public function get_query_args() } - - /** * sets up the filters for the promotions scope selector * - * @since 1.0.0 * @return string + * @since 1.0.0 */ - protected function _get_applies_to_filters() + protected function _get_applies_to_filters($show_filters) { - EE_Registry::instance()->load_helper('Form_Fields'); + $template_args = [ + 'scope' => $this, + 'show_filters' => $show_filters, + ]; // categories - $categories = get_terms('espresso_event_categories', array( 'hide_empty' => false, 'fields' => 'id=>name' )); - $cat_values[] = array( 'text' => __('Include all categories', 'event_espresso'), 'id' => 0 ); - $default = ! empty($_REQUEST['EVT_CAT_ID']) ? absint($_REQUEST['EVT_CAT_ID']) : ''; + $categories = get_terms('espresso_event_categories', ['hide_empty' => false, 'fields' => 'id=>name']); + + $template_args['categories'] = ['text' => esc_html__('Include all categories', 'event_espresso'), 'id' => 0]; foreach ($categories as $id => $name) { - $cat_values[] = array( - 'text' => $name, - 'id' => $id - ); + $template_args['categories'][] = ['text' => $name, 'id' => $id ]; } - $cat_filter = ''; - $cat_filter .= EEH_Form_Fields::select_input('EVT_CAT_ID', $cat_values, $default); + $template_args['default'] = ! empty($_REQUEST['EVT_CAT_ID']) ? absint($_REQUEST['EVT_CAT_ID']) : ''; // start date - $existing_start_date = ! empty($_REQUEST['EVT_start_date_filter']) ? date('Y-m-d h:i a', strtotime($_REQUEST['EVT_start_date_filter'])) : ''; - $start_date_filter = ''; - $start_date_filter .= ''; + $existing_start_date = ! empty($_REQUEST['EVT_start_date_filter']) + ? date('Y-m-d h:i a',strtotime($_REQUEST['EVT_start_date_filter'])) + : ''; + + $template_args['start_date_picker'] = new PromotionsDatepicker( + $existing_start_date, + 'start', + '#promotions-applied-to-mbox', + 'EVT_start_date_filter', + esc_html__('enter filter start date', 'event_espresso') + ); // end date - $existing_end_date = ! empty($_REQUEST['EVT_end_date_filter']) ? date('Y-m-d h:i a', strtotime($_REQUEST['EVT_end_date_filter'])) : ''; - $end_date_filter = ''; - $end_date_filter .= ''; + $existing_end_date = ! empty($_REQUEST['EVT_end_date_filter']) + ? date('Y-m-d h:i a', strtotime($_REQUEST['EVT_end_date_filter'])) + : ''; + $template_args['end_date_picker'] = new PromotionsDatepicker( + $existing_end_date, + 'end', + '#promotions-applied-to-mbox', + 'EVT_end_date_filter', + esc_html__('enter filter end date', 'event_espresso') + ); // event name - $existing_name = ! empty($_REQUEST['EVT_title_filter']) ? sanitize_title_for_query($_REQUEST['EVT_title_filter']) : ''; - $event_title_filter = ''; - $event_title_filter .= ''; + $template_args['existing_name'] = ! empty($_REQUEST['EVT_title_filter']) + ? sanitize_title_for_query($_REQUEST['EVT_title_filter']) + : ''; // include expired events - $expired_checked = isset($_REQUEST['include_expired_events_filter']) ? " checked=checked" : ''; - $include_expired_filter = '
'; + $template_args['expired_checked'] = isset($_REQUEST['include_expired_events_filter']) ? " checked" : ''; - - return $cat_filter . '
' . $start_date_filter . '
' . $end_date_filter . '
' . $event_title_filter . '
' . $include_expired_filter . '
'; + // return $cat_filter . '
' . $start_date_filter . '
' . $end_date_filter . '
' . $event_title_filter . '
' . $include_expired_filter . '
'; + return EEH_Template::display_template( + EE_PROMOTIONS_PATH . '/lib/scopes/templates/promotion_applies_to_filters.template.php', + $template_args, + true + ); } - - /** * save event relation for the applies to promotion * - * @since 1.0.0 - * * @param EE_Promotion $promotion - * @param array $data the incoming form data + * @param array $data the incoming form data * @return void + * @since 1.0.0 + * */ public function handle_promotion_update(EE_Promotion $promotion, $data) { // first do we have any selected items? - $selected_items = !empty($data['ee_promotions_applied_selected_items_Event']) ? explode(',', $data['ee_promotions_applied_selected_items_Event']) : array(); - $evt_ids = array(); + $selected_items = ! empty($data['ee_promotions_applied_selected_items_Event']) ? explode( + ',', + $data['ee_promotions_applied_selected_items_Event'] + ) : []; + $evt_ids = []; // existing pro_objects $pro_objects = $promotion->promotion_objects(); @@ -396,7 +444,7 @@ public function handle_promotion_update(EE_Promotion $promotion, $data) // loop through existing and remove any that aren't present in the selected_items. foreach ($pro_objects as $pro_obj) { if (! in_array($pro_obj->OBJ_ID(), $selected_items)) { - $promotion->delete_related('Promotion_Object', array( array( 'POB_ID' => $pro_obj->ID() ) )); + $promotion->delete_related('Promotion_Object', [['POB_ID' => $pro_obj->ID()]]); } $evt_ids[] = $pro_obj->OBJ_ID(); } @@ -407,30 +455,32 @@ public function handle_promotion_update(EE_Promotion $promotion, $data) continue; } $promotion_obj = EE_Promotion_Object::new_instance( - array( + [ 'PRO_ID' => $promotion->ID(), 'OBJ_ID' => $EVT_ID, 'POB_type' => $this->slug, - 'POB_used' => 0 - ) + 'POB_used' => 0, + ] ); $promotion_obj->save(); } // any filters to save? - $set_filters = array( - 'EVT_CAT_ID' => ! empty($data['EVT_CAT_ID']) ? $data['EVT_CAT_ID'] : null, - 'EVT_start_date_filter' => ! empty($data['EVT_start_date_filter']) ? $data['EVT_start_date_filter'] : null, - 'EVT_end_date_filter' => ! empty($data['EVT_end_date_filter']) ? $data['EVT_end_date_filter'] : null, - 'EVT_title_filter' => ! empty($data['EVT_title_filter']) ? $data['EVT_title_filter'] : null, - 'include_expired_events_filter' => ! empty($data['include_expired_events_filter']) ? $data['include_expired_events_filter'] : null - ); + $set_filters = [ + 'EVT_CAT_ID' => ! empty($data['EVT_CAT_ID']) ? $data['EVT_CAT_ID'] : null, + 'EVT_start_date_filter' => ! empty($data['EVT_start_date_filter']) ? $data['EVT_start_date_filter'] + : null, + 'EVT_end_date_filter' => ! empty($data['EVT_end_date_filter']) ? $data['EVT_end_date_filter'] + : null, + 'EVT_title_filter' => ! empty($data['EVT_title_filter']) ? $data['EVT_title_filter'] : null, + 'include_expired_events_filter' => ! empty($data['include_expired_events_filter']) + ? $data['include_expired_events_filter'] : null, + ]; $promotion->update_extra_meta('promo_saved_filters', $set_filters); } - /** * get_promotion_line_item_type * @@ -442,7 +492,6 @@ public function get_promotion_line_item_type() } - /** * is_applicable_item * control which events have promotions applied to them diff --git a/lib/scopes/EE_Promotion_Scope.lib.php b/lib/scopes/EE_Promotion_Scope.lib.php index 292a16f..7139113 100644 --- a/lib/scopes/EE_Promotion_Scope.lib.php +++ b/lib/scopes/EE_Promotion_Scope.lib.php @@ -266,7 +266,7 @@ public function get_scope_icon($class_only = false) return $class_only ? 'dashicons dashicons-megaphone' : ''; } @@ -301,7 +301,7 @@ protected function _model() if (! $model instanceof $expected_model_class) { throw new EE_Error( sprintf( - __( + esc_html__( 'The loading of a corresponding model for %s failed because there is not a %s instance available.', 'event_espresso' ), @@ -355,7 +355,7 @@ protected function _get_model_object($OBJ_ID, $reset_cache = false) if (! $obj instanceof $expected_class) { throw new EE_Error( sprintf( - __( + esc_html__( 'Unable to retrieve the model object related to the %s class with this id: %s. Maybe it was deleted from the db and the promotion got orphaned.', 'event_espresso' ), @@ -528,9 +528,9 @@ public function ajax_get_applies_to_items_to_select() $PRO_ID ) : sprintf( - __('%sNo results for the given query%s', 'event_espresso'), - '
  • ', - '
' + esc_html__('%sNo results for the given query%s', 'event_espresso'), + '
', + '
' ); // paging list $total_items = $this->_get_total_items(); @@ -570,14 +570,14 @@ protected function _get_applies_to_items_to_select($items_to_select, $selected_i ) ] instanceof EE_Base_Class ) { return sprintf( - __( + esc_html__( 'There are no active %s to assign to this scope. You will need to create some first.', 'event_espresso' ), $this->label->plural ); } - $checkboxes = '
    '; + $checkboxes = '
    '; foreach ($items_to_select as $id => $obj) { $checked = in_array($id, $selected_items) ? ' checked=checked' : ''; // disabled check @@ -588,23 +588,24 @@ protected function _get_applies_to_items_to_select($items_to_select, $selected_i $disabled = $promo_obj instanceof EE_Promotion_Object && $promo_obj->used() > 0 ? ' disabled="disabled"' : ''; } - $checkboxes .= '
  • '; - $checkboxes .= ''; + $checkboxes .= " + '; } - $checkboxes .= '
'; + $checkboxes .= '
'; return $checkboxes; } @@ -619,16 +620,16 @@ protected function _get_applies_to_items_to_select($items_to_select, $selected_i */ protected function _get_applies_to_items_paging($total_items) { - EE_Registry::instance()->load_helper('Template'); - $current_page = isset($_REQUEST['paged']) ? $_REQUEST['paged'] : 1; - $perpage = isset($_REQUEST['perpage']) ? $_REQUEST['perpage'] : $this->_per_page; - $url = isset($_REQUEST['redirect_url']) ? $_REQUEST['redirect_url'] : $_SERVER['REQUEST_URI']; - return ' ' . EEH_Template::get_paging_html( + $current_page = isset($_REQUEST['paged']) ? absint($_REQUEST['paged']) : 1; + $perpage = isset($_REQUEST['perpage']) ? absint($_REQUEST['perpage']) : $this->_per_page; + $url = isset($_REQUEST['redirect_url']) ? esc_url_raw($_REQUEST['redirect_url']) : $_SERVER['REQUEST_URI']; + return EEH_Template::get_paging_html( $total_items, $current_page, $perpage, $url - ); + ) + . ' '; } @@ -651,7 +652,7 @@ private function _verify_properties_set() if (empty($this->slug)) { throw new EE_Error( sprintf( - __( + esc_html__( 'The %s class has not set the $slug property. This is used as a identifier for this scope and is necessary.', 'event_espresso' ), @@ -913,13 +914,13 @@ public function generate_promotion_line_item( // verify EE_Line_Item if (! $parent_line_item instanceof EE_Line_Item) { throw new EE_Error( - __('A valid EE_Line_Item object is required to generate a promotion line item.', 'event_espresso') + esc_html__('A valid EE_Line_Item object is required to generate a promotion line item.', 'event_espresso') ); } // verify EE_Promotion if (! $promotion instanceof EE_Promotion) { throw new EE_Error( - __('A valid EE_Promotion object is required to generate a promotion line item.', 'event_espresso') + esc_html__('A valid EE_Promotion object is required to generate a promotion line item.', 'event_espresso') ); } $promo_name = ! empty($promo_name) ? $promo_name : $promotion->name(); diff --git a/lib/scopes/templates/promotion_applies_to_filters.template.php b/lib/scopes/templates/promotion_applies_to_filters.template.php new file mode 100644 index 0000000..b52fba4 --- /dev/null +++ b/lib/scopes/templates/promotion_applies_to_filters.template.php @@ -0,0 +1,95 @@ + +
+

+ + +

+
> +

+ label->plural) + ); ?> +

+ +
+ + +
+ +
+ + +
+ +
+ + getHtml(); ?> +
+ +
+ + getHtml(); ?> +
+ +
+ +
+ + + +
+
+
diff --git a/lib/scopes/templates/promotion_applies_to_wrapper.template.php b/lib/scopes/templates/promotion_applies_to_wrapper.template.php index 231ae38..20b5183 100644 --- a/lib/scopes/templates/promotion_applies_to_wrapper.template.php +++ b/lib/scopes/templates/promotion_applies_to_wrapper.template.php @@ -2,24 +2,26 @@ /** * This file is the template for the promotions applies to metabox wrapper. * - * @since 1.0.0 - * @package EE4 Promotions + * @since 1.0.0 + * @package EE4 Promotions * @subpackage admin */ + /** * Template variables in use for this template - * @type string $scope_slug The slug for the scope this template serves. - * @type EE_Promotion_Scope $scope The EE_Promotion_Scope object for labels etc. - * @type string $header_content Any header content for this template and scope. - * @type string $filters Any filters this selector might use - * @type bool $show_filters Whether to show the filters container by default. - * @type string $items_to_select All the selectable items for this page view. - * @type string $items_paging This will be the html string for the paging of items. - * @type array $selected_items Array of IDs for the selected items + * + * @var string $scope_slug The slug for the scope this template serves. + * @var EE_Promotion_Scope $scope The EE_Promotion_Scope object for labels etc. + * @var string $header_content Any header content for this template and scope. + * @var string $filters Any filters this selector might use + * @var string $items_to_select All the selectable items for this page view. + * @var string $items_paging This will be the html string for the paging of items. + * @var array $selected_items Array of IDs for the selected items * that this promotion applies to. - * @type string $display_selected_label The test for the display selected label trigger/toggle. + * @var string $display_selected_label The test for the display selected label trigger/toggle. + * @var int $number_of_selected_items + * @var string $footer_content */ -$show_filters = ! $show_filters ? ' style="display:none"' : ''; ?>
@@ -28,40 +30,62 @@ if ($number_of_selected_items < 2) { // singular : This promotion is currently only applied to 1 event echo sprintf( - __('This promotion is currently only applied to :%3$s %1$s %2$s %3$s', 'event_espresso'), - '' . $number_of_selected_items . '', - strtolower($scope->label->singular), + esc_html__('This promotion is currently only applied to :%3$s %1$s %2$s %3$s', 'event_espresso'), + '' + . $number_of_selected_items + . '', + '' . strtolower($scope->label->plural) . '', '
' ); } else { // plural : This promotion is currently applied to 5 events echo sprintf( - __('This promotion is currently applied to :%3$s %1$s %2$s %3$s', 'event_espresso'), - '' . $number_of_selected_items . '', - strtolower($scope->label->plural), + esc_html__('This promotion is currently applied to :%3$s %1$s %2$s %3$s', 'event_espresso'), + '' + . $number_of_selected_items + . '', + '' . strtolower($scope->label->plural) . '', '
' ); } ?>

- -
-

-
> -

label->plural)); ?>

- - -
-
-
+ +
- - -
- - +
+ + + + +
+
+

+ + + + + + +
@@ -71,10 +95,12 @@
-
- -
-

+

+ +

diff --git a/templates/upcoming-promotions-grid.template.php b/templates/upcoming-promotions-grid.template.php index d8d3795..6ab9d52 100644 --- a/templates/upcoming-promotions-grid.template.php +++ b/templates/upcoming-promotions-grid.template.php @@ -15,7 +15,7 @@

-
+

$objects) : ?>
diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 43521df..179ffe7 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,9 +1,6 @@