' . esc_html__( 'Options', 'tonys-sportspress-enhancements' ) . ' ';
echo '';
echo ' ';
@@ -542,7 +551,7 @@ if ( ! class_exists( 'Tony_Sportspress_Printable_Calendars' ) ) {
echo '';
echo '';
echo '' . esc_html__( 'Open Printable URL', 'tonys-sportspress-enhancements' ) . '
';
- echo '' . esc_html__( 'The printable route requires a single team selection.', 'tonys-sportspress-enhancements' ) . '
';
+ echo '' . esc_html__( 'The printable route requires at least one selected team.', 'tonys-sportspress-enhancements' ) . '
';
echo '';
$this->render_printable_url_builder_script();
@@ -573,18 +582,32 @@ if ( ! class_exists( 'Tony_Sportspress_Printable_Calendars' ) ) {
var paper = root.querySelector('#tse-printable-builder-paper');
var teamLabel = root.querySelector('#tse-printable-builder-team-label');
var fieldLabel = root.querySelector('#tse-printable-builder-field-label');
+ var titleFormat = root.querySelector('#tse-printable-builder-title-format');
var autoprint = root.querySelector('#tse-printable-builder-autoprint');
var monthPages = root.querySelector('#tse-printable-builder-month-pages');
var output = root.querySelector('#tse-printable-builder-output');
var copyButton = root.querySelector('#tse-printable-builder-copy');
var openLink = root.querySelector('#tse-printable-builder-open');
+ function selectedValues(select) {
+ if (!select) {
+ return [];
+ }
+
+ return Array.prototype.slice.call(select.selectedOptions || []).map(function(option){
+ return option.value;
+ }).filter(function(value){
+ return value && value !== '0';
+ });
+ }
+
function buildUrl() {
var url = new URL(baseUrl, window.location.origin);
+ var teamValues = selectedValues(team);
url.searchParams.set(queryFlag, '1');
- if (team.value && team.value !== '0') {
- url.searchParams.set('sp_team', team.value);
+ if (teamValues.length) {
+ url.searchParams.set('sp_team', teamValues.join(','));
} else {
url.searchParams.delete('sp_team');
}
@@ -619,6 +642,10 @@ if ( ! class_exists( 'Tony_Sportspress_Printable_Calendars' ) ) {
url.searchParams.set('field_label', fieldLabel.value);
}
+ if (titleFormat.value) {
+ url.searchParams.set('title_format', titleFormat.value);
+ }
+
if (autoprint.checked) {
url.searchParams.set('autoprint', '1');
} else {
@@ -633,10 +660,10 @@ if ( ! class_exists( 'Tony_Sportspress_Printable_Calendars' ) ) {
output.value = url.toString();
openLink.href = url.toString();
- openLink.toggleAttribute('disabled', !(team.value && team.value !== '0'));
+ openLink.toggleAttribute('disabled', !teamValues.length);
}
- [team, season, league, field, paper, teamLabel, fieldLabel, autoprint, monthPages].forEach(function(input){
+ [team, season, league, field, paper, teamLabel, fieldLabel, titleFormat, autoprint, monthPages].forEach(function(input){
input.addEventListener('change', buildUrl);
});
@@ -705,6 +732,7 @@ if ( ! class_exists( 'Tony_Sportspress_Printable_Calendars' ) ) {
$field_ids = $this->parse_term_ids( get_query_var( 'sp_field' ), 'sp_venue' );
$team_label_mode = $this->sanitize_label_mode( get_query_var( 'team_label' ), 'abbreviation' );
$field_label_mode = $this->sanitize_label_mode( get_query_var( 'field_label' ), $this->get_venue_label_mode() );
+ $title_format = $this->sanitize_title_format( get_query_var( 'title_format' ) );
$paper = $this->normalize_paper_size( (string) get_query_var( 'paper' ) );
$autoprint = '1' === (string) get_query_var( 'autoprint' );
@@ -719,7 +747,7 @@ if ( ! class_exists( 'Tony_Sportspress_Printable_Calendars' ) ) {
$qr_url = 'https://api.qrserver.com/v1/create-qr-code/?size=144x144&data=' . rawurlencode( $site_url );
$season_name = '';
$field_name = count( $field_ids ) === 1 ? $this->get_term_label( (int) $field_ids[0], 'sp_venue', $field_label_mode ) : '';
- $entries = $this->get_schedule_entries( $team_ids, $season_id, $league_id, $field_ids, $team_label_mode, $field_label_mode );
+ $entries = $this->get_schedule_entries( $team_ids, $season_id, $league_id, $field_ids, $team_label_mode, $field_label_mode, $title_format );
$team_palette = $is_multi_team ? $this->get_default_printable_palette() : $this->get_team_color_palette( $primary_team_id );
$team_primary_for_fields = $is_multi_team ? '' : $this->get_strict_team_primary_color( $primary_team_id );
$entries_by_day = array();
@@ -897,7 +925,7 @@ if ( ! class_exists( 'Tony_Sportspress_Printable_Calendars' ) ) {
* @param string $paper Paper size.
* @return string
*/
- private function build_url( $team_id, $season_id, $paper, $league_id = 0, $field_id = 0, $month_pages = false, $team_label_mode = 'name', $field_label_mode = '' ) {
+ private function build_url( $team_id, $season_id, $paper, $league_id = 0, $field_id = 0, $month_pages = false, $team_label_mode = 'name', $field_label_mode = '', $title_format = 'selected_first' ) {
$paper = $this->normalize_paper_size( $paper );
$field_label_mode = '' === $field_label_mode ? $this->get_venue_label_mode() : $field_label_mode;
@@ -910,6 +938,7 @@ if ( ! class_exists( 'Tony_Sportspress_Printable_Calendars' ) ) {
'sp_field' => $field_id > 0 ? (string) absint( $field_id ) : '',
'team_label' => $this->sanitize_label_mode( $team_label_mode, 'name' ),
'field_label' => $this->sanitize_label_mode( $field_label_mode, $this->get_venue_label_mode() ),
+ 'title_format' => $this->sanitize_title_format( $title_format ),
'paper' => (string) $paper,
'month_pages' => $month_pages ? '1' : '',
),
@@ -1124,6 +1153,31 @@ if ( ! class_exists( 'Tony_Sportspress_Printable_Calendars' ) ) {
return $this->sanitize_label_mode( $value, 'name' );
}
+ /**
+ * Get supported event title formats.
+ *
+ * @return array
+ */
+ private function get_title_format_options() {
+ return array(
+ 'selected_first' => __( 'Selected Teams First', 'tonys-sportspress-enhancements' ),
+ 'matchup' => __( 'Matchup', 'tonys-sportspress-enhancements' ),
+ );
+ }
+
+ /**
+ * Sanitize event title format.
+ *
+ * @param mixed $value Raw value.
+ * @return string
+ */
+ private function sanitize_title_format( $value ) {
+ $format = is_string( $value ) ? sanitize_key( $value ) : '';
+ $options = array_keys( $this->get_title_format_options() );
+
+ return in_array( $format, $options, true ) ? $format : 'selected_first';
+ }
+
/**
* Whether SportsPress is available.
*
@@ -1384,13 +1438,14 @@ if ( ! class_exists( 'Tony_Sportspress_Printable_Calendars' ) ) {
* @param int[] $field_ids Field IDs.
* @return array
*/
- private function get_schedule_entries( $team_ids, $season_id, $league_id = 0, $field_ids = array(), $team_label_mode = 'abbreviation', $field_label_mode = '' ) {
+ private function get_schedule_entries( $team_ids, $season_id, $league_id = 0, $field_ids = array(), $team_label_mode = 'abbreviation', $field_label_mode = '', $title_format = 'selected_first' ) {
$team_ids = is_array( $team_ids ) ? array_values( array_filter( array_map( 'absint', $team_ids ) ) ) : array( absint( $team_ids ) );
$primary_team = isset( $team_ids[0] ) ? (int) $team_ids[0] : 0;
$is_multi_team = count( $team_ids ) > 1;
$field_ids = is_array( $field_ids ) ? array_values( array_filter( array_map( 'absint', $field_ids ) ) ) : array();
$team_label_mode = $this->sanitize_label_mode( $team_label_mode, 'abbreviation' );
$field_label_mode = '' === $field_label_mode ? $this->get_venue_label_mode() : $this->sanitize_label_mode( $field_label_mode, $this->get_venue_label_mode() );
+ $title_format = $this->sanitize_title_format( $title_format );
if ( empty( $team_ids ) ) {
return array();
@@ -1478,6 +1533,7 @@ if ( ! class_exists( 'Tony_Sportspress_Printable_Calendars' ) ) {
}
}
}
+ $title_data = $this->get_event_title_data( $home_id, $away_id, $team_ids, $team_label_mode, $title_format );
$venue = $this->get_event_venue_term( $event_id );
$venue_name = '';
@@ -1495,9 +1551,12 @@ if ( ! class_exists( 'Tony_Sportspress_Printable_Calendars' ) ) {
'month_key' => wp_date( 'Y-m', $timestamp ),
'timestamp' => $timestamp,
'is_home' => ! $is_multi_team && $home_id === $context_id,
- 'is_matchup' => $is_multi_team,
+ 'is_matchup' => 'matchup' === $title_format,
'opponent_id' => $opponent_id,
'opponent_name' => $opponent_id > 0 ? $this->get_team_label( $opponent_id, $team_label_mode ) : __( 'TBD', 'tonys-sportspress-enhancements' ),
+ 'title_team_name' => $title_data['team_name'],
+ 'title_separator' => $title_data['separator'],
+ 'title_opponent_name' => $title_data['opponent_name'],
'home_team_id' => $home_id,
'away_team_id' => $away_id,
'home_team_name' => $home_id > 0 ? $this->get_team_label( $home_id, $team_label_mode ) : __( 'TBD', 'tonys-sportspress-enhancements' ),
@@ -1547,6 +1606,91 @@ if ( ! class_exists( 'Tony_Sportspress_Printable_Calendars' ) ) {
return $months;
}
+ /**
+ * Get event title parts for the selected title format.
+ *
+ * @param int $home_id Home team ID.
+ * @param int $away_id Away team ID.
+ * @param int[] $selected_ids Selected team IDs.
+ * @param string $team_label_mode Team label mode.
+ * @param string $title_format Title format.
+ * @return array
+ */
+ private function get_event_title_data( $home_id, $away_id, $selected_ids, $team_label_mode, $title_format ) {
+ $home_id = absint( $home_id );
+ $away_id = absint( $away_id );
+ $selected_ids = array_values( array_filter( array_map( 'absint', (array) $selected_ids ) ) );
+ $title_format = $this->sanitize_title_format( $title_format );
+
+ if ( 'matchup' === $title_format ) {
+ return array(
+ 'team_name' => $away_id > 0 ? $this->get_team_label( $away_id, $team_label_mode ) : __( 'TBD', 'tonys-sportspress-enhancements' ),
+ 'separator' => 'at',
+ 'opponent_name' => $home_id > 0 ? $this->get_team_label( $home_id, $team_label_mode ) : __( 'TBD', 'tonys-sportspress-enhancements' ),
+ );
+ }
+
+ $context = $this->get_selected_team_context( $home_id, $away_id, $selected_ids );
+ if ( empty( $context['team_id'] ) ) {
+ return array(
+ 'team_name' => '',
+ 'separator' => '',
+ 'opponent_name' => '',
+ );
+ }
+
+ $opponent_id = isset( $context['opponent_id'] ) ? (int) $context['opponent_id'] : 0;
+ if ( 1 === count( $selected_ids ) ) {
+ return array(
+ 'team_name' => '',
+ 'separator' => '',
+ 'opponent_name' => $opponent_id > 0 ? $this->get_team_label( $opponent_id, $team_label_mode ) : __( 'TBD', 'tonys-sportspress-enhancements' ),
+ );
+ }
+
+ return array(
+ 'team_name' => $this->get_team_label( (int) $context['team_id'], $team_label_mode ),
+ 'separator' => isset( $context['separator'] ) ? (string) $context['separator'] : '',
+ 'opponent_name' => $opponent_id > 0 ? $this->get_team_label( $opponent_id, $team_label_mode ) : __( 'TBD', 'tonys-sportspress-enhancements' ),
+ );
+ }
+
+ /**
+ * Get selected-team perspective for an event.
+ *
+ * @param int $home_id Home team ID.
+ * @param int $away_id Away team ID.
+ * @param int[] $selected_ids Selected team IDs.
+ * @return array
+ */
+ private function get_selected_team_context( $home_id, $away_id, $selected_ids ) {
+ $home_id = absint( $home_id );
+ $away_id = absint( $away_id );
+ $selected_ids = array_values( array_filter( array_map( 'absint', (array) $selected_ids ) ) );
+
+ if ( $away_id > 0 && in_array( $away_id, $selected_ids, true ) ) {
+ return array(
+ 'team_id' => $away_id,
+ 'opponent_id' => $home_id,
+ 'separator' => 'at',
+ );
+ }
+
+ if ( $home_id > 0 && in_array( $home_id, $selected_ids, true ) ) {
+ return array(
+ 'team_id' => $home_id,
+ 'opponent_id' => $away_id,
+ 'separator' => 'vs',
+ );
+ }
+
+ return array(
+ 'team_id' => 0,
+ 'opponent_id' => 0,
+ 'separator' => '',
+ );
+ }
+
/**
* Render a single month grid.
*
@@ -1585,7 +1729,7 @@ if ( ! class_exists( 'Tony_Sportspress_Printable_Calendars' ) ) {
$day_entries = isset( $entries_by_day[ $day_key ] ) ? $entries_by_day[ $day_key ] : array();
$has_matchup = false;
foreach ( $day_entries as $day_entry ) {
- if ( ! empty( $day_entry['is_matchup'] ) || $is_multi_team ) {
+ if ( ! empty( $day_entry['is_matchup'] ) || ! empty( $day_entry['title_team_name'] ) ) {
$has_matchup = true;
break;
}
@@ -1599,7 +1743,7 @@ if ( ! class_exists( 'Tony_Sportspress_Printable_Calendars' ) ) {
if ( ! empty( $day_entries ) ) {
$first_entry = $day_entries[0];
$first_is_home = ! empty( $first_entry['is_home'] );
- $first_is_matchup = ! empty( $first_entry['is_matchup'] ) || $is_multi_team;
+ $first_is_matchup = ! empty( $first_entry['is_matchup'] ) || ! empty( $first_entry['title_team_name'] );
$first_venue_key = isset( $first_entry['venue_key'] ) && is_string( $first_entry['venue_key'] ) ? $first_entry['venue_key'] : '';
$first_venue_color = ( '' !== $first_venue_key && isset( $venue_colors[ $first_venue_key ]['color'] ) ) ? (string) $venue_colors[ $first_venue_key ]['color'] : '';
$first_background = '' !== $first_venue_color ? $first_venue_color : ( $first_is_home || $first_is_matchup ? $team_palette['primary'] : $team_palette['secondary'] );
@@ -1617,14 +1761,15 @@ if ( ! class_exists( 'Tony_Sportspress_Printable_Calendars' ) ) {
echo '';
foreach ( $day_entries as $entry ) {
$is_home = ! empty( $entry['is_home'] );
- $is_matchup = ! empty( $entry['is_matchup'] ) || $is_multi_team;
- $event_class = $is_matchup ? 'matchup' : ( $is_home ? 'h' : 'a' );
+ $is_matchup = ! empty( $entry['is_matchup'] );
+ $uses_split_title = $is_matchup || ! empty( $entry['title_team_name'] );
+ $event_class = $uses_split_title ? 'matchup' : ( $is_home ? 'h' : 'a' );
$venue_key = isset( $entry['venue_key'] ) && is_string( $entry['venue_key'] ) ? $entry['venue_key'] : '';
$venue_color = ( '' !== $venue_key && isset( $venue_colors[ $venue_key ]['color'] ) ) ? (string) $venue_colors[ $venue_key ]['color'] : '';
$opponent_id = isset( $entry['opponent_id'] ) ? (int) $entry['opponent_id'] : 0;
- $logo = ( ! $is_matchup && $opponent_id > 0 ) ? get_the_post_thumbnail( $opponent_id, 'medium', array( 'class' => 'event-logo-img', 'loading' => 'eager', 'decoding' => 'async' ) ) : '';
+ $logo = ( ! $uses_split_title && $opponent_id > 0 ) ? get_the_post_thumbnail( $opponent_id, 'medium', array( 'class' => 'event-logo-img', 'loading' => 'eager', 'decoding' => 'async' ) ) : '';
$has_logo = '' !== $logo;
- $event_background = '' !== $venue_color ? $venue_color : ( $is_home || $is_matchup ? $team_palette['primary'] : $team_palette['secondary'] );
+ $event_background = '' !== $venue_color ? $venue_color : ( $is_home || $uses_split_title ? $team_palette['primary'] : $team_palette['secondary'] );
$event_foreground = $this->get_readable_text_color( $event_background );
$event_background = $this->ensure_minimum_contrast( $event_background, $event_foreground, self::MIN_WHITE_CONTRAST );
$event_foreground = $this->get_readable_text_color( $event_background );
@@ -1635,16 +1780,17 @@ if ( ! class_exists( 'Tony_Sportspress_Printable_Calendars' ) ) {
if ( $has_logo ) {
echo wp_kses_post( $logo );
} else {
- if ( $is_matchup ) {
- $away_name = isset( $entry['away_team_name'] ) ? (string) $entry['away_team_name'] : __( 'TBD', 'tonys-sportspress-enhancements' );
- $home_name = isset( $entry['home_team_name'] ) ? (string) $entry['home_team_name'] : __( 'TBD', 'tonys-sportspress-enhancements' );
- echo '' . esc_html( $away_name ) . ' ' . esc_html__( 'vs', 'tonys-sportspress-enhancements' ) . ' ' . esc_html( $home_name ) . ' ';
+ if ( $uses_split_title ) {
+ $team_name = isset( $entry['title_team_name'] ) ? (string) $entry['title_team_name'] : __( 'TBD', 'tonys-sportspress-enhancements' );
+ $separator = isset( $entry['title_separator'] ) ? (string) $entry['title_separator'] : 'at';
+ $opponent_name = isset( $entry['title_opponent_name'] ) ? (string) $entry['title_opponent_name'] : __( 'TBD', 'tonys-sportspress-enhancements' );
+ echo '' . esc_html( $team_name ) . ' ' . esc_html( $separator ) . ' ' . esc_html( $opponent_name ) . ' ';
} else {
- echo '' . esc_html( isset( $entry['opponent_name'] ) ? (string) $entry['opponent_name'] : '' ) . ' ';
+ echo '' . esc_html( isset( $entry['title_opponent_name'] ) ? (string) $entry['title_opponent_name'] : '' ) . ' ';
}
}
echo '
';
- if ( ! $is_matchup ) {
+ if ( ! $uses_split_title ) {
echo '' . esc_html( $is_home ? 'H' : 'A' ) . ' ';
}
echo '
+
+
@@ -127,7 +134,7 @@ function tse_sp_schedule_exporter_render_shortcode() {
-
+
@@ -162,7 +169,7 @@ function tse_sp_schedule_exporter_render_shortcode() {
-
+
@@ -190,9 +197,9 @@ function tse_sp_schedule_exporter_render_shortcode() {
$team_ids, 'season_id' => $season_id, 'league_id' => $league_id, 'field_id' => $field_id, 'format' => $subformat ), 'csv' );
- $ics_url = tse_sp_event_export_get_feed_url( array( 'team_id' => $team_ids, 'season_id' => $season_id, 'league_id' => $league_id, 'field_id' => $field_id ), 'ics' );
- $print_url = tse_sp_schedule_exporter_get_printable_url( $team_ids, $season_id, 'letter', $league_id, false, $field_id );
+ $csv_url = tse_sp_event_export_get_feed_url( array( 'team_id' => $team_ids, 'season_id' => $season_id, 'league_id' => $league_id, 'field_id' => $field_id, 'format' => $subformat, 'title_format' => $title_format ), 'csv' );
+ $ics_url = tse_sp_event_export_get_feed_url( array( 'team_id' => $team_ids, 'season_id' => $season_id, 'league_id' => $league_id, 'field_id' => $field_id, 'title_format' => $title_format ), 'ics' );
+ $print_url = tse_sp_schedule_exporter_get_printable_url( $team_ids, $season_id, 'letter', $league_id, false, $field_id, false, 'name', 'name', $title_format );
$current_url = tse_sp_schedule_exporter_get_output_url( $export_type, $csv_url, $ics_url, $print_url );
?>
@@ -561,6 +568,29 @@ function tse_sp_schedule_exporter_resolve_subformat() {
return tse_sp_event_export_sanitize_format( $requested );
}
+/**
+ * Resolve selected title format.
+ *
+ * @return string
+ */
+function tse_sp_schedule_exporter_resolve_title_format() {
+ $requested = isset( $_GET['title_format'] ) ? sanitize_key( wp_unslash( $_GET['title_format'] ) ) : 'selected_first';
+
+ return tse_sp_schedule_exporter_resolve_title_format_value( $requested );
+}
+
+/**
+ * Normalize a title format value.
+ *
+ * @param string $value Raw value.
+ * @return string
+ */
+function tse_sp_schedule_exporter_resolve_title_format_value( $value ) {
+ $value = sanitize_key( (string) $value );
+
+ return in_array( $value, array( 'selected_first', 'matchup' ), true ) ? $value : 'selected_first';
+}
+
/**
* Get current output URL for the selected export type.
*
@@ -720,9 +750,10 @@ function tse_sp_schedule_exporter_get_primary_venue( $event_id ) {
* @param int $league_id League ID.
* @param string $team_label_mode Team label mode.
* @param string $field_label_mode Field label mode.
+ * @param string $title_format Title format.
* @return string
*/
-function tse_sp_schedule_exporter_get_printable_url( $team_id, $season_id, $paper, $league_id = 0, $autoprint = false, $field_id = 0, $month_pages = false, $team_label_mode = 'name', $field_label_mode = 'name' ) {
+function tse_sp_schedule_exporter_get_printable_url( $team_id, $season_id, $paper, $league_id = 0, $autoprint = false, $field_id = 0, $month_pages = false, $team_label_mode = 'name', $field_label_mode = 'name', $title_format = 'selected_first' ) {
$team_ids = is_array( $team_id ) ? array_values( array_filter( array_map( 'absint', $team_id ) ) ) : array( absint( $team_id ) );
return add_query_arg(
@@ -734,6 +765,7 @@ function tse_sp_schedule_exporter_get_printable_url( $team_id, $season_id, $pape
'sp_field' => $field_id > 0 ? (string) absint( $field_id ) : '',
'team_label' => sanitize_key( (string) $team_label_mode ),
'field_label' => sanitize_key( (string) $field_label_mode ),
+ 'title_format' => tse_sp_schedule_exporter_resolve_title_format_value( $title_format ),
'paper' => $paper,
'autoprint' => $autoprint ? '1' : '',
'month_pages' => $month_pages ? '1' : '',
@@ -787,6 +819,7 @@ function tse_sp_schedule_exporter_render_link_sync_script( $echo = false ) {
var team = form.querySelector('[name="team_id[]"], [name="team_id"]');
var exportType = form.querySelector('[name="export_type"]');
var subformat = form.querySelector('[name="subformat"]');
+ var titleFormat = form.querySelector('[name="title_format"]');
var field = form.querySelector('[name="field_id"]');
var monthPages = form.querySelector('[name="month_pages"]');
var outputUrl = scope.querySelector('.tse-output-url');
@@ -806,12 +839,6 @@ function tse_sp_schedule_exporter_render_link_sync_script( $echo = false ) {
var teamValue = teamValues.length ? teamValues.join(',') : '0';
var activeSubformat = subformat ? (subformat.value || 'matchup') : 'matchup';
var selectedExportType = exportType ? (exportType.value || 'csv') : 'csv';
- if (teamValues.length > 1 && activeSubformat === 'team') {
- activeSubformat = 'matchup';
- if (subformat) {
- subformat.value = 'matchup';
- }
- }
scope.querySelectorAll('[data-column-group]').forEach(function(group){
var visible = selectedExportType === 'csv' && group.getAttribute('data-column-group') === activeSubformat;
@@ -833,6 +860,7 @@ function tse_sp_schedule_exporter_render_link_sync_script( $echo = false ) {
if (season) csvUrl.searchParams.set('season_id', season.value || '0');
if (team) csvUrl.searchParams.set('team_id', teamValue);
if (field) csvUrl.searchParams.set('field_id', field.value || '0');
+ if (titleFormat) csvUrl.searchParams.set('title_format', titleFormat.value || 'selected_first');
csvUrl.searchParams.set('format', activeSubformat);
var columns = Array.prototype.slice.call(scope.querySelectorAll('[data-columns-format="' + activeSubformat + '"]:checked')).map(function(input){
return input.value;
@@ -849,6 +877,7 @@ function tse_sp_schedule_exporter_render_link_sync_script( $echo = false ) {
if (season) icsUrl.searchParams.set('season_id', season.value || '0');
if (team) icsUrl.searchParams.set('team_id', teamValue);
if (field) icsUrl.searchParams.set('field_id', field.value || '0');
+ if (titleFormat) icsUrl.searchParams.set('title_format', titleFormat.value || 'selected_first');
icsUrl.searchParams.delete('format');
icsUrl.searchParams.delete('columns');
}
@@ -858,6 +887,7 @@ function tse_sp_schedule_exporter_render_link_sync_script( $echo = false ) {
if (season) printUrl.searchParams.set('sp_season', season.value || '0');
if (team) printUrl.searchParams.set('sp_team', teamValue);
if (field) printUrl.searchParams.set('sp_field', field.value || '0');
+ if (titleFormat) printUrl.searchParams.set('title_format', titleFormat.value || 'selected_first');
if (monthPages && monthPages.checked) {
printUrl.searchParams.set('month_pages', '1');
} else {
@@ -884,7 +914,7 @@ function tse_sp_schedule_exporter_render_link_sync_script( $echo = false ) {
}
} else if (selectedExportType === 'csv' && activeSubformat === 'team' && teamValue === '0') {
disabled = true;
- note = 'CSV team layout requires one selected team.';
+ note = 'CSV team layout requires at least one selected team.';
}
if (outputUrl) {
diff --git a/tests/test-sp-schedule-exporter.php b/tests/test-sp-schedule-exporter.php
index b15ef82..31422ff 100644
--- a/tests/test-sp-schedule-exporter.php
+++ b/tests/test-sp-schedule-exporter.php
@@ -112,6 +112,7 @@ class Test_SP_Schedule_Exporter extends WP_UnitTestCase {
$this->assertSame( '90', $query['sp_field'] );
$this->assertSame( 'name', $query['team_label'] );
$this->assertSame( 'name', $query['field_label'] );
+ $this->assertSame( 'selected_first', $query['title_format'] );
$this->assertSame( '1', $query['month_pages'] );
}
@@ -172,9 +173,94 @@ class Test_SP_Schedule_Exporter extends WP_UnitTestCase {
}
/**
- * Multi-team printable entries should return one matchup row per event.
+ * Team CSV layout should support multiple selected teams with away-first context.
*/
- public function test_printable_multi_team_entries_are_matchup_rows() {
+ public function test_team_export_multiple_selected_teams_uses_away_team_first() {
+ $home_id = $this->create_team( 'Home Team' );
+ $away_id = $this->create_team( 'Away Team' );
+ $this->create_event( $home_id, $away_id );
+
+ $events = tse_sp_event_export_get_events(
+ array(
+ 'team_ids' => array( $home_id, $away_id ),
+ )
+ );
+
+ $this->assertCount( 1, $events );
+ $this->assertSame( 'Away Team', $events[0]['team_name'] );
+ $this->assertSame( 'Away Team at Home Team', $events[0]['title'] );
+ $this->assertSame( 'at', $events[0]['separator'] );
+ $this->assertSame( 'Home Team', $events[0]['opponent_name'] );
+ $this->assertSame( 'Away', $events[0]['location_flag'] );
+ }
+
+ /**
+ * Team CSV layout should use vs when the selected team is home.
+ */
+ public function test_team_export_home_selected_team_uses_vs_separator() {
+ $home_id = $this->create_team( 'Home Team' );
+ $away_id = $this->create_team( 'Away Team' );
+ $this->create_event( $home_id, $away_id );
+
+ $events = tse_sp_event_export_get_events(
+ array(
+ 'team_ids' => array( $home_id ),
+ )
+ );
+
+ $this->assertCount( 1, $events );
+ $this->assertSame( 'Home Team', $events[0]['team_name'] );
+ $this->assertSame( 'Away Team', $events[0]['title'] );
+ $this->assertSame( 'vs', $events[0]['separator'] );
+ $this->assertSame( 'Away Team', $events[0]['opponent_name'] );
+ $this->assertSame( 'Home', $events[0]['location_flag'] );
+ }
+
+ /**
+ * Team CSV layout should use at when the selected team is away.
+ */
+ public function test_team_export_away_selected_team_uses_at_separator() {
+ $home_id = $this->create_team( 'Home Team' );
+ $away_id = $this->create_team( 'Away Team' );
+ $this->create_event( $home_id, $away_id );
+
+ $events = tse_sp_event_export_get_events(
+ array(
+ 'team_ids' => array( $away_id ),
+ )
+ );
+
+ $this->assertCount( 1, $events );
+ $this->assertSame( 'Away Team', $events[0]['team_name'] );
+ $this->assertSame( 'Home Team', $events[0]['title'] );
+ $this->assertSame( 'at', $events[0]['separator'] );
+ $this->assertSame( 'Home Team', $events[0]['opponent_name'] );
+ $this->assertSame( 'Away', $events[0]['location_flag'] );
+ }
+
+ /**
+ * Matchup title format should ignore selected-team perspective.
+ */
+ public function test_team_export_matchup_title_format_uses_away_at_home() {
+ $home_id = $this->create_team( 'Home Team' );
+ $away_id = $this->create_team( 'Away Team' );
+ $this->create_event( $home_id, $away_id );
+
+ $events = tse_sp_event_export_get_events(
+ array(
+ 'team_ids' => array( $home_id ),
+ 'title_format' => 'matchup',
+ )
+ );
+
+ $this->assertCount( 1, $events );
+ $this->assertSame( 'Away Team at Home Team', $events[0]['title'] );
+ }
+
+ /**
+ * Multi-team printable entries should use selected-team-first titles by default.
+ */
+ public function test_printable_multi_team_entries_use_selected_first_titles() {
$home_id = $this->create_team( 'Home Team' );
$away_id = $this->create_team( 'Away Team' );
$venue_id = self::factory()->term->create( array( 'taxonomy' => 'sp_venue', 'name' => 'North Field' ) );
@@ -187,9 +273,10 @@ class Test_SP_Schedule_Exporter extends WP_UnitTestCase {
$entries = $method->invoke( $printable, array( $home_id, $away_id ), 0, 0, array() );
$this->assertCount( 1, $entries );
- $this->assertTrue( $entries[0]['is_matchup'] );
- $this->assertSame( 'Away Team', $entries[0]['away_team_name'] );
- $this->assertSame( 'Home Team', $entries[0]['home_team_name'] );
+ $this->assertFalse( $entries[0]['is_matchup'] );
+ $this->assertSame( 'Away Team', $entries[0]['title_team_name'] );
+ $this->assertSame( 'at', $entries[0]['title_separator'] );
+ $this->assertSame( 'Home Team', $entries[0]['title_opponent_name'] );
}
/**