Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter stobipole

    (@stobipole)

    Another temp addition – only show upcoming when limit is set:

    	$game_count = 0;
    foreach ($data['data'] as $game) {
    // Defensive: skip if competitors is missing or not an array
    if (!isset($game['competitors']) || !is_array($game['competitors'])) {
    continue;
    }
    $date = $game['schedule']['date'] ?? '-';
    $time = $game['schedule']['time'] ?? 'TBA';
    $round_full = $game['round']['name'] ?? '-';
    $round = preg_replace('/[^\d]/', '', $round_full);

    $game_datetime = DateTime::createFromFormat('Y-m-d H:i:s', $date . ' ' . $time, new DateTimeZone("Australia/Melbourne"));
    if ($game_datetime === false) {
    $game_datetime = null;
    }
    if (!empty($atts['limit'])) {
    $filter = 'upcoming';
    $game_limit = $atts['limit'];
    }
    if ($filter === 'upcoming' && $game_datetime && $game_datetime < $now) continue;
    if ($filter === 'past' && $game_datetime && $game_datetime > $now) continue;

    $home = $away = '-';
    $home_id = $away_id = '';
    foreach ($game['competitors'] as $team) {
    if (!isset($team['name'])) continue;
    $team_name = $team['name'];
    if ($clean_team_names) {
    $team_name = preg_replace([
    '/\s*Over\s*\d{1,2}s?/i',
    '/\s*O\d{1,2}s?/i',
    '/\s*Under\s*\d{1,2}s?/i',
    '/\s*U\d{1,2}s?/i',
    '/\s*Reserves?/i',
    '/\s*Div(?:ision)?\s*\d+/i',
    '/\s*Grade\s*\w+/i',
    '/\s*Men\'?s?/i',
    '/\s*Women\'?s?/i',
    '/\s*Mixed/i',
    ], '', $team_name);
    $team_name = trim($team_name);
    }
    if (!empty($team['isHomeTeam'])) {
    $home = $team_name;
    $home_id = $team['id'] ?? '';
    } else {
    $away = $team_name;
    $away_id = $team['id'] ?? '';
    }
    }

    // Only color and bold the selected team (home or away)
    $is_home_selected = ($home_id === $selected_team_id);
    $is_away_selected = ($away_id === $selected_team_id);

    if ($is_home_selected) {
    $home = '<span class="playhq-selected-team">' . esc_html($home) . '</span>';
    }
    if ($is_away_selected) {
    $away = '<span class="playhq-selected-team">' . esc_html($away) . '</span>';
    }

    $venue = $game['venue']['name'] ?? '-';

    $date_formatted = $game_datetime ? $game_datetime->format($date_format) : $date;
    $time_formatted = $game_datetime ? $game_datetime->format($time_format) : $time;
    $datetime_combined = trim($date_formatted . ' ' . $time_formatted);

    // Determine opponent for mobile
    $opponent = '-';
    if ($is_home_selected) {
    $opponent = $away_id ? $away : $away;
    } elseif ($is_away_selected) {
    $opponent = $home_id ? $home : $home;
    }

    $output .= "<tr>
    <td class='phq-col-datetime' data-label='" . esc_attr__('Date/Time', 'fixture-viewer-for-playhq') . "' style='display:none;'>$datetime_combined</td>
    <td class='phq-col-opponent' data-label='" . esc_attr__('Opponent', 'fixture-viewer-for-playhq') . "' style='display:none;'>$opponent</td>
    <td class='phq-col-round' data-label='" . esc_attr__('Round', 'fixture-viewer-for-playhq') . "'>$round</td>
    <td class='phq-col-date' data-label='" . esc_attr__('Date', 'fixture-viewer-for-playhq') . "'>$date_formatted</td>
    <td class='phq-col-time' data-label='" . esc_attr__('Time', 'fixture-viewer-for-playhq') . "'>$time_formatted</td>
    <td class='phq-col-home' data-label='" . esc_attr__('Home', 'fixture-viewer-for-playhq') . "'>$home</td>
    <td class='phq-col-away' data-label='" . esc_attr__('Away', 'fixture-viewer-for-playhq') . "'>$away</td>
    <td class='phq-col-venue' data-label='" . esc_attr__('Venue', 'fixture-viewer-for-playhq') . "'>$venue</td>
    </tr>";
    $game_count++;
    if ($game_count == $game_limit){
    break;
    }
    }

    $output .= '</tbody></table>';
    return '<div class="playhq-fixture-wrapper">' . $selector . $output . '</div>';
    }

    Thread Starter stobipole

    (@stobipole)

    Here’s a temp addition I’ve done to filter the returned list of teams

    $club_name = '<VALUE>';
    $teams_list = array_filter($teams_list, function($item) use ($club_name) {
    return str_contains($item['name'], $club_name);
    });
    Thread Starter stobipole

    (@stobipole)

    Hi Mark,

    Yeah, optional filter in the settings page so that way you could have a single ‘club fixtures’ page and have the drop down only populate teams from your own club, not the entire league.

    I can see scores being a good addition.

    Other one I forgot to mention was the option to limit the number of returned rounds from the fixtures in the shortcode, for example:

    [playhq_fixtures team=”<TEAM NAME>” limit=”<VALUE>”]

    If set, then it would take the current date and get the next round(s) (based on the limit set) so you can have an ‘upcoming games’ section rather than the full table.

Viewing 3 replies - 1 through 3 (of 3 total)