@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | |
@@ -17,121 +17,121 @@ discard block |
||
| 17 | 17 | { |
| 18 | 18 | |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * enqueues css and js, so that this can be called statically |
|
| 22 | - */ |
|
| 23 | - public static function enqueue_styles_and_scripts() |
|
| 24 | - { |
|
| 25 | - wp_register_style( |
|
| 26 | - 'checkbox_dropdown_selector', |
|
| 27 | - EE_GLOBAL_ASSETS_URL . 'css/checkbox_dropdown_selector.css', |
|
| 28 | - array('espresso_default'), |
|
| 29 | - EVENT_ESPRESSO_VERSION |
|
| 30 | - ); |
|
| 31 | - wp_enqueue_style('checkbox_dropdown_selector'); |
|
| 32 | - wp_register_script( |
|
| 33 | - 'checkbox_dropdown_selector', |
|
| 34 | - EE_GLOBAL_ASSETS_URL . 'scripts/checkbox_dropdown_selector.js', |
|
| 35 | - array('jquery'), |
|
| 36 | - EVENT_ESPRESSO_VERSION, |
|
| 37 | - true |
|
| 38 | - ); |
|
| 39 | - wp_enqueue_script('checkbox_dropdown_selector'); |
|
| 40 | - } |
|
| 20 | + /** |
|
| 21 | + * enqueues css and js, so that this can be called statically |
|
| 22 | + */ |
|
| 23 | + public static function enqueue_styles_and_scripts() |
|
| 24 | + { |
|
| 25 | + wp_register_style( |
|
| 26 | + 'checkbox_dropdown_selector', |
|
| 27 | + EE_GLOBAL_ASSETS_URL . 'css/checkbox_dropdown_selector.css', |
|
| 28 | + array('espresso_default'), |
|
| 29 | + EVENT_ESPRESSO_VERSION |
|
| 30 | + ); |
|
| 31 | + wp_enqueue_style('checkbox_dropdown_selector'); |
|
| 32 | + wp_register_script( |
|
| 33 | + 'checkbox_dropdown_selector', |
|
| 34 | + EE_GLOBAL_ASSETS_URL . 'scripts/checkbox_dropdown_selector.js', |
|
| 35 | + array('jquery'), |
|
| 36 | + EVENT_ESPRESSO_VERSION, |
|
| 37 | + true |
|
| 38 | + ); |
|
| 39 | + wp_enqueue_script('checkbox_dropdown_selector'); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | 42 | |
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Informs the rest of the forms system what CSS and JS is needed to display the input |
|
| 46 | - */ |
|
| 47 | - public function enqueue_js(){ |
|
| 48 | - EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts(); |
|
| 49 | - } |
|
| 44 | + /** |
|
| 45 | + * Informs the rest of the forms system what CSS and JS is needed to display the input |
|
| 46 | + */ |
|
| 47 | + public function enqueue_js(){ |
|
| 48 | + EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts(); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @throws EE_Error |
|
| 54 | - * @return string of html to display the field |
|
| 55 | - */ |
|
| 56 | - public function display() |
|
| 57 | - { |
|
| 58 | - $input = $this->get_input(); |
|
| 59 | - $select_button_text = $input instanceof EE_Checkbox_Dropdown_Selector_Input ? $input->select_button_text() : ''; |
|
| 60 | - // $multi = count( $input->options() ) > 1 ? TRUE : FALSE; |
|
| 61 | - $input->set_label_sizes(); |
|
| 62 | - $label_size_class = $input->get_label_size_class(); |
|
| 63 | - if ( ! is_array($input->raw_value()) && $input->raw_value() !== null) { |
|
| 64 | - EE_Error::doing_it_wrong( |
|
| 65 | - 'EE_Checkbox_Display_Strategy::display()', |
|
| 66 | - sprintf( |
|
| 67 | - esc_html__( |
|
| 68 | - 'Input values for checkboxes should be an array of values, but the value for input "%1$s" is "%2$s". Please verify that the input name is exactly "%3$s"', |
|
| 69 | - 'event_espresso' |
|
| 70 | - ), |
|
| 71 | - $input->html_id(), |
|
| 72 | - var_export($input->raw_value(), true), |
|
| 73 | - $input->html_name() . '[]' |
|
| 74 | - ), |
|
| 75 | - '4.8.1' |
|
| 76 | - ); |
|
| 77 | - } |
|
| 78 | - $html = '<button type="submit"'; |
|
| 79 | - $html .= ' id="' . $input->html_id() . '-btn"'; |
|
| 80 | - // $html .= ' name="' . $input->html_name() . '"'; |
|
| 81 | - $html .= ' class="' . $input->html_class() . ' checkbox-dropdown-selector-btn button-secondary button"'; |
|
| 82 | - $html .= ' style="' . $input->html_style() . '"'; |
|
| 83 | - $html .= ' data-target="' . $input->html_id() . '-options-dv"'; |
|
| 84 | - $html .= ' ' . $input->html_other_attributes() . '>'; |
|
| 85 | - $html .= '<span class="checkbox-dropdown-selector-selected-spn">'; |
|
| 86 | - $html .= $select_button_text; |
|
| 87 | - $html .= '</span> <span class="dashicons dashicons-arrow-down"></span>'; |
|
| 88 | - $html .= '</button>'; |
|
| 89 | - $html .= EEH_HTML::div( |
|
| 90 | - '', |
|
| 91 | - $input->html_id() . '-options-dv', |
|
| 92 | - 'checkbox-dropdown-selector' |
|
| 93 | - ); |
|
| 94 | - $html .= EEH_HTML::link( |
|
| 95 | - '', |
|
| 96 | - '<span class="dashicons dashicons-no"></span>', |
|
| 97 | - esc_html__('close datetime selector', 'event_espresso'), |
|
| 98 | - '', |
|
| 99 | - 'close-espresso-notice' |
|
| 100 | - ); |
|
| 101 | - $html .= EEH_HTML::ul(); |
|
| 102 | - $input_raw_value = (array)$input->raw_value(); |
|
| 103 | - foreach ($input->options() as $value => $display_text) { |
|
| 104 | - $html .= EEH_HTML::li(); |
|
| 105 | - $value = $input->get_normalization_strategy()->unnormalize_one($value); |
|
| 106 | - $html_id = $this->get_sub_input_id($value); |
|
| 107 | - $html .= EEH_HTML::nl(0, 'checkbox'); |
|
| 108 | - $html .= '<label for="' |
|
| 109 | - . $html_id |
|
| 110 | - . '" id="' |
|
| 111 | - . $html_id |
|
| 112 | - . '-lbl" class="ee-checkbox-label-after' |
|
| 113 | - . $label_size_class |
|
| 114 | - . '">'; |
|
| 115 | - $html .= EEH_HTML::nl(1, 'checkbox'); |
|
| 116 | - $html .= '<input type="checkbox"'; |
|
| 117 | - $html .= ' name="' . $input->html_name() . '[]"'; |
|
| 118 | - $html .= ' id="' . $html_id . '"'; |
|
| 119 | - $html .= ' class="' . $input->html_class() . '-option"'; |
|
| 120 | - $html .= ' style="' . $input->html_style() . '"'; |
|
| 121 | - $html .= ' value="' . esc_attr($value) . '"'; |
|
| 122 | - $html .= ! empty($input_raw_value) && in_array($value, $input_raw_value, true) |
|
| 123 | - ? ' checked="checked"' |
|
| 124 | - : ''; |
|
| 125 | - $html .= ' ' . $this->_input->other_html_attributes(); |
|
| 126 | - $html .= '>'; |
|
| 127 | - $html .= '<span class="datetime-selector-option-text-spn">' . $display_text . '</span>'; |
|
| 128 | - $html .= EEH_HTML::nl(-1, 'checkbox') . '</label>'; |
|
| 129 | - $html .= EEH_HTML::lix(); |
|
| 130 | - } |
|
| 131 | - $html .= EEH_HTML::ulx(); |
|
| 132 | - $html .= EEH_HTML::divx(); |
|
| 133 | - return $html; |
|
| 134 | - } |
|
| 52 | + /** |
|
| 53 | + * @throws EE_Error |
|
| 54 | + * @return string of html to display the field |
|
| 55 | + */ |
|
| 56 | + public function display() |
|
| 57 | + { |
|
| 58 | + $input = $this->get_input(); |
|
| 59 | + $select_button_text = $input instanceof EE_Checkbox_Dropdown_Selector_Input ? $input->select_button_text() : ''; |
|
| 60 | + // $multi = count( $input->options() ) > 1 ? TRUE : FALSE; |
|
| 61 | + $input->set_label_sizes(); |
|
| 62 | + $label_size_class = $input->get_label_size_class(); |
|
| 63 | + if ( ! is_array($input->raw_value()) && $input->raw_value() !== null) { |
|
| 64 | + EE_Error::doing_it_wrong( |
|
| 65 | + 'EE_Checkbox_Display_Strategy::display()', |
|
| 66 | + sprintf( |
|
| 67 | + esc_html__( |
|
| 68 | + 'Input values for checkboxes should be an array of values, but the value for input "%1$s" is "%2$s". Please verify that the input name is exactly "%3$s"', |
|
| 69 | + 'event_espresso' |
|
| 70 | + ), |
|
| 71 | + $input->html_id(), |
|
| 72 | + var_export($input->raw_value(), true), |
|
| 73 | + $input->html_name() . '[]' |
|
| 74 | + ), |
|
| 75 | + '4.8.1' |
|
| 76 | + ); |
|
| 77 | + } |
|
| 78 | + $html = '<button type="submit"'; |
|
| 79 | + $html .= ' id="' . $input->html_id() . '-btn"'; |
|
| 80 | + // $html .= ' name="' . $input->html_name() . '"'; |
|
| 81 | + $html .= ' class="' . $input->html_class() . ' checkbox-dropdown-selector-btn button-secondary button"'; |
|
| 82 | + $html .= ' style="' . $input->html_style() . '"'; |
|
| 83 | + $html .= ' data-target="' . $input->html_id() . '-options-dv"'; |
|
| 84 | + $html .= ' ' . $input->html_other_attributes() . '>'; |
|
| 85 | + $html .= '<span class="checkbox-dropdown-selector-selected-spn">'; |
|
| 86 | + $html .= $select_button_text; |
|
| 87 | + $html .= '</span> <span class="dashicons dashicons-arrow-down"></span>'; |
|
| 88 | + $html .= '</button>'; |
|
| 89 | + $html .= EEH_HTML::div( |
|
| 90 | + '', |
|
| 91 | + $input->html_id() . '-options-dv', |
|
| 92 | + 'checkbox-dropdown-selector' |
|
| 93 | + ); |
|
| 94 | + $html .= EEH_HTML::link( |
|
| 95 | + '', |
|
| 96 | + '<span class="dashicons dashicons-no"></span>', |
|
| 97 | + esc_html__('close datetime selector', 'event_espresso'), |
|
| 98 | + '', |
|
| 99 | + 'close-espresso-notice' |
|
| 100 | + ); |
|
| 101 | + $html .= EEH_HTML::ul(); |
|
| 102 | + $input_raw_value = (array)$input->raw_value(); |
|
| 103 | + foreach ($input->options() as $value => $display_text) { |
|
| 104 | + $html .= EEH_HTML::li(); |
|
| 105 | + $value = $input->get_normalization_strategy()->unnormalize_one($value); |
|
| 106 | + $html_id = $this->get_sub_input_id($value); |
|
| 107 | + $html .= EEH_HTML::nl(0, 'checkbox'); |
|
| 108 | + $html .= '<label for="' |
|
| 109 | + . $html_id |
|
| 110 | + . '" id="' |
|
| 111 | + . $html_id |
|
| 112 | + . '-lbl" class="ee-checkbox-label-after' |
|
| 113 | + . $label_size_class |
|
| 114 | + . '">'; |
|
| 115 | + $html .= EEH_HTML::nl(1, 'checkbox'); |
|
| 116 | + $html .= '<input type="checkbox"'; |
|
| 117 | + $html .= ' name="' . $input->html_name() . '[]"'; |
|
| 118 | + $html .= ' id="' . $html_id . '"'; |
|
| 119 | + $html .= ' class="' . $input->html_class() . '-option"'; |
|
| 120 | + $html .= ' style="' . $input->html_style() . '"'; |
|
| 121 | + $html .= ' value="' . esc_attr($value) . '"'; |
|
| 122 | + $html .= ! empty($input_raw_value) && in_array($value, $input_raw_value, true) |
|
| 123 | + ? ' checked="checked"' |
|
| 124 | + : ''; |
|
| 125 | + $html .= ' ' . $this->_input->other_html_attributes(); |
|
| 126 | + $html .= '>'; |
|
| 127 | + $html .= '<span class="datetime-selector-option-text-spn">' . $display_text . '</span>'; |
|
| 128 | + $html .= EEH_HTML::nl(-1, 'checkbox') . '</label>'; |
|
| 129 | + $html .= EEH_HTML::lix(); |
|
| 130 | + } |
|
| 131 | + $html .= EEH_HTML::ulx(); |
|
| 132 | + $html .= EEH_HTML::divx(); |
|
| 133 | + return $html; |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | 136 | |
| 137 | 137 | |
@@ -24,14 +24,14 @@ discard block |
||
| 24 | 24 | { |
| 25 | 25 | wp_register_style( |
| 26 | 26 | 'checkbox_dropdown_selector', |
| 27 | - EE_GLOBAL_ASSETS_URL . 'css/checkbox_dropdown_selector.css', |
|
| 27 | + EE_GLOBAL_ASSETS_URL.'css/checkbox_dropdown_selector.css', |
|
| 28 | 28 | array('espresso_default'), |
| 29 | 29 | EVENT_ESPRESSO_VERSION |
| 30 | 30 | ); |
| 31 | 31 | wp_enqueue_style('checkbox_dropdown_selector'); |
| 32 | 32 | wp_register_script( |
| 33 | 33 | 'checkbox_dropdown_selector', |
| 34 | - EE_GLOBAL_ASSETS_URL . 'scripts/checkbox_dropdown_selector.js', |
|
| 34 | + EE_GLOBAL_ASSETS_URL.'scripts/checkbox_dropdown_selector.js', |
|
| 35 | 35 | array('jquery'), |
| 36 | 36 | EVENT_ESPRESSO_VERSION, |
| 37 | 37 | true |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | /** |
| 45 | 45 | * Informs the rest of the forms system what CSS and JS is needed to display the input |
| 46 | 46 | */ |
| 47 | - public function enqueue_js(){ |
|
| 47 | + public function enqueue_js() { |
|
| 48 | 48 | EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts(); |
| 49 | 49 | } |
| 50 | 50 | |
@@ -70,25 +70,25 @@ discard block |
||
| 70 | 70 | ), |
| 71 | 71 | $input->html_id(), |
| 72 | 72 | var_export($input->raw_value(), true), |
| 73 | - $input->html_name() . '[]' |
|
| 73 | + $input->html_name().'[]' |
|
| 74 | 74 | ), |
| 75 | 75 | '4.8.1' |
| 76 | 76 | ); |
| 77 | 77 | } |
| 78 | 78 | $html = '<button type="submit"'; |
| 79 | - $html .= ' id="' . $input->html_id() . '-btn"'; |
|
| 79 | + $html .= ' id="'.$input->html_id().'-btn"'; |
|
| 80 | 80 | // $html .= ' name="' . $input->html_name() . '"'; |
| 81 | - $html .= ' class="' . $input->html_class() . ' checkbox-dropdown-selector-btn button-secondary button"'; |
|
| 82 | - $html .= ' style="' . $input->html_style() . '"'; |
|
| 83 | - $html .= ' data-target="' . $input->html_id() . '-options-dv"'; |
|
| 84 | - $html .= ' ' . $input->html_other_attributes() . '>'; |
|
| 81 | + $html .= ' class="'.$input->html_class().' checkbox-dropdown-selector-btn button-secondary button"'; |
|
| 82 | + $html .= ' style="'.$input->html_style().'"'; |
|
| 83 | + $html .= ' data-target="'.$input->html_id().'-options-dv"'; |
|
| 84 | + $html .= ' '.$input->html_other_attributes().'>'; |
|
| 85 | 85 | $html .= '<span class="checkbox-dropdown-selector-selected-spn">'; |
| 86 | 86 | $html .= $select_button_text; |
| 87 | 87 | $html .= '</span> <span class="dashicons dashicons-arrow-down"></span>'; |
| 88 | 88 | $html .= '</button>'; |
| 89 | 89 | $html .= EEH_HTML::div( |
| 90 | 90 | '', |
| 91 | - $input->html_id() . '-options-dv', |
|
| 91 | + $input->html_id().'-options-dv', |
|
| 92 | 92 | 'checkbox-dropdown-selector' |
| 93 | 93 | ); |
| 94 | 94 | $html .= EEH_HTML::link( |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | 'close-espresso-notice' |
| 100 | 100 | ); |
| 101 | 101 | $html .= EEH_HTML::ul(); |
| 102 | - $input_raw_value = (array)$input->raw_value(); |
|
| 102 | + $input_raw_value = (array) $input->raw_value(); |
|
| 103 | 103 | foreach ($input->options() as $value => $display_text) { |
| 104 | 104 | $html .= EEH_HTML::li(); |
| 105 | 105 | $value = $input->get_normalization_strategy()->unnormalize_one($value); |
@@ -114,18 +114,18 @@ discard block |
||
| 114 | 114 | . '">'; |
| 115 | 115 | $html .= EEH_HTML::nl(1, 'checkbox'); |
| 116 | 116 | $html .= '<input type="checkbox"'; |
| 117 | - $html .= ' name="' . $input->html_name() . '[]"'; |
|
| 118 | - $html .= ' id="' . $html_id . '"'; |
|
| 119 | - $html .= ' class="' . $input->html_class() . '-option"'; |
|
| 120 | - $html .= ' style="' . $input->html_style() . '"'; |
|
| 121 | - $html .= ' value="' . esc_attr($value) . '"'; |
|
| 117 | + $html .= ' name="'.$input->html_name().'[]"'; |
|
| 118 | + $html .= ' id="'.$html_id.'"'; |
|
| 119 | + $html .= ' class="'.$input->html_class().'-option"'; |
|
| 120 | + $html .= ' style="'.$input->html_style().'"'; |
|
| 121 | + $html .= ' value="'.esc_attr($value).'"'; |
|
| 122 | 122 | $html .= ! empty($input_raw_value) && in_array($value, $input_raw_value, true) |
| 123 | 123 | ? ' checked="checked"' |
| 124 | 124 | : ''; |
| 125 | - $html .= ' ' . $this->_input->other_html_attributes(); |
|
| 125 | + $html .= ' '.$this->_input->other_html_attributes(); |
|
| 126 | 126 | $html .= '>'; |
| 127 | - $html .= '<span class="datetime-selector-option-text-spn">' . $display_text . '</span>'; |
|
| 128 | - $html .= EEH_HTML::nl(-1, 'checkbox') . '</label>'; |
|
| 127 | + $html .= '<span class="datetime-selector-option-text-spn">'.$display_text.'</span>'; |
|
| 128 | + $html .= EEH_HTML::nl(-1, 'checkbox').'</label>'; |
|
| 129 | 129 | $html .= EEH_HTML::lix(); |
| 130 | 130 | } |
| 131 | 131 | $html .= EEH_HTML::ulx(); |
@@ -16,159 +16,159 @@ |
||
| 16 | 16 | class DatetimeSelector |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @var \EE_Event $event |
|
| 21 | - */ |
|
| 22 | - protected $event; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @var \EE_Ticket[] $tickets |
|
| 26 | - */ |
|
| 27 | - protected $tickets; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @var \EE_Datetime[] $datetimes |
|
| 31 | - */ |
|
| 32 | - protected $datetimes; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @var \EE_Ticket_Selector_Config $template_settings |
|
| 36 | - */ |
|
| 37 | - protected $template_settings; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @var boolean $active |
|
| 41 | - */ |
|
| 42 | - protected $active = false; |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * DatetimeSelector constructor. |
|
| 48 | - * |
|
| 49 | - * @param \EE_Event $event |
|
| 50 | - * @param \EE_Ticket[] $tickets |
|
| 51 | - * @param \EE_Ticket_Selector_Config $template_settings |
|
| 52 | - * @throws \EE_Error |
|
| 53 | - */ |
|
| 54 | - public function __construct(\EE_Event $event, array $tickets, \EE_Ticket_Selector_Config $template_settings) |
|
| 55 | - { |
|
| 56 | - $this->event = $event; |
|
| 57 | - $this->tickets = $tickets; |
|
| 58 | - $this->template_settings = $template_settings; |
|
| 59 | - $this->datetimes = $this->getAllDatetimesForAllTicket($tickets); |
|
| 60 | - $this->active = $this->template_settings->showDatetimeSelector($this->datetimes); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @param \EE_Ticket[] $tickets |
|
| 67 | - * @return array |
|
| 68 | - * @throws \EE_Error |
|
| 69 | - */ |
|
| 70 | - protected function getAllDatetimesForAllTicket($tickets = array()) |
|
| 71 | - { |
|
| 72 | - $datetimes = array(); |
|
| 73 | - foreach ($tickets as $ticket) { |
|
| 74 | - $datetimes = $this->getTicketDatetimes($ticket, $datetimes); |
|
| 75 | - } |
|
| 76 | - return $datetimes; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @param \EE_Ticket $ticket |
|
| 83 | - * @param \EE_Datetime[] $datetimes |
|
| 84 | - * @return \EE_Datetime[] |
|
| 85 | - * @throws \EE_Error |
|
| 86 | - */ |
|
| 87 | - protected function getTicketDatetimes(\EE_Ticket $ticket, $datetimes = array()) |
|
| 88 | - { |
|
| 89 | - $ticket_datetimes = $ticket->datetimes( |
|
| 90 | - array( |
|
| 91 | - 'order_by' => array( |
|
| 92 | - 'DTT_order' => 'ASC', |
|
| 93 | - 'DTT_EVT_start' => 'ASC' |
|
| 94 | - ), |
|
| 95 | - 'default_where_conditions' => 'none', |
|
| 96 | - ) |
|
| 97 | - ); |
|
| 98 | - foreach ($ticket_datetimes as $ticket_datetime) { |
|
| 99 | - if ( ! $ticket_datetime instanceof \EE_Datetime) { |
|
| 100 | - continue; |
|
| 101 | - } |
|
| 102 | - $datetimes[ $ticket_datetime->ID() ] = $ticket_datetime; |
|
| 103 | - } |
|
| 104 | - return $datetimes; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @param \EE_Ticket $ticket |
|
| 111 | - * @return string |
|
| 112 | - * @throws \EE_Error |
|
| 113 | - */ |
|
| 114 | - public function getTicketDatetimeClasses( \EE_Ticket $ticket ) { |
|
| 115 | - if ( ! $this->active) { |
|
| 116 | - return ''; |
|
| 117 | - } |
|
| 118 | - $ticket_datetimes = $this->getTicketDatetimes($ticket); |
|
| 119 | - $classes = ''; |
|
| 120 | - foreach ($this->datetimes as $datetime) { |
|
| 121 | - if ( ! $datetime instanceof \EE_Datetime || ! in_array($datetime, $ticket_datetimes, true)) { |
|
| 122 | - continue; |
|
| 123 | - } |
|
| 124 | - $classes .= ' ee-ticket-datetimes-' . $datetime->date_range('Y_m_d', '-'); |
|
| 125 | - } |
|
| 126 | - $classes .= ' ee-hidden-ticket-tr'; |
|
| 127 | - return $classes; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * @param string $date_format |
|
| 134 | - * @return string |
|
| 135 | - * @throws \EE_Error |
|
| 136 | - */ |
|
| 137 | - public function getDatetimeSelector($date_format = 'Y-m-d') { |
|
| 138 | - if ( ! $this->active) { |
|
| 139 | - return ''; |
|
| 140 | - } |
|
| 141 | - $datetime_options = array(); |
|
| 142 | - foreach ($this->datetimes as $datetime) { |
|
| 143 | - if ( ! $datetime instanceof \EE_Datetime) { |
|
| 144 | - continue; |
|
| 145 | - } |
|
| 146 | - $desc = $datetime->name(); |
|
| 147 | - $desc .= ! empty($desc) |
|
| 148 | - ? ' ' . $datetime->date_range($date_format) |
|
| 149 | - : $datetime->date_range($date_format); |
|
| 150 | - $datetime_options[$datetime->date_range('Y_m_d', '-')] = $desc; |
|
| 151 | - } |
|
| 152 | - $dropdown_selector = new \EE_Checkbox_Dropdown_Selector_Input( |
|
| 153 | - $datetime_options, |
|
| 154 | - array( |
|
| 155 | - 'html_id' => 'datetime-selector-' . $this->event->ID(), |
|
| 156 | - 'html_name' => 'datetime_selector_' . $this->event->ID(), |
|
| 157 | - 'html_class' => 'datetime-selector', |
|
| 158 | - 'select_button_text' => '<span class="dashicons dashicons-calendar-alt"></span> ' |
|
| 159 | - . esc_html__('Select a Datetime', 'event_espresso'), |
|
| 160 | - 'other_html_attributes' => ' data-tkt_slctr_evt="' . $this->event->ID() . '"', |
|
| 161 | - ) |
|
| 162 | - ); |
|
| 163 | - return \EEH_HTML::div( |
|
| 164 | - \EEH_HTML::div( |
|
| 165 | - $dropdown_selector->get_html_for_input(), |
|
| 166 | - '', 'select-wrap-dv' |
|
| 167 | - ) |
|
| 168 | - . \EEH_HTML::br(), |
|
| 169 | - '', 'datetime_selector-dv' |
|
| 170 | - ); |
|
| 171 | - } |
|
| 19 | + /** |
|
| 20 | + * @var \EE_Event $event |
|
| 21 | + */ |
|
| 22 | + protected $event; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @var \EE_Ticket[] $tickets |
|
| 26 | + */ |
|
| 27 | + protected $tickets; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @var \EE_Datetime[] $datetimes |
|
| 31 | + */ |
|
| 32 | + protected $datetimes; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @var \EE_Ticket_Selector_Config $template_settings |
|
| 36 | + */ |
|
| 37 | + protected $template_settings; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @var boolean $active |
|
| 41 | + */ |
|
| 42 | + protected $active = false; |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * DatetimeSelector constructor. |
|
| 48 | + * |
|
| 49 | + * @param \EE_Event $event |
|
| 50 | + * @param \EE_Ticket[] $tickets |
|
| 51 | + * @param \EE_Ticket_Selector_Config $template_settings |
|
| 52 | + * @throws \EE_Error |
|
| 53 | + */ |
|
| 54 | + public function __construct(\EE_Event $event, array $tickets, \EE_Ticket_Selector_Config $template_settings) |
|
| 55 | + { |
|
| 56 | + $this->event = $event; |
|
| 57 | + $this->tickets = $tickets; |
|
| 58 | + $this->template_settings = $template_settings; |
|
| 59 | + $this->datetimes = $this->getAllDatetimesForAllTicket($tickets); |
|
| 60 | + $this->active = $this->template_settings->showDatetimeSelector($this->datetimes); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @param \EE_Ticket[] $tickets |
|
| 67 | + * @return array |
|
| 68 | + * @throws \EE_Error |
|
| 69 | + */ |
|
| 70 | + protected function getAllDatetimesForAllTicket($tickets = array()) |
|
| 71 | + { |
|
| 72 | + $datetimes = array(); |
|
| 73 | + foreach ($tickets as $ticket) { |
|
| 74 | + $datetimes = $this->getTicketDatetimes($ticket, $datetimes); |
|
| 75 | + } |
|
| 76 | + return $datetimes; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @param \EE_Ticket $ticket |
|
| 83 | + * @param \EE_Datetime[] $datetimes |
|
| 84 | + * @return \EE_Datetime[] |
|
| 85 | + * @throws \EE_Error |
|
| 86 | + */ |
|
| 87 | + protected function getTicketDatetimes(\EE_Ticket $ticket, $datetimes = array()) |
|
| 88 | + { |
|
| 89 | + $ticket_datetimes = $ticket->datetimes( |
|
| 90 | + array( |
|
| 91 | + 'order_by' => array( |
|
| 92 | + 'DTT_order' => 'ASC', |
|
| 93 | + 'DTT_EVT_start' => 'ASC' |
|
| 94 | + ), |
|
| 95 | + 'default_where_conditions' => 'none', |
|
| 96 | + ) |
|
| 97 | + ); |
|
| 98 | + foreach ($ticket_datetimes as $ticket_datetime) { |
|
| 99 | + if ( ! $ticket_datetime instanceof \EE_Datetime) { |
|
| 100 | + continue; |
|
| 101 | + } |
|
| 102 | + $datetimes[ $ticket_datetime->ID() ] = $ticket_datetime; |
|
| 103 | + } |
|
| 104 | + return $datetimes; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @param \EE_Ticket $ticket |
|
| 111 | + * @return string |
|
| 112 | + * @throws \EE_Error |
|
| 113 | + */ |
|
| 114 | + public function getTicketDatetimeClasses( \EE_Ticket $ticket ) { |
|
| 115 | + if ( ! $this->active) { |
|
| 116 | + return ''; |
|
| 117 | + } |
|
| 118 | + $ticket_datetimes = $this->getTicketDatetimes($ticket); |
|
| 119 | + $classes = ''; |
|
| 120 | + foreach ($this->datetimes as $datetime) { |
|
| 121 | + if ( ! $datetime instanceof \EE_Datetime || ! in_array($datetime, $ticket_datetimes, true)) { |
|
| 122 | + continue; |
|
| 123 | + } |
|
| 124 | + $classes .= ' ee-ticket-datetimes-' . $datetime->date_range('Y_m_d', '-'); |
|
| 125 | + } |
|
| 126 | + $classes .= ' ee-hidden-ticket-tr'; |
|
| 127 | + return $classes; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * @param string $date_format |
|
| 134 | + * @return string |
|
| 135 | + * @throws \EE_Error |
|
| 136 | + */ |
|
| 137 | + public function getDatetimeSelector($date_format = 'Y-m-d') { |
|
| 138 | + if ( ! $this->active) { |
|
| 139 | + return ''; |
|
| 140 | + } |
|
| 141 | + $datetime_options = array(); |
|
| 142 | + foreach ($this->datetimes as $datetime) { |
|
| 143 | + if ( ! $datetime instanceof \EE_Datetime) { |
|
| 144 | + continue; |
|
| 145 | + } |
|
| 146 | + $desc = $datetime->name(); |
|
| 147 | + $desc .= ! empty($desc) |
|
| 148 | + ? ' ' . $datetime->date_range($date_format) |
|
| 149 | + : $datetime->date_range($date_format); |
|
| 150 | + $datetime_options[$datetime->date_range('Y_m_d', '-')] = $desc; |
|
| 151 | + } |
|
| 152 | + $dropdown_selector = new \EE_Checkbox_Dropdown_Selector_Input( |
|
| 153 | + $datetime_options, |
|
| 154 | + array( |
|
| 155 | + 'html_id' => 'datetime-selector-' . $this->event->ID(), |
|
| 156 | + 'html_name' => 'datetime_selector_' . $this->event->ID(), |
|
| 157 | + 'html_class' => 'datetime-selector', |
|
| 158 | + 'select_button_text' => '<span class="dashicons dashicons-calendar-alt"></span> ' |
|
| 159 | + . esc_html__('Select a Datetime', 'event_espresso'), |
|
| 160 | + 'other_html_attributes' => ' data-tkt_slctr_evt="' . $this->event->ID() . '"', |
|
| 161 | + ) |
|
| 162 | + ); |
|
| 163 | + return \EEH_HTML::div( |
|
| 164 | + \EEH_HTML::div( |
|
| 165 | + $dropdown_selector->get_html_for_input(), |
|
| 166 | + '', 'select-wrap-dv' |
|
| 167 | + ) |
|
| 168 | + . \EEH_HTML::br(), |
|
| 169 | + '', 'datetime_selector-dv' |
|
| 170 | + ); |
|
| 171 | + } |
|
| 172 | 172 | |
| 173 | 173 | |
| 174 | 174 | |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | if ( ! $ticket_datetime instanceof \EE_Datetime) { |
| 100 | 100 | continue; |
| 101 | 101 | } |
| 102 | - $datetimes[ $ticket_datetime->ID() ] = $ticket_datetime; |
|
| 102 | + $datetimes[$ticket_datetime->ID()] = $ticket_datetime; |
|
| 103 | 103 | } |
| 104 | 104 | return $datetimes; |
| 105 | 105 | } |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | * @return string |
| 112 | 112 | * @throws \EE_Error |
| 113 | 113 | */ |
| 114 | - public function getTicketDatetimeClasses( \EE_Ticket $ticket ) { |
|
| 114 | + public function getTicketDatetimeClasses(\EE_Ticket $ticket) { |
|
| 115 | 115 | if ( ! $this->active) { |
| 116 | 116 | return ''; |
| 117 | 117 | } |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | if ( ! $datetime instanceof \EE_Datetime || ! in_array($datetime, $ticket_datetimes, true)) { |
| 122 | 122 | continue; |
| 123 | 123 | } |
| 124 | - $classes .= ' ee-ticket-datetimes-' . $datetime->date_range('Y_m_d', '-'); |
|
| 124 | + $classes .= ' ee-ticket-datetimes-'.$datetime->date_range('Y_m_d', '-'); |
|
| 125 | 125 | } |
| 126 | 126 | $classes .= ' ee-hidden-ticket-tr'; |
| 127 | 127 | return $classes; |
@@ -145,19 +145,19 @@ discard block |
||
| 145 | 145 | } |
| 146 | 146 | $desc = $datetime->name(); |
| 147 | 147 | $desc .= ! empty($desc) |
| 148 | - ? ' ' . $datetime->date_range($date_format) |
|
| 148 | + ? ' '.$datetime->date_range($date_format) |
|
| 149 | 149 | : $datetime->date_range($date_format); |
| 150 | 150 | $datetime_options[$datetime->date_range('Y_m_d', '-')] = $desc; |
| 151 | 151 | } |
| 152 | 152 | $dropdown_selector = new \EE_Checkbox_Dropdown_Selector_Input( |
| 153 | 153 | $datetime_options, |
| 154 | 154 | array( |
| 155 | - 'html_id' => 'datetime-selector-' . $this->event->ID(), |
|
| 156 | - 'html_name' => 'datetime_selector_' . $this->event->ID(), |
|
| 155 | + 'html_id' => 'datetime-selector-'.$this->event->ID(), |
|
| 156 | + 'html_name' => 'datetime_selector_'.$this->event->ID(), |
|
| 157 | 157 | 'html_class' => 'datetime-selector', |
| 158 | 158 | 'select_button_text' => '<span class="dashicons dashicons-calendar-alt"></span> ' |
| 159 | 159 | . esc_html__('Select a Datetime', 'event_espresso'), |
| 160 | - 'other_html_attributes' => ' data-tkt_slctr_evt="' . $this->event->ID() . '"', |
|
| 160 | + 'other_html_attributes' => ' data-tkt_slctr_evt="'.$this->event->ID().'"', |
|
| 161 | 161 | ) |
| 162 | 162 | ); |
| 163 | 163 | return \EEH_HTML::div( |