Clean up multi-team schedule title code
Centralize title format validation for schedule exports and reuse it from the public URL builder. Tidy request, feed, and printable entry arrays introduced during the multi-team title work. Clarify printable calendar render naming so split-title layout is distinct from matchup title format.
This commit is contained in:
@@ -93,6 +93,15 @@ function tse_sp_event_export_get_default_columns( $format ) {
|
||||
return isset( $defaults[ $format ] ) ? $defaults[ $format ] : $defaults['matchup'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get supported event title formats.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
function tse_sp_event_export_get_title_formats() {
|
||||
return array( 'selected_first', 'matchup' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize event title format.
|
||||
*
|
||||
@@ -102,7 +111,7 @@ function tse_sp_event_export_get_default_columns( $format ) {
|
||||
function tse_sp_event_export_sanitize_title_format( $format ) {
|
||||
$format = sanitize_key( (string) $format );
|
||||
|
||||
return in_array( $format, array( 'selected_first', 'matchup' ), true ) ? $format : 'selected_first';
|
||||
return in_array( $format, tse_sp_event_export_get_title_formats(), true ) ? $format : 'selected_first';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1727,15 +1727,15 @@ if ( ! class_exists( 'Tony_Sportspress_Printable_Calendars' ) ) {
|
||||
for ( $day = 1; $day <= $days_in_month; $day++ ) {
|
||||
$day_key = sprintf( '%s-%02d', $month_key, $day );
|
||||
$day_entries = isset( $entries_by_day[ $day_key ] ) ? $entries_by_day[ $day_key ] : array();
|
||||
$has_matchup = false;
|
||||
$has_split_title = false;
|
||||
foreach ( $day_entries as $day_entry ) {
|
||||
if ( ! empty( $day_entry['is_matchup'] ) || ! empty( $day_entry['title_team_name'] ) ) {
|
||||
$has_matchup = true;
|
||||
$has_split_title = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$day_class = ! empty( $day_entries ) ? 'day has-events' : 'day no-events';
|
||||
if ( $has_matchup ) {
|
||||
if ( $has_split_title ) {
|
||||
$day_class .= ' has-matchups';
|
||||
}
|
||||
$day_style = '';
|
||||
@@ -1743,10 +1743,10 @@ 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'] ) || ! empty( $first_entry['title_team_name'] );
|
||||
$first_split_title = ! 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'] );
|
||||
$first_background = '' !== $first_venue_color ? $first_venue_color : ( $first_is_home || $first_split_title ? $team_palette['primary'] : $team_palette['secondary'] );
|
||||
$first_foreground = $this->get_readable_text_color( $first_background );
|
||||
$first_background = $this->ensure_minimum_contrast( $first_background, $first_foreground, self::MIN_WHITE_CONTRAST );
|
||||
$first_foreground = $this->get_readable_text_color( $first_background );
|
||||
|
||||
@@ -197,8 +197,15 @@ function tse_sp_schedule_exporter_render_shortcode() {
|
||||
<?php tse_sp_schedule_exporter_render_column_picker( 'team', 'public', $subformat ); ?>
|
||||
|
||||
<?php
|
||||
$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' );
|
||||
$feed_args = array(
|
||||
'team_id' => $team_ids,
|
||||
'season_id' => $season_id,
|
||||
'league_id' => $league_id,
|
||||
'field_id' => $field_id,
|
||||
'title_format' => $title_format,
|
||||
);
|
||||
$csv_url = tse_sp_event_export_get_feed_url( array_merge( $feed_args, array( 'format' => $subformat ) ), 'csv' );
|
||||
$ics_url = tse_sp_event_export_get_feed_url( $feed_args, '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 );
|
||||
?>
|
||||
@@ -588,7 +595,7 @@ function tse_sp_schedule_exporter_resolve_title_format() {
|
||||
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';
|
||||
return in_array( $value, tse_sp_event_export_get_title_formats(), true ) ? $value : 'selected_first';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user