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 .= '- +
- +
- + | |
-
- - - + + + + |
@@ -53,7 +73,12 @@
+
+
- + |
-
+ + + redeemed() > 0) : ?> -+ + + + + |
- + |
-
+ + + |
---|---|
-
+ + + |
|
- + |
-
-
+
+ + + |
- + getHtml(); ?> | |
- - + getHtml(); ?> | |
-
-
+
+ + + |
|
-
-
+
+ + + |
|
-
-
+
+ + + |
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 .= '
', '
'), - '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 . '+ label->plural) + ); ?> +
+ +-
label->plural)); ?>
- - -+ +
-
+