# Przykłady Użycia Systemu Meczów

## Przykładowe Shortcodes

### 1. Sezon Mistrzowski 1978-79

```html
<div class="championship-season">
    <h1>🏆 Sezon 1978-79 - Mistrzostwo NBA!</h1>
    
    <div class="season-intro">
        <p>Seattle SuperSonics zdobyli swój jedyny tytuł mistrzowski w historii,
        pokonując Washington Bullets 4-1 w finale NBA. Pod wodzą trenera Lenny'ego Wilkensa,
        zespół z Dennisem Johnsonem, Gusem Williamsem i Jackiem Sikmą zdominował ligę.</p>
    </div>

    <!-- Pełny harmonogram sezonu -->
    [sonics_season_schedule season="1978-79"]
</div>
```

### 2. Ostatni Sezon w Seattle (2007-08)

```html
<div class="farewell-season">
    <h1>Sezon 2007-08 - Pożegnanie z Seattle</h1>
    
    <p>Ostatni sezon Seattle SuperSonics przed przeprowadzką do Oklahoma City.
    Sezon zakończył się bilansem 20-62, ale pozostaje ważnym momentem w historii
    dla wszystkich fanów w Seattle.</p>

    <!-- Wszystkie mecze ostatniego sezonu -->
    [sonics_season_schedule season="2007-08"]
    
    <h2>Mecze domowe - KeyArena</h2>
    [sonics_games season="2007-08" home_away="HOME" limit="50"]
</div>
```

### 3. Finał NBA 1996

```html
<div class="finals-1996">
    <h1>Finał NBA 1996 vs Chicago Bulls</h1>
    
    <p>Seattle SuperSonics z bilansem 64-18 dotarli do finału NBA,
    gdzie zmierzyli się z legendarnymi Chicago Bulls Michaela Jordana
    (72-10 w sezonie regularnym).</p>

    <!-- Mecze finałowe -->
    <h2>Seria Finałowa (Bulls wygrali 4-2)</h2>
    [sonics_games season="1995-96" type="Playoffs" limit="6"]
    
    <!-- Cały sezon playoff -->
    <h2>Droga do Finału</h2>
    [sonics_games season="1995-96" type="Playoffs" limit="100"]
</div>
```

### 4. Dashboard z Aktualnymi Meczami

```html
<div class="sonics-live-dashboard">
    <div class="row">
        <div class="col-md-6">
            <h3>Ostatni Mecz</h3>
            [sonics_last_game]
        </div>
        <div class="col-md-6">
            <h3>Następny Mecz</h3>
            [sonics_next_game]
        </div>
    </div>
    
    <h3>Ostatnie 5 Meczów</h3>
    [sonics_games limit="5" style="cards"]
</div>
```

### 5. Strona "Wszystkie Sezony"

```html
<div class="all-seasons">
    <h1>Historia Seattle SuperSonics (1967-2008)</h1>
    
    <h2>Era Mistrzowska (1978-79)</h2>
    [sonics_season_schedule season="1978-79"]
    
    <h2>Era Paytona i Kempa (1995-96)</h2>
    [sonics_season_schedule season="1995-96"]
    
    <h2>Lata 90. - Złota Era</h2>
    [sonics_games season="1993-94" type="Regular Season" limit="20"]
    
    <h2>Pierwsze Lata (1967-68)</h2>
    [sonics_season_schedule season="1967-68"]
</div>
```

### 6. Widget Boczny

```html
<!-- Sidebar Widget -->
<div class="widget sonics-recent-games">
    <h3 class="widget-title">Ostatnie Mecze</h3>
    [sonics_games limit="3" style="cards"]
</div>
```

### 7. Strona Playoff History

```html
<div class="playoff-history">
    <h1>Historia Playoff Seattle SuperSonics</h1>
    
    <div class="playoff-year">
        <h2>1979 - Mistrzostwo 🏆</h2>
        [sonics_games season="1978-79" type="Playoffs"]
    </div>
    
    <div class="playoff-year">
        <h2>1996 - Finał NBA</h2>
        [sonics_games season="1995-96" type="Playoffs"]
    </div>
    
    <div class="playoff-year">
        <h2>1993 - Conference Finals</h2>
        [sonics_games season="1992-93" type="Playoffs"]
    </div>
</div>
```

### 8. Mecze Domowe vs Wyjazdowe

```html
<div class="home-away-split">
    <h2>Mecze Domowe w KeyArena</h2>
    [sonics_games season="2007-08" home_away="HOME"]
    
    <h2>Mecze Wyjazdowe</h2>
    [sonics_games season="2007-08" home_away="AWAY"]
</div>
```

---

## Przykłady PHP

### Wyświetlanie Statystyk Sezonu

```php
<?php
$db = Sonics_Database::get_instance();
$season_id = 1; // ID sezonu 2007-08

// Pobierz bilans
$regular_record = $db->get_season_record( $season_id, 'Regular Season' );
$playoff_record = $db->get_season_record( $season_id, 'Playoffs' );

// Wyświetl
echo '<div class="season-stats">';
echo '<h3>Bilans Sezonu</h3>';
echo '<p>Sezon Regularny: ' . $regular_record['wins'] . '-' . $regular_record['losses'] . '</p>';

if ( $playoff_record['total'] > 0 ) {
    echo '<p>Playoffs: ' . $playoff_record['wins'] . '-' . $playoff_record['losses'] . '</p>';
}
echo '</div>';
?>
```

### Custom Loop Meczów

```php
<?php
$db = Sonics_Database::get_instance();
$games = $db->get_games( 1, array(
    'game_type' => 'Regular Season',
    'limit'     => 10,
    'order'     => 'DESC'
) );

if ( $games ) {
    echo '<ul class="games-list">';
    foreach ( $games as $game ) {
        $result_class = $game->win_loss === 'W' ? 'win' : 'loss';
        
        echo '<li class="' . $result_class . '">';
        echo '<strong>' . date( 'M j', strtotime( $game->game_date ) ) . '</strong> ';
        echo $game->home_away === 'HOME' ? 'vs ' : '@ ';
        echo $game->opponent . ' ';
        echo '<span class="score">' . $game->sonics_score . '-' . $game->opponent_score . '</span> ';
        echo '<span class="result">' . $game->win_loss . '</span>';
        echo '</li>';
    }
    echo '</ul>';
}
?>
```

### Widget z Najbliższymi Meczami

```php
<?php
class Sonics_Upcoming_Games_Widget extends WP_Widget {
    
    public function widget( $args, $instance ) {
        $db = Sonics_Database::get_instance();
        $next_games = $db->get_games( null, array(
            'limit' => 5,
            'order' => 'ASC'
        ) );
        
        echo $args['before_widget'];
        echo $args['before_title'] . 'Najbliższe Mecze' . $args['after_title'];
        
        if ( $next_games ) {
            echo '<ul class="upcoming-games">';
            foreach ( $next_games as $game ) {
                echo '<li>';
                echo date( 'M j, H:i', strtotime( $game->game_date ) ) . '<br>';
                echo $game->home_away === 'HOME' ? 'vs ' : '@ ';
                echo '<strong>' . $game->opponent . '</strong>';
                echo '</li>';
            }
            echo '</ul>';
        }
        
        echo $args['after_widget'];
    }
}
?>
```

### Najlepsze Mecze (Najwyższy Wynik)

```php
<?php
global $wpdb;
$table = $wpdb->prefix . 'sonics_games';

$high_scoring = $wpdb->get_results(
    "SELECT * FROM $table 
     WHERE game_type = 'Regular Season' 
     AND sonics_score IS NOT NULL
     ORDER BY sonics_score DESC 
     LIMIT 10"
);

echo '<h3>Najwyższe Wyniki Sonics</h3>';
echo '<ol>';
foreach ( $high_scoring as $game ) {
    echo '<li>';
    echo $game->sonics_score . ' punktów ';
    echo '(' . $game->home_away === 'HOME' ? 'vs ' : '@ ';
    echo $game->opponent . ', ';
    echo date( 'M j, Y', strtotime( $game->game_date ) ) . ')';
    echo '</li>';
}
echo '</ol>';
?>
```

### Serie Zwycięstw

```php
<?php
$db = Sonics_Database::get_instance();
$games = $db->get_games( 1, array( 'order' => 'ASC' ) );

$current_streak = 0;
$max_streak = 0;
$streak_type = '';

foreach ( $games as $game ) {
    if ( $game->win_loss === 'W' ) {
        $current_streak++;
        if ( $current_streak > $max_streak ) {
            $max_streak = $current_streak;
            $streak_type = 'zwycięstw';
        }
    } else {
        $current_streak = 0;
    }
}

echo '<div class="streak-stats">';
echo '<h4>Najdłuższa seria: ' . $max_streak . ' ' . $streak_type . '</h4>';
echo '</div>';
?>
```

---

## Przykłady Custom CSS

### Kolorystyka Drużynowa

```css
/* Kolory Seattle SuperSonics */
:root {
    --sonics-green: #00A651;
    --sonics-gold: #FFC72C;
    --sonics-dark: #2D5C2D;
}

/* Tabela z kolorami Sonics */
.sonics-games-table thead {
    background: linear-gradient(135deg, var(--sonics-dark) 0%, var(--sonics-green) 100%);
}

.sonics-games-table tbody tr.win {
    background-color: rgba(0, 166, 81, 0.08);
    border-left: 5px solid var(--sonics-green);
}

.sonics-games-table tbody tr.win:hover {
    background-color: rgba(0, 166, 81, 0.15);
}
```

### Animacje dla Kart

```css
/* Animacja pojawiania się kart */
.sonics-game-card {
    animation: slideUp 0.4s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Hover effect */
.sonics-game-card:hover {
    transform: translateY(-8px) scale(1.02);
    box-shadow: 0 12px 24px rgba(0, 166, 81, 0.2);
}
```

### Responsywny Layout

```css
/* Desktop */
@media (min-width: 1200px) {
    .sonics-games-cards {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Tablet */
@media (min-width: 768px) and (max-width: 1199px) {
    .sonics-games-cards {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Mobile */
@media (max-width: 767px) {
    .sonics-games-cards {
        grid-template-columns: 1fr;
    }
    
    .sonics-games-table {
        font-size: 12px;
    }
    
    .sonics-games-table th,
    .sonics-games-table td {
        padding: 8px 5px;
    }
}
```

---

## Integracja z Innymi Elementami

### Połączenie z Kalendarzem

```php
<?php
// Dodaj mecze do kalendarza WordPress
$games = $db->get_games( $season_id );

foreach ( $games as $game ) {
    // Utwórz event w kalendarzu
    $event_title = 'Sonics vs ' . $game->opponent;
    $event_date = $game->game_date;
    
    // Integracja z The Events Calendar lub inną wtyczką
    tribe_create_event( array(
        'post_title'  => $event_title,
        'post_status' => 'publish',
        'EventStartDate' => $event_date,
        'EventEndDate'   => $event_date,
    ) );
}
?>
```

### Email Newsletter

```php
<?php
// Wyślij newsletter z najbliższymi meczami
$next_games = $db->get_games( null, array( 'limit' => 3 ) );

$email_content = '<h2>Najbliższe Mecze Seattle SuperSonics</h2>';
$email_content .= '<ul>';

foreach ( $next_games as $game ) {
    $email_content .= '<li>';
    $email_content .= '<strong>' . date( 'l, F j', strtotime( $game->game_date ) ) . '</strong><br>';
    $email_content .= $game->home_away === 'HOME' ? 'vs ' : '@ ';
    $email_content .= $game->opponent;
    $email_content .= '</li>';
}

$email_content .= '</ul>';

wp_mail( 
    get_option( 'admin_email' ), 
    'Sonics - Najbliższe Mecze', 
    $email_content,
    array( 'Content-Type: text/html; charset=UTF-8' )
);
?>
```

---

## Tips & Tricks

### 1. Cachowanie Wyników

```php
<?php
// Cache wyników na 1 godzinę
$cache_key = 'sonics_games_' . $season_id;
$games = get_transient( $cache_key );

if ( false === $games ) {
    $games = $db->get_games( $season_id );
    set_transient( $cache_key, $games, HOUR_IN_SECONDS );
}
?>
```

### 2. Lazy Loading dla Dużych List

```javascript
// Ładuj więcej meczów po kliknięciu
jQuery('.load-more-games').on('click', function() {
    var offset = jQuery('.sonics-game-card').length;
    
    jQuery.post(ajaxurl, {
        action: 'load_more_games',
        season_id: seasonId,
        offset: offset
    }, function(response) {
        jQuery('.sonics-games-cards').append(response);
    });
});
```

### 3. Eksport do CSV

```php
<?php
// Eksportuj mecze do CSV
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="sonics-games.csv"');

$output = fopen('php://output', 'w');
fputcsv($output, array('Data', 'Przeciwnik', 'Wynik', 'W/L'));

$games = $db->get_games( $season_id );
foreach ($games as $game) {
    fputcsv($output, array(
        $game->game_date,
        $game->opponent,
        $game->sonics_score . '-' . $game->opponent_score,
        $game->win_loss
    ));
}

fclose($output);
exit;
?>
```

---

## FAQ

**Q: Jak często aktualizować dane z Basketball-Reference?**
A: Dla sezonów historycznych (1967-2008) wystarczy jednorazowy import. Dane są już kompletne.

**Q: Czy mogę edytować zaimportowane mecze?**
A: Tak, możesz używać metod `update_game()` w klasie Database.

**Q: Jak dodać własne notatki do meczów?**
A: Użyj pola `game_notes` podczas dodawania/edycji meczu.

**Q: Czy shortcodes działają w widgetach?**
A: Tak, shortcodes są kompatybilne z widgetami WordPress.

**Q: Jak wyświetlić tylko mecze z określonego miesiąca?**
A: Użyj własnego query SQL z warunkiem WHERE dla game_date.

---

© 2025 Sonics Polska
