// ========================================================================= // 29. SHORTCODE: Special Coach Profile /coach-profile/ // ========================================================================= add_shortcode('otg_coach_profile', 'otg_render_coach_profile'); function otg_render_coach_profile($atts) { global $wpdb; $a = shortcode_atts(array('id' => 0), $atts, 'otg_coach_profile'); $coach_id = isset($_GET['coach_id']) ? intval($_GET['coach_id']) : intval($a['id']); if (!$coach_id) return "Coach ID required."; $c = $wpdb->get_row($wpdb->prepare("SELECT * FROM otg_coach WHERE CoachID = %d", $coach_id)); if (!$c) return "Coach not found."; // --- Coach Rank Calculation (Joining otg_coach with otg_coach_statistics for NYR only) --- // Groups coaching stints by Season first, then CoachID. $ranked_stints = $wpdb->get_results( "SELECT CoachID, Season FROM otg_coach_statistics WHERE Team = 'New York Rangers' GROUP BY Season, CoachID ORDER BY Season ASC, CoachID ASC" ); // Group stints by season to handle multiple coaches in the same season $season_to_coaches = []; foreach ($ranked_stints as $stint) { $c_id = intval($stint->CoachID); $season_str = $stint->Season; $season_to_coaches[$season_str][$c_id] = true; } // Get all unique seasons sorted chronologically first $all_seasons = array_keys($season_to_coaches); sort($all_seasons); // Build chronological list of active coaches per season, resolving multi-coach tie-breaks $chronological_stints = []; foreach ($all_seasons as $i => $season_str) { $coaches_in_season = array_keys($season_to_coaches[$season_str]); sort($coaches_in_season); // Default fallback: lowest CoachID first if (count($coaches_in_season) > 1) { $resolved_order = []; $unresolved = $coaches_in_season; // 1. Check previous season to see who coached then (put them first) if ($i > 0) { $prev_season = $all_seasons[$i - 1]; $prev_coaches = $season_to_coaches[$prev_season]; foreach ($unresolved as $key => $c_id) { if (isset($prev_coaches[$c_id])) { $resolved_order[] = $c_id; unset($unresolved[$key]); } } $unresolved = array_values($unresolved); } // 2. Check next season to see who coaches next (put them last among remaining) if ($i < count($all_seasons) - 1 && count($unresolved) > 1) { $next_season = $all_seasons[$i + 1]; $next_coaches = $season_to_coaches[$next_season]; $matched_next = []; foreach ($unresolved as $key => $c_id) { if (isset($next_coaches[$c_id])) { $matched_next[] = $c_id; unset($unresolved[$key]); } } $unresolved = array_values($unresolved); // Append remaining unresolved, then the next-season coaches at the very end $coaches_in_season = array_merge($resolved_order, $unresolved, $matched_next); } else { $coaches_in_season = array_merge($resolved_order, $unresolved); } } foreach ($coaches_in_season as $c_id) { $chronological_stints[] = ['CoachID' => $c_id, 'Season' => $season_str]; } } // --- RANK 1: CoachID Order (Chronological appearance of each unique coach) --- $unique_coach_ranks = []; $coach_counter = 1; foreach ($chronological_stints as $stint) { $c_id = intval($stint['CoachID']); if (!isset($unique_coach_ranks[$c_id])) { $unique_coach_ranks[$c_id] = $coach_counter; $coach_counter++; } } $primary_coach_rank = isset($unique_coach_ranks[$coach_id]) ? $unique_coach_ranks[$coach_id] : null; // --- RANK 2: Stint / Tenure Order (Collapsing consecutive seasons into tenure blocks) --- $coach_tenures = []; $current_coach = null; $last_season_start = null; $current_tenure_id = null; foreach ($chronological_stints as $stint) { $c_id = intval($stint['CoachID']); $season_str = $stint['Season']; $season_start = intval(substr($season_str, 0, 4)); if ($current_coach !== $c_id || $last_season_start === null || $season_start !== ($last_season_start + 1)) { $current_tenure_id = $c_id . '_' . $season_start; $current_coach = $c_id; } $coach_tenures[$c_id][$season_str] = $current_tenure_id; $last_season_start = $season_start; } $unique_tenure_ranks = []; $global_rank = 1; foreach ($coach_tenures as $c_id => $seasons) { $tenure_map = []; foreach ($seasons as $season_str => $tenure_id) { if (!isset($tenure_map[$tenure_id])) { $tenure_map[$tenure_id] = $global_rank; $global_rank++; } $unique_tenure_ranks[$c_id][$season_str] = $tenure_map[$tenure_id]; } } // Fetch all coaches for the dropdown pivot selector (ordered alphabetically by name) $all_coaches = $wpdb->get_results("SELECT CoachID, Name FROM otg_coach ORDER BY Name ASC"); // Query stats based on CoachID $stats = $wpdb->get_results($wpdb->prepare("SELECT * FROM otg_coach_statistics WHERE CoachID = %d ORDER BY Season ASC", $coach_id)); // --- Bio Calculations & Career Totals Logic --- $bday = (empty($c->Birthday) || $c->Birthday === '1800-01-01') ? '-' : (new DateTime($c->Birthday))->format('F jS, Y'); $birthplace = esc_html($c->Birthplace) . (!empty($c->State) ? ' ' . esc_html($c->State) : ''); $scf_season_display = []; $sc_season_display = []; $coach_rank_displays = []; // Accumulators for NYR career totals $reg_w = 0; $reg_l = 0; $reg_t = 0; $reg_ot = 0; $play_w = 0; $play_l = 0; $play_t = 0; $total_sw = 0; $total_sl = 0; if (!empty($stats)) { foreach ($stats as $s) { $y1 = substr($s->Season, 0, 4); $y2 = str_pad((int)substr($s->Season, 0, 4) + 1, 4, '0', STR_PAD_LEFT); $disp_season = $y1 . '-' . substr($y2, 2, 2); $season_url = esc_url(home_url('/schedule/?season=' . $disp_season)); $season_link_html = '' . $disp_season . ''; // Gather rank for each NYR tenure stint, tracking start and end seasons if ($s->Team === 'New York Rangers' && isset($unique_tenure_ranks[$coach_id][$s->Season])) { $rank_num = $unique_tenure_ranks[$coach_id][$s->Season]; if (!isset($coach_rank_displays[$rank_num])) { $coach_rank_displays[$rank_num] = [ 'rank' => $rank_num, 'start' => $disp_season, 'end' => $disp_season ]; } else { $coach_rank_displays[$rank_num]['end'] = $disp_season; } } if (isset($s->SCF) && intval($s->SCF) == 1) { if ($s->Team === 'New York Rangers') { $scf_season_display[] = $season_link_html; } else { $scf_season_display[] = $disp_season; } } if (isset($s->SC) && intval($s->SC) == 1) { if ($s->Team === 'New York Rangers') { $sc_season_display[] = $season_link_html; } else { $sc_season_display[] = $disp_season; } } // Only accumulate stats where the team is New York Rangers if ($s->Team === 'New York Rangers') { if (isset($s->SW)) { $total_sw += intval($s->SW); } if (isset($s->SL)) { $total_sl += intval($s->SL); } // Regular Season totals accumulation $reg_w += isset($s->W) ? intval($s->W) : 0; $reg_l += isset($s->L) ? intval($s->L) : 0; $reg_t += isset($s->T) ? intval($s->T) : 0; $reg_ot += isset($s->OT) ? intval($s->OT) : 0; // Playoff totals accumulation $play_w += isset($s->PW) ? intval($s->PW) : 0; $play_l += isset($s->PL) ? intval($s->PL) : 0; $play_t += isset($s->PT) ? intval($s->PT) : 0; } } } // Format Stint rank strings (e.g. "#5 (2012-13)" or "#5 (2012-13 – 2014-15)") $formatted_stint_ranks = []; foreach ($coach_rank_displays as $stint_info) { $span = ($stint_info['start'] === $stint_info['end']) ? $stint_info['start'] : $stint_info['start'] . ' – ' . $stint_info['end']; $formatted_stint_ranks[] = '#' . $stint_info['rank'] . ' (' . $span . ')'; } if (empty($formatted_stint_ranks)) { $earlier_coaches_count = $wpdb->get_var( "SELECT COUNT(DISTINCT c.CoachID) FROM otg_coach c INNER JOIN otg_coach_statistics s ON c.CoachID = s.CoachID WHERE s.Team = 'New York Rangers' AND c.CoachID < " . intval($coach_id) ); $formatted_stint_ranks[] = '#' . (intval($earlier_coaches_count) + 1); } // Format Coach rank string $formatted_coach_rank = $primary_coach_rank ? '#' . $primary_coach_rank : '-'; // Format Regular Season Record $reg_record_parts = [$reg_w, $reg_l]; if ($reg_t > 0) $reg_record_parts[] = $reg_t; if ($reg_ot > 0) $reg_record_parts[] = $reg_ot; $reg_record_display = implode('–', $reg_record_parts); if (empty($reg_record_display)) { $reg_record_display = '0–0'; } // Format Playoff Record $play_record_parts = [$play_w, $play_l]; if ($play_t > 0) $play_record_parts[] = $play_t; $play_record_display = implode('–', $play_record_parts); if (empty($play_record_display)) { $play_record_display = '0–0'; } // Format Playoff Series Record $series_record_display = "{$total_sw}–{$total_sl}"; $data = []; $data[] = ['Birthday', $bday]; $data[] = ['Birthplace', $birthplace]; $data[] = ['Coach', $formatted_coach_rank]; $data[] = ['Stint', implode(', ', $formatted_stint_ranks)]; $data[] = ['NYR Regular Season Record', $reg_record_display]; $data[] = ['NYR Playoff Record', $play_record_display]; $data[] = ['NYR Playoff Series Record', $series_record_display]; if (!empty($sc_season_display)) { $data[] = ['Stanley Cups', implode(', ', $sc_season_display)]; } if (!empty($scf_season_display)) { $filtered_scf_display = []; foreach ($stats as $s) { if (isset($s->SCF) && intval($s->SCF) == 1) { $y1 = substr($s->Season, 0, 4); $y2 = str_pad((int)substr($s->Season, 0, 4) + 1, 4, '0', STR_PAD_LEFT); $disp_season = $y1 . '-' . substr($y2, 2, 2); if ($s->Team === 'New York Rangers') { $season_url = esc_url(home_url('/schedule/?season=' . $disp_season)); $filtered_scf_display[] = '' . $disp_season . ''; } else { $filtered_scf_display[] = $disp_season; } } } $data[] = ['Stanley Cup Finals', implode(', ', array_unique($filtered_scf_display))]; } // --- Conditional Profile Cross-Links --- $cross_links = []; if (!empty($c->player_id) && intval($c->player_id) > 0) { $cross_links[] = 'View Player Profile'; } $gm_exists = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM otg_general_managers WHERE name = %s", $c->Name)); if ($gm_exists > 0) { $cross_links[] = 'View General Manager Profile'; } if (!empty($cross_links)) { $data[] = ['Profiles', implode(' | ', $cross_links)]; } // --- Image Fallback Logic (Using Local File Check) --- $coach_id_val = intval($c->CoachID); $base_dir = $_SERVER['DOCUMENT_ROOT'] . '/images/coaches/'; $base_url = 'https://outsidethegarden.com/images/coaches/'; $default_img = 'https://outsidethegarden.com/images/players/default_player.png'; $display_img = $default_img; $extensions = ['jpg', 'jpeg', 'png']; foreach ($extensions as $ext) { if (file_exists($base_dir . $coach_id_val . '.' . $ext)) { $display_img = $base_url . $coach_id_val . '.' . $ext; break; } } // --- HTML Generation --- $html = ''; $html .= '
'; // --- Coach Pivot Dropdown Selector --- if (!empty($all_coaches)) { $html .= '
'; $html .= ''; $html .= ''; $html .= '
'; } $html .= '
'; // Left Column: Flag, Name, and Coach Photo $html .= '
'; $html .= '

'; if (!empty($c->Country)) { $html .= ''; } $html .= strtoupper(esc_html($c->Name)) . '

'; $html .= ''; $html .= '
'; // Right Column: Bio Data Grid $html .= '
'; foreach ($data as $index => $row) { $border_style = ($index === count($data) - 1) ? 'border-bottom: none;' : 'border-bottom: 1px solid #808080;'; $html .= '
' . $row[0] . ':
' . $row[1] . '
'; } $html .= '
'; if (!empty($stats)) { $html .= '

Coaching Statistics

'; // Toggle controls & Filters layout $html .= '
'; $html .= '
'; $html .= ''; $html .= ''; $html .= '
'; $html .= '
'; $html .= '
'; $td_style = 'padding: 6px 4px; border-bottom: 1px solid #222; vertical-align: middle; line-height: 1; text-align: center;'; $th_style = 'padding: 8px 4px; border-bottom: 2px solid #555; background-color: #222; text-align: center;'; // ========================================== // 1. REGULAR SEASON SECTION // ========================================== $html .= '
'; $html .= '
'; $html .= ''; $has_unique_field = property_exists($stats[0], 'unique_field'); if ($has_unique_field) { $html .= ''; } $html .= ''; $totals = ['NHL' => ['GC'=>0, 'W'=>0, 'L'=>0, 'T'=>0, 'OT'=>0, 'PT'=>0], 'NYR' => ['GC'=>0, 'W'=>0, 'L'=>0, 'T'=>0, 'OT'=>0, 'PT'=>0]]; foreach ($stats as $s) { $y1 = substr($s->Season, 0, 4); $y2 = str_pad((int)substr($s->Season, 0, 4) + 1, 4, '0', STR_PAD_LEFT); $disp_season = $y1 . '-' . substr($y2, 2, 2); $is_nhl = ($s->League === 'NHL'); $is_nyr = ($s->Team === 'New York Rangers'); $row_classes = 'league-' . ($is_nhl ? 'nhl' : 'other') . ($is_nyr ? ' team-nyr' : ''); $display = ($is_nhl || $is_nyr) ? '' : 'display: none;'; $unique_val = ($has_unique_field && isset($s->unique_field)) ? esc_attr($s->unique_field) : ''; $data_attr = !empty($unique_val) ? ' data-unique-field="' . $unique_val . '"' : ''; $gc = intval($s->GC); $w = intval($s->W); $l = intval($s->L); $t_val = isset($s->T) ? intval($s->T) : 0; $ot = isset($s->OT) ? intval($s->OT) : 0; // Dynamically calculate Pts as (W * 2) + T + OT $calculated_pts = ($w * 2) + $t_val + $ot; $max_pts = $gc * 2; $pt_pct = ($max_pts > 0) ? number_format(( $calculated_pts / $max_pts ) * 100, 2) . '%' : '0.00%'; $html .= ''; if ($has_unique_field) { $html .= ''; } $html .= ''; $scopes = []; if ($is_nhl) $scopes[] = 'NHL'; if ($is_nyr) $scopes[] = 'NYR'; foreach ($scopes as $scope) { $totals[$scope]['GC'] += $gc; $totals[$scope]['W'] += $w; $totals[$scope]['L'] += $l; $totals[$scope]['T'] += $t_val; $totals[$scope]['OT'] += $ot; $totals[$scope]['PT'] += $calculated_pts; } } $f = 'padding: 6px 4px; border-top: 2px solid #555; font-weight: bold; text-align: center;'; $fl = 'padding: 6px 4px; border-top: 2px solid #555; font-weight: bold; text-align: left;'; foreach (['NHL', 'NYR'] as $scope) { if ($totals[$scope]['GC'] > 0) { $t = $totals[$scope]; $row_class = ($scope === 'NYR') ? 'team-nyr' : 'league-nhl'; $max_pts = $t['GC'] * 2; $tot_pt_pct = ($max_pts > 0) ? number_format(( $t['PT'] / $max_pts ) * 100, 2) . '%' : '0.00%'; $html .= ''; if ($has_unique_field) { $html .= ''; } $html .= ''; $html .= ''; $html .= ''; $html .= ''; } } $html .= '
IDSeason Team League GC W L T OT Pts P%
'.$unique_val.''.esc_html($disp_season).' '.esc_html($s->Team).' '.esc_html($s->League).' '.esc_html($s->GC).' '.esc_html($s->W).' '.esc_html($s->L).' '.esc_html($s->T).' '.esc_html($s->OT).' '.$calculated_pts.' '.$pt_pct.'
-Career Totals'.$scope.'NHL'.$t['GC'].''.$t['W'].''.$t['L'].''.$t['T'].''.$t['OT'].''.$t['PT'].''.$tot_pt_pct.'
'; // ========================================== // 2. PLAYOFFS SECTION // ========================================== $html .= '
'; $html .= '
'; $html .= ''; if ($has_unique_field) { $html .= ''; } $html .= ''; $p_totals = ['NHL' => ['GC'=>0, 'W'=>0, 'L'=>0, 'T'=>0, 'SW'=>0, 'SL'=>0], 'NYR' => ['GC'=>0, 'W'=>0, 'L'=>0, 'T'=>0, 'SW'=>0, 'SL'=>0]]; $p_has_data = ['NHL' => false, 'NYR' => false]; foreach ($stats as $s) { $y1 = substr($s->Season, 0, 4); $y2 = str_pad((int)substr($s->Season, 0, 4) + 1, 4, '0', STR_PAD_LEFT); $disp_season = $y1 . '-' . substr($y2, 2, 2); $is_nhl = ($s->League === 'NHL'); $is_nyr = ($s->Team === 'New York Rangers'); $row_classes = 'league-' . ($is_nhl ? 'nhl' : 'other') . ($is_nyr ? ' team-nyr' : ''); $display = ($is_nhl || $is_nyr) ? '' : 'display: none;'; $unique_val = ($has_unique_field && isset($s->unique_field)) ? esc_attr($s->unique_field) : ''; $data_attr = !empty($unique_val) ? ' data-unique-field="' . $unique_val . '"' : ''; $pgc = isset($s->PGC) ? intval($s->PGC) : 0; $pw = isset($s->PW) ? intval($s->PW) : 0; $pl = isset($s->PL) ? intval($s->PL) : 0; $pt = isset($s->PT) ? intval($s->PT) : 0; $sw = isset($s->SW) ? intval($s->SW) : 0; $sl = isset($s->SL) ? intval($s->SL) : 0; $series_display = $sw . '–' . $sl; $scf = isset($s->SCF) ? intval($s->SCF) : 0; $sc = isset($s->SC) ? intval($s->SC) : 0; $sc_display = '-'; if ($pgc === 0) { $sc_display = 'Missed Playoffs'; } elseif ($sc === 1) { $sc_display = 'Won Stanley Cup'; } elseif ($scf === 1) { $sc_display = 'Stanley Cup Finals'; } $html .= ''; if ($has_unique_field) { $html .= ''; } $html .= ''; $scopes = []; if ($is_nhl) { $scopes[] = 'NHL'; $p_has_data['NHL'] = true; } if ($is_nyr) { $scopes[] = 'NYR'; $p_has_data['NYR'] = true; } foreach ($scopes as $scope) { $p_totals[$scope]['GC'] += $pgc; $p_totals[$scope]['W'] += $pw; $p_totals[$scope]['L'] += $pl; $p_totals[$scope]['T'] += $pt; $p_totals[$scope]['SW'] += $sw; $p_totals[$scope]['SL'] += $sl; } } foreach (['NHL', 'NYR'] as $scope) { if ($p_has_data[$scope]) { $t = $p_totals[$scope]; $tot_gc = isset($t['GC']) ? $t['GC'] : 0; $tot_w = isset($t['W']) ? $t['W'] : 0; $tot_l = isset($t['L']) ? $t['L'] : 0; $tot_t = isset($t['T']) ? $t['T'] : 0; $tot_sw = isset($t['SW']) ? $t['SW'] : 0; $tot_sl = isset($t['SL']) ? $t['SL'] : 0; $tot_series = $tot_sw . '–' . $tot_sl; $row_class = ($scope === 'NYR') ? 'team-nyr' : 'league-nhl'; $html .= ''; if ($has_unique_field) { $html .= ''; } $html .= ''; $html .= ''; $html .= ''; $html .= ''; } } $html .= '
IDSeason Team League GC W L T Series Stanley Cup
'.$unique_val.''.esc_html($disp_season).' '.esc_html($s->Team).' '.esc_html($s->League).' '.$pgc.' '.$pw.' '.$pl.' '.$pt.' '.$series_display.' '.$sc_display.'
-Career Totals'.$scope.'NHL'.$tot_gc.''.$tot_w.''.$tot_l.''.$tot_t.''.$tot_series.'-
'; } else { $html .= '

No coaching statistics found.

'; } // JavaScript for row filtering and switching between regular season / playoffs $html .= ''; return $html; } Gerard Gallant – Activity – OutsideTheGarden Boards – Page 38
JANUARY
«
Wed
6
Thu
7
7:00PM
Fri
8
Sat
9
10:00PM
Sun
10
Mon
11
10:00PM
Tue
12
10:00PM
»
Gerard Gallant
Gerard Gallant
Group: Registered
Joined: 2023-10-19
Team MVP
1
Follow