Plugin Directory

Changeset 3046250


Ignore:
Timestamp:
03/06/2024 10:53:01 AM (2 years ago)
Author:
mtreherne
Message:

Release of Version 3.10

Location:
eh-gms-feed
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • eh-gms-feed/tags/3.10/css/gms-default.css

    r2981152 r3046250  
    88.gms-filter fieldset { width: fit-content }
    99.gms-filter legend { padding: 0px }
     10.gms-detaillink { cursor: pointer }
     11.gms-detaillink:hover { background-color: yellow }
    1012
    1113/* This styling sets alignment for specific tables */
     
    2628@media screen and (max-width: 767px) { .gms-table { overflow-x: auto; display: block; white-space: nowrap } .gms-nomobile { display: none } }
    2729
    28 /* Styling for fixtures and results displayed as list */
     30/* Styling for fixtures and results displayed as list and fixture details */
    2931.gms-list > * + * { margin-top: 1.5rem; margin-bottom: 1.5rem }
     32.gms-list + .gms-footnote { margin-top: 1rem }
    3033.gms-card { text-align: center; padding: 3px 3px; border-radius: 0.5rem }
    31 .gms-card, .gms-cardtime { border: 1px solid; border-color: silver }
    32 .gms-cardfixture { display: flex; gap: 0.5rem; align-items: center }
     34.gms-card, .gms-cardtime, .gms-cardnoscore, .gms-fixturedetails > div { border: 1px solid; border-color: silver }
     35.gms-cardtitle { font-weight: 700; font-size:larger }
     36.gms-cardfixture, .gms-cardscorers { display: flex; gap: 0.5rem; align-items: center }
    3337.gms-cardhome { flex: 1 1 0%; text-align: right }
    3438.gms-carddivide { padding: 0.25rem 0.5rem }
    35 .gms-cardtime { font-weight: 700; border-radius: 0.375rem; background-color: white }
     39.gms-cardtime, .gms-cardnoscore { font-weight: 700; border-radius: 0.375rem; background-color: white }
    3640.gms-cardaway { flex: 1 1 0%; text-align: left }
    37 .gms-list + .gms-footnote { margin-top: 1rem }
     41.gms-cardscorers { font-size: smaller }
     42.gms-cardstatus { background-color: black; color: white; margin: 0.25rem auto; width:fit-content; padding: 0.25rem 0.5rem }
     43.gms-fixture .gms-card > * { margin-top: 0.5rem; margin-bottom: 0.5rem }
     44.gms-fixturedetails { display: flex; flex-wrap: wrap; gap: 1rem }
     45.gms-fixturedetails > div { flex-grow: 1; padding: 0.5rem 0.5rem; border-radius: 0.5rem }
     46.gms-fixturedetails img { display: inline; width: 1.5rem; height: 1.5rem; vertical-align: middle; margin-right: 0.25rem }
     47.gms-fixturedetails ul { list-style-type: none; padding: 0; margin: 0 }
     48.gms-players li { display: flex; align-items: center }
     49.gms-players svg { width: 1rem; height: 1rem }
    3850
    3951/* Creates a loader image for the AJAX wait */
  • eh-gms-feed/tags/3.10/eh-gms-feed.php

    r3042119 r3046250  
    44 * Plugin URI: https://wordpress.org/plugins/eh-gms-feed/
    55 * Description: Show fixtures, results and tables from England Hockey GMS
    6  * Version: 3.9
     6 * Version: 3.10
    77 * Author: Matthew Treherne
    88 * Author URI: https://profiles.wordpress.org/mtreherne
  • eh-gms-feed/tags/3.10/includes/main-class.php

    r3042119 r3046250  
    1010class EH_GMS_Feed {
    1111
    12     private $basename, $settings, $atts_show, $not_valid, $filter_match, $table_name, $fixture_data, $display_name, $show_gender, $show_list, $show_cal, $cal_summary;
     12    private $basename, $settings, $atts_show, $not_valid, $filter_match, $table_name, $fixture_data, $display_name, $show_gender, $show_list, $show_cal, $cal_summary, $id, $show_detail;
    1313    private $club_link, $team_link, $comp_link, $team_comps, $comp_name;
    1414    private $args = ['method','show','team','comp_id','club_id','whatson','link','sort_by','options'];
     
    2222        'compsinfixtures' => ['suffix' => 'fixturesandresults', 'transient' => 'TEAM', 'keys' => ['teams'], 'error_bag' => 'competition', 'expiry' => 'default'],
    2323        'competition' => ['suffix' => '', 'transient' => 'COMPETITION SUMMARY', 'keys' => ['competitions'], 'error_bag' => null, 'expiry' => 'default'],
     24        'fixture' => ['suffix' => '', 'transient' => 'FIXTURE', 'keys' => ['fixtures'], 'error_bag' => null, 'expiry' => 'default'],
    2425    ];
    2526
     
    176177    }
    177178
     179    private function show_goals ($events) {
     180        $goals = [];
     181        foreach ($events as $event) if (in_array($event->eventType,['FG','PC','PS'])) $goals[$event->memberId][] = $event;
     182        $showGoals = [];
     183        foreach ($goals as $goalsById) {
     184            $playerName = '';
     185            $playerGoals = [];
     186            foreach ($goalsById as $goal) {
     187                if (!$playerName) $playerName = $goal->displayName;
     188                $playerGoals[] = ($goal->minute ? $goal->minute . '′ ' : '') . $goal->eventType;
     189            }
     190            $showGoals[] = $playerName . ' (' . implode(', ',$playerGoals) . ')';
     191        }
     192        return implode(', ', $showGoals);
     193    }
     194
     195    private function show_players($players) {
     196        $showPlayers = '';
     197        $withheld = 0;
     198        foreach ($players as $player) {
     199            if (!($player->consent || isset($player->shirtNumber))) { $withheld += 1; continue; }
     200            $playerEvents = [];
     201            foreach ($player->playerEvents as $event) {
     202                switch ($event->eventType) {
     203                    case 'GC': $showType = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M1.892 20.5 12 3.959 22.109 20.5z" fill="#0FBD00" stroke="#0DA300"/></svg>'; break;
     204                    case 'YC': $showType = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><rect x="3.5" y=".5" width="17" height="23" rx="1.5" fill="#FFE500" stroke="#DBCA39"/></svg>'; break;
     205                    case 'RC': $showType = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10.5" fill="#E0251B" stroke="#E0251B"/></svg>'; break;
     206                    default : $showType = '<b>'.$event->eventType.'</b>';
     207                }
     208                $playerEvents[] = ($event->minute ? '<b>'.$event->minute . '&prime;&nbsp;</b>' : '') . $showType;
     209            }
     210            switch ($player->otherRoleDescription) {
     211                case 'Goalkeeper' : $role = ' (GK)'; break;
     212                case 'Captain' : $role = ' (C)'; break;
     213                default : $role = '';
     214            }
     215            $showPlayers .= '<li>'.($player->shirtNumber ?? '') . ' ' . $player->displayName . $role . (!empty($playerEvents) ? ('&nbsp;' . implode(',&nbsp;',$playerEvents)) : '') . '</li>';
     216        }
     217        if ($withheld) $showPlayers .= ($withheld > 1) ? '<li>Names Withheld (&times;'.$withheld.')</li>' : '<li>Name Withheld</li>';
     218        return $showPlayers;
     219    }
     220
     221    private function show_officials($officials) {
     222        $showOfficials = '';
     223        foreach ($officials as $official) {
     224            if ($official->displayName != 'Name Withheld') $showOfficials .= '<li>' . $official->role . ': ' . $official->displayName . '</li>';
     225        }
     226        return $showOfficials;
     227    }
     228
     229    private function fixture_summary ($fixture, $valid_date, $show_detail=false) {
     230        $html = '';
     231        $fixture_card = [
     232            'Date' => $valid_date->format('d M Y'),
     233            'Time' => $fixture->fixtureTime == '00:00' ? '' : $fixture->fixtureTime,
     234            'Home Team' => $fixture->homeTeam->teamName,
     235            'Score' => '',
     236            'Away Team' => $fixture->awayTeam->teamName,
     237            'Venue' => !empty($fixture->venue) ? ($this->show_detail ? esc_html($fixture->venue) : '<a href="https://www.google.com/maps/search/?api=1&query='.urlencode($fixture->venue).'" target="_blank">'.esc_html($fixture->venue).'</a>') : '',
     238        ];
     239        if ($show_detail) {
     240            $home_goals = $this->show_goals($fixture->homeTeamEvents);
     241            $away_goals = $this->show_goals($fixture->awayTeamEvents);
     242            $address = !empty($fixture->venueDetails->address) ? $fixture->venueDetails->address . (!empty($fixture->venueDetails->postCode) ? ','.$fixture->venueDetails->postCode : '') : '';
     243        }
     244        $score_class = '';
     245        $home_attr = $away_attr = $home_class = $away_class = [];
     246        if ($fixture->isResult && !$fixture->isBye) {
     247            $fixture_card['Score'] = $fixture->homeTeamScore . ' : ' . $fixture->awayTeamScore;
     248            if ($fixture->status == 'Postponed' || ($fixture->homeTeamScore == 'P' && $fixture->awayTeamScore == 'P'));
     249            elseif ($fixture->status == 'Cancelled' || ($fixture->homeTeamScore == 'C' && $fixture->awayTeamScore == 'C'));
     250            elseif ($fixture->homeTeamScore == $fixture->awayTeamScore) $score_class = 'gms-draw';
     251            elseif (($fixture->homeTeam->id == $this->atts_show['team'] || ($this->is_clubwide() && $fixture->homeTeam->clubId == $this->atts_show['club_id'])) && $fixture->homeTeamScore > $fixture->awayTeamScore) $score_class = 'gms-win';
     252            elseif (($fixture->awayTeam->id == $this->atts_show['team'] || ($this->is_clubwide() && $fixture->awayTeam->clubId == $this->atts_show['club_id'])) && $fixture->homeTeamScore < $fixture->awayTeamScore) $score_class = 'gms-win';
     253            else $score_class = 'gms-loss';
     254        }
     255        if ($this->is_clubteam($fixture->homeTeam) && $this->is_clubwide()) {
     256            $home_class[] = 'gms-clubteam';
     257            $home_attr[] = 'data-team="'.($fixture->homeTeam->id).'"';
     258            if ($this->show_gender) $fixture_card['Home Team'] .= ' ('.$fixture->homeTeam->gender.')';
     259        }
     260        if ($this->is_clubteam($fixture->awayTeam) && $this->is_clubwide()) {
     261            $away_class[] = 'gms-clubteam';
     262            $away_attr[] = 'data-team="'.($fixture->awayTeam->id).'"';
     263            if ($this->show_gender) $fixture_card['Away Team'] .= ' ('.$fixture->awayTeam->gender.')';
     264        }
     265        if ($this->show_list) {
     266            $statusDisplay = !in_array($fixture->status, ['Active','Result','Bye']) ? $fixture->status : '';
     267            if ($fixture->isResult && ($fixture->homeTeamShootoutScore > 0 || $fixture->awayTeamShootoutScore > 0)) $statusDisplay = 'Shootout '.$fixture->homeTeamShootoutScore.' - '. $fixture->awayTeamShootoutScore;
     268            $home_attr[] = 'class="'.implode(' ',$home_class).'"';
     269            $away_attr[] = 'class="'.implode(' ',$away_class).'"';
     270            if ($fixture->isBye) {
     271                $divide = '- : -';
     272                $divide_attr = ' class="gms-carddivide gms-cardnoscore"';
     273            }
     274            elseif ($fixture->isResult) {
     275                $divide = $fixture_card['Score'];
     276                $divide_attr = ' class="gms-carddivide '.($score_class ?: 'gms-cardnoscore').'"';
     277            }
     278            else {
     279                $divide = $fixture_card['Time'] ?: 'TBC';
     280                $divide_attr = ' class="gms-carddivide gms-cardtime"';
     281            }
     282            $html .= '<div class="gms-card'.($this->show_detail ? ' gms-detaillink' : '').'"'.($this->show_detail ? ' data-fixture="'.$fixture->id.'"': '').'>'
     283                .($show_detail ? '<div class="gms-cardtitle">Fixture Details</div>': '')
     284                .'<div class="gms-carddate">'.$fixture_card['Date'].'</div>'
     285                .'<div class="gms-cardfixture"><div class="gms-cardhome"><div '.implode(' ',$home_attr).'>'.$fixture_card['Home Team'].'</div></div><div'.$divide_attr.'>'.$divide.'</div><div class="gms-cardaway"><div '.implode(' ',$away_attr).'>'.$fixture_card['Away Team'].'</div></div></div>'
     286                .(($show_detail && ($home_goals || $away_goals)) ? '<div class="gms-cardscorers"><div class="gms-cardhome"><div>'.$home_goals.'</div></div><div class="gms-carddivide"></div><div class="gms-cardaway"><div>'.$away_goals.'</div></div></div>' : '')
     287                .($statusDisplay ? '<div class="gms-cardstatus">'.$statusDisplay.'</div>' : '')
     288                .'<div class="gms-cardvenue">'.($fixture_card['Venue'] ?: 'Venue TBC').'</div>'
     289                .($show_detail && $address ? '<div>'.$address.'</div>' : '')
     290                .'</div>';
     291            if ($show_detail) {
     292                $participant_details = false;
     293                $html .= '<div class="gms-fixturedetails">';
     294                foreach (['home','away'] as $team) {
     295                    $showPlayers = $this->show_players($fixture->{$team . 'Players'});
     296                    $showOfficials = $this->show_officials($fixture->{$team. 'TeamOfficials'});
     297                    if ($showPlayers || $showOfficials) {
     298                        $club_logo = $fixture->{$team . 'Team'}->clubLogoUrl ?? null;
     299                        $participant_details = true;
     300                        $html .= '<div>';
     301                        if ($showPlayers) $html .= '<div class="gms-players">'.($club_logo ? '<img src="'.$club_logo.'" onerror="this.style.display=\'none\'"></img>' : '').'<b>'.$fixture->{$team.'Team'}->teamName.'</b><ul>'.$showPlayers.'</ul></div>';
     302                        if ($showOfficials) $html .= '<div class="gms-officials">'.($showPlayers ? '<br/>' : '').'<b>Coaching Roles</b><ul>'.$showOfficials.'</ul></div>';
     303                        $html .= '</div>';
     304                    }
     305                }
     306                $showOfficials = $this->show_officials($fixture->officials);
     307                if ($showOfficials) {
     308                    $participant_details = true;
     309                    $html .= '<div class="gms-officials"><b>Match Officials</b><ul>'.$showOfficials.'</ul></div>';
     310                }
     311                if (!$participant_details) $html .= '<div><b>No more details available</b></div>';
     312                $html .= '</div>';
     313            }
     314        }
     315        else {
     316            $home_attr[] = 'class="'.implode(' ',$home_class).'"';
     317            $away_attr[] = 'class="'.implode(' ',$away_class).'"';
     318            $html .= $this->show_detail ? '<tr class="gms-detaillink" data-fixture="'.$fixture->id.'">': '<tr>';
     319            foreach ($this->fixture_data as $column_title => $field_name) {
     320                $value = $fixture_card[$column_title];
     321                switch ($column_title) {
     322                    case 'Home Team' : $attr = implode(' ',$home_attr); break;
     323                    case 'Away Team' : $attr = implode(' ',$away_attr); break;
     324                    case 'Score' : $attr = 'class="'.$score_class.'"';  break;
     325                    default : $attr = '';
     326                }
     327                $html .= '<td '.$attr.'>'.($column_title != 'Venue' ? esc_html($value) : $value).'</td>';
     328            }
     329            $html .= '</tr>';
     330        }
     331        return $html;
     332    }
     333
    178334    private function process_matches ($fixtures) {
    179335        $html = '';
     
    189345            if ($this->filter_whatson($valid_date)) continue;
    190346            $this->filter_match = true;
    191             $fixture_card = [
    192                 'Date' => $valid_date->format('d M Y'),
    193                 'Time' => $fixture->fixtureTime == '00:00' ? '' : $fixture->fixtureTime,
    194                 'Home Team' => $fixture->homeTeam->teamName,
    195                 'Score' => '',
    196                 'Away Team' => $fixture->awayTeam->teamName,
    197                 'Venue' => !empty($fixture->venue) ? '<a href="https://www.google.com/maps/search/?api=1&query='.urlencode($fixture->venue).'" target="_blank">'.esc_html($fixture->venue).'</a>' : ''
    198             ];
    199             $score_class = '';
    200             $home_attr = $away_attr = $home_class = $away_class = [];
    201             if ($fixture->isResult && !$fixture->isBye) {
    202                 $fixture_card['Score'] = $fixture->homeTeamScore . ' : ' . $fixture->awayTeamScore;
    203                 if ($fixture->status == 'Postponed' || ($fixture->homeTeamScore == 'P' && $fixture->awayTeamScore == 'P'));
    204                 elseif ($fixture->homeTeamScore == $fixture->awayTeamScore) $score_class = 'gms-draw';
    205                 elseif (($fixture->homeTeam->id == $this->atts_show['team'] || ($this->is_clubwide() && $fixture->homeTeam->clubId == $this->atts_show['club_id'])) && $fixture->homeTeamScore > $fixture->awayTeamScore) $score_class = 'gms-win';
    206                 elseif (($fixture->awayTeam->id == $this->atts_show['team'] || ($this->is_clubwide() && $fixture->awayTeam->clubId == $this->atts_show['club_id'])) && $fixture->homeTeamScore < $fixture->awayTeamScore) $score_class = 'gms-win';
    207                 else $score_class = 'gms-loss';
    208             }
    209             if ($this->is_clubteam($fixture->homeTeam) && $this->is_clubwide()) {
    210                 $home_class[] = 'gms-clubteam';
    211                 $home_attr[] = 'data-team="'.($fixture->homeTeam->id).'"';
    212                 if ($this->show_gender) $fixture_card['Home Team'] .= ' ('.$fixture->homeTeam->gender.')';
    213             }
    214             if ($this->is_clubteam($fixture->awayTeam) && $this->is_clubwide()) {
    215                 $away_class[] = 'gms-clubteam';
    216                 $away_attr[] = 'data-team="'.($fixture->awayTeam->id).'"';
    217                 if ($this->show_gender) $fixture_card['Away Team'] .= ' ('.$fixture->awayTeam->gender.')';
    218             }
    219             if ($this->show_list) {
    220                 $home_class[] = 'gms-cardhome';
    221                 $away_class[] = 'gms-cardaway';
    222                 $home_attr[] = 'class="'.implode(' ',$home_class).'"';
    223                 $away_attr[] = 'class="'.implode(' ',$away_class).'"';
    224                 if ($fixture->isResult && !$fixture->isBye) {
    225                     $divide = $fixture_card['Score'];
    226                     $divide_attr = ' class="gms-carddivide '.$score_class.'"';
    227                 }
    228                 else {
    229                     $divide = $fixture_card['Time'] ?: 'TBC';
    230                     $divide_attr = ' class="gms-carddivide gms-cardtime"';
    231                 }
    232                 $html .= '<div class="gms-card"><div class="gms-carddate">'.$fixture_card['Date'].'</div><div class="gms-cardfixture"><div '.implode(' ',$home_attr).'>'.$fixture_card['Home Team'].'</div><div'.$divide_attr.'>'.$divide.'</div><div '.implode(' ',$away_attr).'>'.$fixture_card['Away Team'].'</div></div><div class="gms-cardvenue">'.($fixture_card['Venue'] ?: 'Venue TBC').'</div></div>';               
    233             }
    234             else {
    235                 $home_attr[] = 'class="'.implode(' ',$home_class).'"';
    236                 $away_attr[] = 'class="'.implode(' ',$away_class).'"';
    237                 $html .= '<tr>';
    238                 foreach ($this->fixture_data as $column_title => $field_name) {
    239                     $value = $fixture_card[$column_title];
    240                     switch ($column_title) {
    241                         case 'Home Team' : $attr = implode(' ',$home_attr); break;
    242                         case 'Away Team' : $attr = implode(' ',$away_attr); break;
    243                         case 'Score' : $attr = 'class="'.$score_class.'"';  break;
    244                         default : $attr = '';
    245                     }
    246                     $html .= '<td '.$attr.'>'.($column_title != 'Venue' ? esc_html($value) : $value).'</td>';
    247                 }
    248                 $html .= '</tr>';
    249             }
     347            $html .= $this->fixture_summary($fixture, $valid_date);
    250348        }
    251349        return $html;
     
    380478    }
    381479
     480    private function process_fixture($data) {
     481        $html = '<div class="gms-list">';
     482        $html .= $this->fixture_summary($data, new \DateTime($data->fixtureDate), true);
     483        $html .= '</div>';
     484        $html .= '<div class="gms-footnote">'.sprintf(esc_html__( '[Fixture %2$s also found at%3$s %1$s]', 'eh-gms-feed'), '<a href="'.$this->get_link('fixture', $this->id).'" target="_blank">England Hockey Link</a>', '<span class="gms-nomobile">', '</span>').'</div>';
     485        return $html;
     486    }
     487
    382488    private function get_table() {
    383489        $html = '';
    384490        $tables = [];
     491        if (str_contains($this->atts_show['show'], 'fixture')) $tables[] = 'fixture';
    385492        if (str_contains($this->atts_show['show'], 'league')) $tables[] = 'league';
    386493        if (str_contains($this->atts_show['show'], 'results')) {
     
    395502            if ($table_name == 'fixtures') unset($this->fixture_data['Score']);
    396503            if ($table_name == 'league' && $this->is_competition()) {
    397                 if ($this->atts_show['link'])  $this->comp_link = $this->atts_show['link'];
     504                if ($this->atts_show['link']) $this->comp_link = $this->atts_show['link'];
    398505                $html .= $this->get_json('competition', $this->atts_show['comp_id']);
    399506            }
     
    407514            }
    408515            elseif ($table_name == 'teams' && $this->is_clubwide()) {
    409             if ($this->atts_show['link'])   $this->club_link = $this->atts_show['link'];
     516                if ($this->atts_show['link']) $this->club_link = $this->atts_show['link'];
    410517                $html .= $this->get_json('teamslist', $this->atts_show['club_id']);
     518            }
     519            elseif ($table_name == 'fixture' && $this->id) {
     520                $this->show_list = true;
     521                $html .= $this->get_json('fixture', $this->id);
    411522            }
    412523        }
     
    483594        $this->atts_show['options'] = sanitize_text_field( $this->atts_show['options'] );
    484595        if ($this->atts_show['method'] == 'api' || $this->atts_show['method'] == 'api-dynamic') {
    485             if (empty($this->atts_show['club_id']) && ((!$this->is_competition() && !$this->is_team()) || $this->atts_show['method'] == 'api-dynamic')) {
     596            if (empty($this->atts_show['club_id']) && ((!$this->is_competition() && !$this->is_team() && !$this->atts_show['show'] == 'fixture') || $this->atts_show['method'] == 'api-dynamic')) {
    486597                $message = esc_html__( 'Please enter a Club ID with the shortcode e.g. [gms club_id="19fd1b0c-e11c-46f9-9114-45c2262a1e90"], or set a default Club ID in the plugin settings.', 'eh-gms-feed' );
    487598                $this->not_valid .= '<p>'.$message.'</p>';
     
    495606        }
    496607        foreach (explode('+',$this->atts_show['show']) as $show) {
    497             if (!in_array($show,['fixtures','results','league','teams'])) {
     608            if (!in_array($show,['fixtures','results','league','teams','fixture'])) {
    498609                $message = sprintf(esc_html__( 'Please enter a "show" parameter (%s) equal to "fixtures", "results", "league" or "teams".', 'eh-gms-feed' ), $show ?: 'empty');
    499610                $this->not_valid .= '<p>'.$message.'</p>';
     
    520631            foreach ($options as $option) {
    521632                $option_split = array_map('trim', explode(':', $option));
    522                 if ($option_split[0] == 'showgender' && ($option_split[1] ?? '') == 'yes') $this->show_gender = true;
    523                 if ($option_split[0] == 'showlist' && ($option_split[1] ?? '') == 'yes') $this->show_list = true;
    524                 if ($option_split[0] == 'showcal' && ($option_split[1] ?? '') == 'yes') $this->show_cal = true;
    525                 if ($option_split[0] == 'calsummary') $this->cal_summary = $option_split[1] ?? '';
     633                switch ($option_split[0]) {
     634                    case 'showgender' : if (($option_split[1] ?? '') == 'yes') $this->show_gender = true; break;
     635                    case 'showlist' : if (($option_split[1] ?? '') == 'yes') $this->show_list = true; break;
     636                    case 'showcal' : if (($option_split[1] ?? '') == 'yes') $this->show_cal = true; break;
     637                    case 'calsummary' : $this->cal_summary = $option_split[1] ?? ''; break;
     638                    case 'id' : $this->id = $option_split[1] ?? ''; break;
     639                    case 'showdetail' : if (($option_split[1] ?? '') == 'yes') $this->show_detail = true; break;
     640                }
    526641            }
    527642        }
     
    540655
    541656    public function enqueue_scripts () {
    542         wp_register_script('EH_GMS_Feed', plugin_dir_url(__DIR__).'js/eh-gms-feed.js', ['jquery'], '3.9', true);
     657        wp_register_script('EH_GMS_Feed', plugin_dir_url(__DIR__).'js/eh-gms-feed.js', ['jquery'], '3.10', true);
    543658        wp_localize_script('EH_GMS_Feed', 'eh_gms_feed_ajax_obj', ['ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce('get_gms_table')]);
    544         wp_register_style('EH_GMS_Feed', plugin_dir_url(__DIR__).'css/gms-default.css',[],'3.8');
     659        wp_register_style('EH_GMS_Feed', plugin_dir_url(__DIR__).'css/gms-default.css',[],'3.10');
    545660        if ($this->settings->default_css == 'yes') wp_enqueue_style('EH_GMS_Feed');
    546661    }
  • eh-gms-feed/tags/3.10/js/eh-gms-feed.js

    r3042119 r3046250  
    77    var refresh_message = 'The tables selected will be shown when you click on the <b>REFRESH</b> button.';
    88
    9     function club_team (message, filter, wrapper) {
    10         wrapper.find('.gms-clubteam[data-team]').css('cursor','pointer').on('click', function(e) {
     9    function club_team (message, filter, wrapper, detail) {
     10        var ele = detail ? detail : wrapper;
     11        ele.find('.gms-clubteam[data-team]').css('cursor','pointer').prop('title', 'Select to filter by team').on('click', function(e) {
     12            if (detail) {
     13                detail.hide();
     14                filter.show();
     15                wrapper.show();
     16            }
    1117            var team = e.currentTarget.dataset.team;
    1218            filter.find('select[name="team"]').val(team);
    1319            team_change(message, filter, wrapper, team, function() {
    1420                filter.find('select[name="whatson"]').val('');
    15                 if (filter.find('select[name="comp_id"]').val() != '- All Competitions -' && filter.find('input[type="checkbox"][name="show"][value="results"]').prop('checked')) {
     21                if (filter.find('select[name="comp_id"]').val() != '' && filter.find('input[type="checkbox"][name="show"][value="results"]').prop('checked')) {
    1622                    filter.find('input[type="checkbox"][name="show"][value="league"]').prop('checked',true);
    1723                }
     
    6369    }
    6470
     71    function fixture_detail (message, filter, loader, wrapper) {
     72        var detail = wrapper.next();
     73        wrapper.find('.gms-detaillink[data-fixture]').each(function() {
     74            jQuery(this).on('click', function(e) {
     75                var fixturelink = e.currentTarget;
     76                var fixture = fixturelink.dataset.fixture;
     77                message.text('Retrieving Fixture Details');
     78                if (filter) filter.hide();
     79                wrapper.hide();
     80                message.show();
     81                loader.show();
     82                message[0].scrollIntoView();
     83                var team = filter ? filter.find('select[name="team"]').val() : null;
     84                var club_id = (wrapper.data('club_id') && !team) ? wrapper.data('club_id') : null;
     85                jQuery.post(eh_gms_feed_ajax_obj.ajax_url, { _ajax_nonce: eh_gms_feed_ajax_obj.nonce, action: "get_gms_table", method: 'api', show: 'fixture', club_id: club_id, options: 'id:' + fixture })
     86                    .always(function() {
     87                        loader.hide();
     88                    })
     89                    .done(function(data) {
     90                        message.hide();
     91                        detail.html(data);
     92                        detail.show();
     93                        detail[0].scrollIntoView();
     94                        if (filter && !team) club_team(message, filter, wrapper, detail);
     95                        var goback = jQuery('<button type="button" class="gms-button">Go Back</button>').appendTo(detail);
     96                        goback.on('click', function(e) {
     97                            detail.hide();
     98                            if (filter) filter.show();
     99                            wrapper.show();
     100                            fixturelink.scrollIntoView({ behavior: 'smooth', block: 'center' });
     101                        });
     102                    })
     103                    .fail(function(response) {
     104                        detail.html('');
     105                        message.text(error_message);
     106                        if (filter) filter.show();
     107                        wrapper.show();
     108                    });
     109            });
     110        });
     111    }
     112
    65113    jQuery('div.gms-ajax').each(function() {
    66114   
     
    69117        if (ele.attr('data-request') != 'true') {
    70118            ele.attr('data-request','true');
    71             var message = jQuery('<p style="text-align: center; display: none"></p>').insertBefore(ele);
     119            var message = jQuery('<p style="text-align: center; display: none; scroll-margin-top: 1rem"></p>').insertBefore(ele);
    72120            var loader = jQuery('<div class="gms-loader" style="display: none"></div>').insertBefore(ele);
    73121            message.text('Retrieving GMS Table');
     
    81129            .done(function(data) {
    82130                message.hide();
     131                var filter;
    83132                if (method=='api-dynamic') {
    84133                    ele.html(data.html);
    85134                    message.before(data.filter);
    86                     var filter = message.prev();
     135                    filter = message.prev();
    87136                    filter.find('select[name="team"]').on('change', function(e) {
    88137                        team_change(message, filter, ele, e.target.value);
     
    111160                            message.hide();
    112161                            ele.html(data);
    113                             club_team(message, filter, ele);
     162                            if (options && options.includes('showDetail:yes')) fixture_detail(message, filter, loader, ele);
     163                            else club_team(message, filter, ele);
    114164                        })
    115165                        .fail(function(response) {
     
    122172                        ele.html(refresh_message);
    123173                    });
    124                     club_team(message, filter, ele);
     174                    if (!(options && options.includes('showDetail:yes'))) club_team(message, filter, ele);
    125175                }
    126176                else ele.html(data);
    127                 if (options && options.includes('showCal:yes')) ele.on('click', '.gms-copy', function(event) {
    128                     var text = event.target.dataset.copy_text;
    129                     var ele = document.getElementById(event.target.dataset.copy_id);
    130                     if (text) ele.textContent = text;
    131                     var range = document.createRange();
    132                     var selection = window.getSelection();
    133                     range.selectNodeContents(ele);
    134                     selection.removeAllRanges();
    135                     selection.addRange(range);
    136                     document.execCommand('copy');
    137                 });
     177                if (options) {
     178                    if (options.includes('showDetail:yes')) {
     179                        jQuery('<div class="gms-fixture" style="scroll-margin-top: 1rem"></div>').insertAfter(ele);
     180                        fixture_detail(message, filter, loader, ele);
     181                    }
     182                    if (options.includes('showCal:yes')) ele.on('click', '.gms-copy', function(event) {
     183                        var text = event.target.dataset.copy_text;
     184                        var ele = document.getElementById(event.target.dataset.copy_id);
     185                        if (text) ele.textContent = text;
     186                        var range = document.createRange();
     187                        var selection = window.getSelection();
     188                        range.selectNodeContents(ele);
     189                        selection.removeAllRanges();
     190                        selection.addRange(range);
     191                        document.execCommand('copy');
     192                    });
     193                }
    138194            })
    139195            .fail(function(response) {
  • eh-gms-feed/tags/3.10/readme.txt

    r3042119 r3046250  
    33Tags: hockey, GMS
    44Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&[email protected]&currency_code=GBP&item_name=Donation+for+EH+GMS+Feed
    5 Tested up to: 6.2
     5Tested up to: 6.3
    66Requires PHP: 5.3
    7 Stable tag: 3.9
     7Stable tag: 3.10
    88License: GPLv2
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    6363== Changelog ==
    6464
     65= 3.10 =
     66* Added option to click through to fixture details
     67* Added status to fixture card e.g. for walkover and shootout result
     68* Change to default CSS for fixture details
     69* Fix to filter when selecting club team in multiple competitions
     70
    6571= 3.9 =
    6672* Added option to provide link to WebCal with club teams list
  • eh-gms-feed/trunk/css/gms-default.css

    r2981152 r3046250  
    88.gms-filter fieldset { width: fit-content }
    99.gms-filter legend { padding: 0px }
     10.gms-detaillink { cursor: pointer }
     11.gms-detaillink:hover { background-color: yellow }
    1012
    1113/* This styling sets alignment for specific tables */
     
    2628@media screen and (max-width: 767px) { .gms-table { overflow-x: auto; display: block; white-space: nowrap } .gms-nomobile { display: none } }
    2729
    28 /* Styling for fixtures and results displayed as list */
     30/* Styling for fixtures and results displayed as list and fixture details */
    2931.gms-list > * + * { margin-top: 1.5rem; margin-bottom: 1.5rem }
     32.gms-list + .gms-footnote { margin-top: 1rem }
    3033.gms-card { text-align: center; padding: 3px 3px; border-radius: 0.5rem }
    31 .gms-card, .gms-cardtime { border: 1px solid; border-color: silver }
    32 .gms-cardfixture { display: flex; gap: 0.5rem; align-items: center }
     34.gms-card, .gms-cardtime, .gms-cardnoscore, .gms-fixturedetails > div { border: 1px solid; border-color: silver }
     35.gms-cardtitle { font-weight: 700; font-size:larger }
     36.gms-cardfixture, .gms-cardscorers { display: flex; gap: 0.5rem; align-items: center }
    3337.gms-cardhome { flex: 1 1 0%; text-align: right }
    3438.gms-carddivide { padding: 0.25rem 0.5rem }
    35 .gms-cardtime { font-weight: 700; border-radius: 0.375rem; background-color: white }
     39.gms-cardtime, .gms-cardnoscore { font-weight: 700; border-radius: 0.375rem; background-color: white }
    3640.gms-cardaway { flex: 1 1 0%; text-align: left }
    37 .gms-list + .gms-footnote { margin-top: 1rem }
     41.gms-cardscorers { font-size: smaller }
     42.gms-cardstatus { background-color: black; color: white; margin: 0.25rem auto; width:fit-content; padding: 0.25rem 0.5rem }
     43.gms-fixture .gms-card > * { margin-top: 0.5rem; margin-bottom: 0.5rem }
     44.gms-fixturedetails { display: flex; flex-wrap: wrap; gap: 1rem }
     45.gms-fixturedetails > div { flex-grow: 1; padding: 0.5rem 0.5rem; border-radius: 0.5rem }
     46.gms-fixturedetails img { display: inline; width: 1.5rem; height: 1.5rem; vertical-align: middle; margin-right: 0.25rem }
     47.gms-fixturedetails ul { list-style-type: none; padding: 0; margin: 0 }
     48.gms-players li { display: flex; align-items: center }
     49.gms-players svg { width: 1rem; height: 1rem }
    3850
    3951/* Creates a loader image for the AJAX wait */
  • eh-gms-feed/trunk/eh-gms-feed.php

    r3042119 r3046250  
    44 * Plugin URI: https://wordpress.org/plugins/eh-gms-feed/
    55 * Description: Show fixtures, results and tables from England Hockey GMS
    6  * Version: 3.9
     6 * Version: 3.10
    77 * Author: Matthew Treherne
    88 * Author URI: https://profiles.wordpress.org/mtreherne
  • eh-gms-feed/trunk/includes/main-class.php

    r3042119 r3046250  
    1010class EH_GMS_Feed {
    1111
    12     private $basename, $settings, $atts_show, $not_valid, $filter_match, $table_name, $fixture_data, $display_name, $show_gender, $show_list, $show_cal, $cal_summary;
     12    private $basename, $settings, $atts_show, $not_valid, $filter_match, $table_name, $fixture_data, $display_name, $show_gender, $show_list, $show_cal, $cal_summary, $id, $show_detail;
    1313    private $club_link, $team_link, $comp_link, $team_comps, $comp_name;
    1414    private $args = ['method','show','team','comp_id','club_id','whatson','link','sort_by','options'];
     
    2222        'compsinfixtures' => ['suffix' => 'fixturesandresults', 'transient' => 'TEAM', 'keys' => ['teams'], 'error_bag' => 'competition', 'expiry' => 'default'],
    2323        'competition' => ['suffix' => '', 'transient' => 'COMPETITION SUMMARY', 'keys' => ['competitions'], 'error_bag' => null, 'expiry' => 'default'],
     24        'fixture' => ['suffix' => '', 'transient' => 'FIXTURE', 'keys' => ['fixtures'], 'error_bag' => null, 'expiry' => 'default'],
    2425    ];
    2526
     
    176177    }
    177178
     179    private function show_goals ($events) {
     180        $goals = [];
     181        foreach ($events as $event) if (in_array($event->eventType,['FG','PC','PS'])) $goals[$event->memberId][] = $event;
     182        $showGoals = [];
     183        foreach ($goals as $goalsById) {
     184            $playerName = '';
     185            $playerGoals = [];
     186            foreach ($goalsById as $goal) {
     187                if (!$playerName) $playerName = $goal->displayName;
     188                $playerGoals[] = ($goal->minute ? $goal->minute . '&prime; ' : '') . $goal->eventType;
     189            }
     190            $showGoals[] = $playerName . ' (' . implode(', ',$playerGoals) . ')';
     191        }
     192        return implode(', ', $showGoals);
     193    }
     194
     195    private function show_players($players) {
     196        $showPlayers = '';
     197        $withheld = 0;
     198        foreach ($players as $player) {
     199            if (!($player->consent || isset($player->shirtNumber))) { $withheld += 1; continue; }
     200            $playerEvents = [];
     201            foreach ($player->playerEvents as $event) {
     202                switch ($event->eventType) {
     203                    case 'GC': $showType = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M1.892 20.5 12 3.959 22.109 20.5z" fill="#0FBD00" stroke="#0DA300"/></svg>'; break;
     204                    case 'YC': $showType = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><rect x="3.5" y=".5" width="17" height="23" rx="1.5" fill="#FFE500" stroke="#DBCA39"/></svg>'; break;
     205                    case 'RC': $showType = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10.5" fill="#E0251B" stroke="#E0251B"/></svg>'; break;
     206                    default : $showType = '<b>'.$event->eventType.'</b>';
     207                }
     208                $playerEvents[] = ($event->minute ? '<b>'.$event->minute . '&prime;&nbsp;</b>' : '') . $showType;
     209            }
     210            switch ($player->otherRoleDescription) {
     211                case 'Goalkeeper' : $role = ' (GK)'; break;
     212                case 'Captain' : $role = ' (C)'; break;
     213                default : $role = '';
     214            }
     215            $showPlayers .= '<li>'.($player->shirtNumber ?? '') . ' ' . $player->displayName . $role . (!empty($playerEvents) ? ('&nbsp;' . implode(',&nbsp;',$playerEvents)) : '') . '</li>';
     216        }
     217        if ($withheld) $showPlayers .= ($withheld > 1) ? '<li>Names Withheld (&times;'.$withheld.')</li>' : '<li>Name Withheld</li>';
     218        return $showPlayers;
     219    }
     220
     221    private function show_officials($officials) {
     222        $showOfficials = '';
     223        foreach ($officials as $official) {
     224            if ($official->displayName != 'Name Withheld') $showOfficials .= '<li>' . $official->role . ': ' . $official->displayName . '</li>';
     225        }
     226        return $showOfficials;
     227    }
     228
     229    private function fixture_summary ($fixture, $valid_date, $show_detail=false) {
     230        $html = '';
     231        $fixture_card = [
     232            'Date' => $valid_date->format('d M Y'),
     233            'Time' => $fixture->fixtureTime == '00:00' ? '' : $fixture->fixtureTime,
     234            'Home Team' => $fixture->homeTeam->teamName,
     235            'Score' => '',
     236            'Away Team' => $fixture->awayTeam->teamName,
     237            'Venue' => !empty($fixture->venue) ? ($this->show_detail ? esc_html($fixture->venue) : '<a href="https://www.google.com/maps/search/?api=1&query='.urlencode($fixture->venue).'" target="_blank">'.esc_html($fixture->venue).'</a>') : '',
     238        ];
     239        if ($show_detail) {
     240            $home_goals = $this->show_goals($fixture->homeTeamEvents);
     241            $away_goals = $this->show_goals($fixture->awayTeamEvents);
     242            $address = !empty($fixture->venueDetails->address) ? $fixture->venueDetails->address . (!empty($fixture->venueDetails->postCode) ? ','.$fixture->venueDetails->postCode : '') : '';
     243        }
     244        $score_class = '';
     245        $home_attr = $away_attr = $home_class = $away_class = [];
     246        if ($fixture->isResult && !$fixture->isBye) {
     247            $fixture_card['Score'] = $fixture->homeTeamScore . ' : ' . $fixture->awayTeamScore;
     248            if ($fixture->status == 'Postponed' || ($fixture->homeTeamScore == 'P' && $fixture->awayTeamScore == 'P'));
     249            elseif ($fixture->status == 'Cancelled' || ($fixture->homeTeamScore == 'C' && $fixture->awayTeamScore == 'C'));
     250            elseif ($fixture->homeTeamScore == $fixture->awayTeamScore) $score_class = 'gms-draw';
     251            elseif (($fixture->homeTeam->id == $this->atts_show['team'] || ($this->is_clubwide() && $fixture->homeTeam->clubId == $this->atts_show['club_id'])) && $fixture->homeTeamScore > $fixture->awayTeamScore) $score_class = 'gms-win';
     252            elseif (($fixture->awayTeam->id == $this->atts_show['team'] || ($this->is_clubwide() && $fixture->awayTeam->clubId == $this->atts_show['club_id'])) && $fixture->homeTeamScore < $fixture->awayTeamScore) $score_class = 'gms-win';
     253            else $score_class = 'gms-loss';
     254        }
     255        if ($this->is_clubteam($fixture->homeTeam) && $this->is_clubwide()) {
     256            $home_class[] = 'gms-clubteam';
     257            $home_attr[] = 'data-team="'.($fixture->homeTeam->id).'"';
     258            if ($this->show_gender) $fixture_card['Home Team'] .= ' ('.$fixture->homeTeam->gender.')';
     259        }
     260        if ($this->is_clubteam($fixture->awayTeam) && $this->is_clubwide()) {
     261            $away_class[] = 'gms-clubteam';
     262            $away_attr[] = 'data-team="'.($fixture->awayTeam->id).'"';
     263            if ($this->show_gender) $fixture_card['Away Team'] .= ' ('.$fixture->awayTeam->gender.')';
     264        }
     265        if ($this->show_list) {
     266            $statusDisplay = !in_array($fixture->status, ['Active','Result','Bye']) ? $fixture->status : '';
     267            if ($fixture->isResult && ($fixture->homeTeamShootoutScore > 0 || $fixture->awayTeamShootoutScore > 0)) $statusDisplay = 'Shootout '.$fixture->homeTeamShootoutScore.' - '. $fixture->awayTeamShootoutScore;
     268            $home_attr[] = 'class="'.implode(' ',$home_class).'"';
     269            $away_attr[] = 'class="'.implode(' ',$away_class).'"';
     270            if ($fixture->isBye) {
     271                $divide = '- : -';
     272                $divide_attr = ' class="gms-carddivide gms-cardnoscore"';
     273            }
     274            elseif ($fixture->isResult) {
     275                $divide = $fixture_card['Score'];
     276                $divide_attr = ' class="gms-carddivide '.($score_class ?: 'gms-cardnoscore').'"';
     277            }
     278            else {
     279                $divide = $fixture_card['Time'] ?: 'TBC';
     280                $divide_attr = ' class="gms-carddivide gms-cardtime"';
     281            }
     282            $html .= '<div class="gms-card'.($this->show_detail ? ' gms-detaillink' : '').'"'.($this->show_detail ? ' data-fixture="'.$fixture->id.'"': '').'>'
     283                .($show_detail ? '<div class="gms-cardtitle">Fixture Details</div>': '')
     284                .'<div class="gms-carddate">'.$fixture_card['Date'].'</div>'
     285                .'<div class="gms-cardfixture"><div class="gms-cardhome"><div '.implode(' ',$home_attr).'>'.$fixture_card['Home Team'].'</div></div><div'.$divide_attr.'>'.$divide.'</div><div class="gms-cardaway"><div '.implode(' ',$away_attr).'>'.$fixture_card['Away Team'].'</div></div></div>'
     286                .(($show_detail && ($home_goals || $away_goals)) ? '<div class="gms-cardscorers"><div class="gms-cardhome"><div>'.$home_goals.'</div></div><div class="gms-carddivide"></div><div class="gms-cardaway"><div>'.$away_goals.'</div></div></div>' : '')
     287                .($statusDisplay ? '<div class="gms-cardstatus">'.$statusDisplay.'</div>' : '')
     288                .'<div class="gms-cardvenue">'.($fixture_card['Venue'] ?: 'Venue TBC').'</div>'
     289                .($show_detail && $address ? '<div>'.$address.'</div>' : '')
     290                .'</div>';
     291            if ($show_detail) {
     292                $participant_details = false;
     293                $html .= '<div class="gms-fixturedetails">';
     294                foreach (['home','away'] as $team) {
     295                    $showPlayers = $this->show_players($fixture->{$team . 'Players'});
     296                    $showOfficials = $this->show_officials($fixture->{$team. 'TeamOfficials'});
     297                    if ($showPlayers || $showOfficials) {
     298                        $club_logo = $fixture->{$team . 'Team'}->clubLogoUrl ?? null;
     299                        $participant_details = true;
     300                        $html .= '<div>';
     301                        if ($showPlayers) $html .= '<div class="gms-players">'.($club_logo ? '<img src="'.$club_logo.'" onerror="this.style.display=\'none\'"></img>' : '').'<b>'.$fixture->{$team.'Team'}->teamName.'</b><ul>'.$showPlayers.'</ul></div>';
     302                        if ($showOfficials) $html .= '<div class="gms-officials">'.($showPlayers ? '<br/>' : '').'<b>Coaching Roles</b><ul>'.$showOfficials.'</ul></div>';
     303                        $html .= '</div>';
     304                    }
     305                }
     306                $showOfficials = $this->show_officials($fixture->officials);
     307                if ($showOfficials) {
     308                    $participant_details = true;
     309                    $html .= '<div class="gms-officials"><b>Match Officials</b><ul>'.$showOfficials.'</ul></div>';
     310                }
     311                if (!$participant_details) $html .= '<div><b>No more details available</b></div>';
     312                $html .= '</div>';
     313            }
     314        }
     315        else {
     316            $home_attr[] = 'class="'.implode(' ',$home_class).'"';
     317            $away_attr[] = 'class="'.implode(' ',$away_class).'"';
     318            $html .= $this->show_detail ? '<tr class="gms-detaillink" data-fixture="'.$fixture->id.'">': '<tr>';
     319            foreach ($this->fixture_data as $column_title => $field_name) {
     320                $value = $fixture_card[$column_title];
     321                switch ($column_title) {
     322                    case 'Home Team' : $attr = implode(' ',$home_attr); break;
     323                    case 'Away Team' : $attr = implode(' ',$away_attr); break;
     324                    case 'Score' : $attr = 'class="'.$score_class.'"';  break;
     325                    default : $attr = '';
     326                }
     327                $html .= '<td '.$attr.'>'.($column_title != 'Venue' ? esc_html($value) : $value).'</td>';
     328            }
     329            $html .= '</tr>';
     330        }
     331        return $html;
     332    }
     333
    178334    private function process_matches ($fixtures) {
    179335        $html = '';
     
    189345            if ($this->filter_whatson($valid_date)) continue;
    190346            $this->filter_match = true;
    191             $fixture_card = [
    192                 'Date' => $valid_date->format('d M Y'),
    193                 'Time' => $fixture->fixtureTime == '00:00' ? '' : $fixture->fixtureTime,
    194                 'Home Team' => $fixture->homeTeam->teamName,
    195                 'Score' => '',
    196                 'Away Team' => $fixture->awayTeam->teamName,
    197                 'Venue' => !empty($fixture->venue) ? '<a href="https://www.google.com/maps/search/?api=1&query='.urlencode($fixture->venue).'" target="_blank">'.esc_html($fixture->venue).'</a>' : ''
    198             ];
    199             $score_class = '';
    200             $home_attr = $away_attr = $home_class = $away_class = [];
    201             if ($fixture->isResult && !$fixture->isBye) {
    202                 $fixture_card['Score'] = $fixture->homeTeamScore . ' : ' . $fixture->awayTeamScore;
    203                 if ($fixture->status == 'Postponed' || ($fixture->homeTeamScore == 'P' && $fixture->awayTeamScore == 'P'));
    204                 elseif ($fixture->homeTeamScore == $fixture->awayTeamScore) $score_class = 'gms-draw';
    205                 elseif (($fixture->homeTeam->id == $this->atts_show['team'] || ($this->is_clubwide() && $fixture->homeTeam->clubId == $this->atts_show['club_id'])) && $fixture->homeTeamScore > $fixture->awayTeamScore) $score_class = 'gms-win';
    206                 elseif (($fixture->awayTeam->id == $this->atts_show['team'] || ($this->is_clubwide() && $fixture->awayTeam->clubId == $this->atts_show['club_id'])) && $fixture->homeTeamScore < $fixture->awayTeamScore) $score_class = 'gms-win';
    207                 else $score_class = 'gms-loss';
    208             }
    209             if ($this->is_clubteam($fixture->homeTeam) && $this->is_clubwide()) {
    210                 $home_class[] = 'gms-clubteam';
    211                 $home_attr[] = 'data-team="'.($fixture->homeTeam->id).'"';
    212                 if ($this->show_gender) $fixture_card['Home Team'] .= ' ('.$fixture->homeTeam->gender.')';
    213             }
    214             if ($this->is_clubteam($fixture->awayTeam) && $this->is_clubwide()) {
    215                 $away_class[] = 'gms-clubteam';
    216                 $away_attr[] = 'data-team="'.($fixture->awayTeam->id).'"';
    217                 if ($this->show_gender) $fixture_card['Away Team'] .= ' ('.$fixture->awayTeam->gender.')';
    218             }
    219             if ($this->show_list) {
    220                 $home_class[] = 'gms-cardhome';
    221                 $away_class[] = 'gms-cardaway';
    222                 $home_attr[] = 'class="'.implode(' ',$home_class).'"';
    223                 $away_attr[] = 'class="'.implode(' ',$away_class).'"';
    224                 if ($fixture->isResult && !$fixture->isBye) {
    225                     $divide = $fixture_card['Score'];
    226                     $divide_attr = ' class="gms-carddivide '.$score_class.'"';
    227                 }
    228                 else {
    229                     $divide = $fixture_card['Time'] ?: 'TBC';
    230                     $divide_attr = ' class="gms-carddivide gms-cardtime"';
    231                 }
    232                 $html .= '<div class="gms-card"><div class="gms-carddate">'.$fixture_card['Date'].'</div><div class="gms-cardfixture"><div '.implode(' ',$home_attr).'>'.$fixture_card['Home Team'].'</div><div'.$divide_attr.'>'.$divide.'</div><div '.implode(' ',$away_attr).'>'.$fixture_card['Away Team'].'</div></div><div class="gms-cardvenue">'.($fixture_card['Venue'] ?: 'Venue TBC').'</div></div>';               
    233             }
    234             else {
    235                 $home_attr[] = 'class="'.implode(' ',$home_class).'"';
    236                 $away_attr[] = 'class="'.implode(' ',$away_class).'"';
    237                 $html .= '<tr>';
    238                 foreach ($this->fixture_data as $column_title => $field_name) {
    239                     $value = $fixture_card[$column_title];
    240                     switch ($column_title) {
    241                         case 'Home Team' : $attr = implode(' ',$home_attr); break;
    242                         case 'Away Team' : $attr = implode(' ',$away_attr); break;
    243                         case 'Score' : $attr = 'class="'.$score_class.'"';  break;
    244                         default : $attr = '';
    245                     }
    246                     $html .= '<td '.$attr.'>'.($column_title != 'Venue' ? esc_html($value) : $value).'</td>';
    247                 }
    248                 $html .= '</tr>';
    249             }
     347            $html .= $this->fixture_summary($fixture, $valid_date);
    250348        }
    251349        return $html;
     
    380478    }
    381479
     480    private function process_fixture($data) {
     481        $html = '<div class="gms-list">';
     482        $html .= $this->fixture_summary($data, new \DateTime($data->fixtureDate), true);
     483        $html .= '</div>';
     484        $html .= '<div class="gms-footnote">'.sprintf(esc_html__( '[Fixture %2$s also found at%3$s %1$s]', 'eh-gms-feed'), '<a href="'.$this->get_link('fixture', $this->id).'" target="_blank">England Hockey Link</a>', '<span class="gms-nomobile">', '</span>').'</div>';
     485        return $html;
     486    }
     487
    382488    private function get_table() {
    383489        $html = '';
    384490        $tables = [];
     491        if (str_contains($this->atts_show['show'], 'fixture')) $tables[] = 'fixture';
    385492        if (str_contains($this->atts_show['show'], 'league')) $tables[] = 'league';
    386493        if (str_contains($this->atts_show['show'], 'results')) {
     
    395502            if ($table_name == 'fixtures') unset($this->fixture_data['Score']);
    396503            if ($table_name == 'league' && $this->is_competition()) {
    397                 if ($this->atts_show['link'])  $this->comp_link = $this->atts_show['link'];
     504                if ($this->atts_show['link']) $this->comp_link = $this->atts_show['link'];
    398505                $html .= $this->get_json('competition', $this->atts_show['comp_id']);
    399506            }
     
    407514            }
    408515            elseif ($table_name == 'teams' && $this->is_clubwide()) {
    409             if ($this->atts_show['link'])   $this->club_link = $this->atts_show['link'];
     516                if ($this->atts_show['link']) $this->club_link = $this->atts_show['link'];
    410517                $html .= $this->get_json('teamslist', $this->atts_show['club_id']);
     518            }
     519            elseif ($table_name == 'fixture' && $this->id) {
     520                $this->show_list = true;
     521                $html .= $this->get_json('fixture', $this->id);
    411522            }
    412523        }
     
    483594        $this->atts_show['options'] = sanitize_text_field( $this->atts_show['options'] );
    484595        if ($this->atts_show['method'] == 'api' || $this->atts_show['method'] == 'api-dynamic') {
    485             if (empty($this->atts_show['club_id']) && ((!$this->is_competition() && !$this->is_team()) || $this->atts_show['method'] == 'api-dynamic')) {
     596            if (empty($this->atts_show['club_id']) && ((!$this->is_competition() && !$this->is_team() && !$this->atts_show['show'] == 'fixture') || $this->atts_show['method'] == 'api-dynamic')) {
    486597                $message = esc_html__( 'Please enter a Club ID with the shortcode e.g. [gms club_id="19fd1b0c-e11c-46f9-9114-45c2262a1e90"], or set a default Club ID in the plugin settings.', 'eh-gms-feed' );
    487598                $this->not_valid .= '<p>'.$message.'</p>';
     
    495606        }
    496607        foreach (explode('+',$this->atts_show['show']) as $show) {
    497             if (!in_array($show,['fixtures','results','league','teams'])) {
     608            if (!in_array($show,['fixtures','results','league','teams','fixture'])) {
    498609                $message = sprintf(esc_html__( 'Please enter a "show" parameter (%s) equal to "fixtures", "results", "league" or "teams".', 'eh-gms-feed' ), $show ?: 'empty');
    499610                $this->not_valid .= '<p>'.$message.'</p>';
     
    520631            foreach ($options as $option) {
    521632                $option_split = array_map('trim', explode(':', $option));
    522                 if ($option_split[0] == 'showgender' && ($option_split[1] ?? '') == 'yes') $this->show_gender = true;
    523                 if ($option_split[0] == 'showlist' && ($option_split[1] ?? '') == 'yes') $this->show_list = true;
    524                 if ($option_split[0] == 'showcal' && ($option_split[1] ?? '') == 'yes') $this->show_cal = true;
    525                 if ($option_split[0] == 'calsummary') $this->cal_summary = $option_split[1] ?? '';
     633                switch ($option_split[0]) {
     634                    case 'showgender' : if (($option_split[1] ?? '') == 'yes') $this->show_gender = true; break;
     635                    case 'showlist' : if (($option_split[1] ?? '') == 'yes') $this->show_list = true; break;
     636                    case 'showcal' : if (($option_split[1] ?? '') == 'yes') $this->show_cal = true; break;
     637                    case 'calsummary' : $this->cal_summary = $option_split[1] ?? ''; break;
     638                    case 'id' : $this->id = $option_split[1] ?? ''; break;
     639                    case 'showdetail' : if (($option_split[1] ?? '') == 'yes') $this->show_detail = true; break;
     640                }
    526641            }
    527642        }
     
    540655
    541656    public function enqueue_scripts () {
    542         wp_register_script('EH_GMS_Feed', plugin_dir_url(__DIR__).'js/eh-gms-feed.js', ['jquery'], '3.9', true);
     657        wp_register_script('EH_GMS_Feed', plugin_dir_url(__DIR__).'js/eh-gms-feed.js', ['jquery'], '3.10', true);
    543658        wp_localize_script('EH_GMS_Feed', 'eh_gms_feed_ajax_obj', ['ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce('get_gms_table')]);
    544         wp_register_style('EH_GMS_Feed', plugin_dir_url(__DIR__).'css/gms-default.css',[],'3.8');
     659        wp_register_style('EH_GMS_Feed', plugin_dir_url(__DIR__).'css/gms-default.css',[],'3.10');
    545660        if ($this->settings->default_css == 'yes') wp_enqueue_style('EH_GMS_Feed');
    546661    }
  • eh-gms-feed/trunk/js/eh-gms-feed.js

    r3042119 r3046250  
    77    var refresh_message = 'The tables selected will be shown when you click on the <b>REFRESH</b> button.';
    88
    9     function club_team (message, filter, wrapper) {
    10         wrapper.find('.gms-clubteam[data-team]').css('cursor','pointer').on('click', function(e) {
     9    function club_team (message, filter, wrapper, detail) {
     10        var ele = detail ? detail : wrapper;
     11        ele.find('.gms-clubteam[data-team]').css('cursor','pointer').prop('title', 'Select to filter by team').on('click', function(e) {
     12            if (detail) {
     13                detail.hide();
     14                filter.show();
     15                wrapper.show();
     16            }
    1117            var team = e.currentTarget.dataset.team;
    1218            filter.find('select[name="team"]').val(team);
    1319            team_change(message, filter, wrapper, team, function() {
    1420                filter.find('select[name="whatson"]').val('');
    15                 if (filter.find('select[name="comp_id"]').val() != '- All Competitions -' && filter.find('input[type="checkbox"][name="show"][value="results"]').prop('checked')) {
     21                if (filter.find('select[name="comp_id"]').val() != '' && filter.find('input[type="checkbox"][name="show"][value="results"]').prop('checked')) {
    1622                    filter.find('input[type="checkbox"][name="show"][value="league"]').prop('checked',true);
    1723                }
     
    6369    }
    6470
     71    function fixture_detail (message, filter, loader, wrapper) {
     72        var detail = wrapper.next();
     73        wrapper.find('.gms-detaillink[data-fixture]').each(function() {
     74            jQuery(this).on('click', function(e) {
     75                var fixturelink = e.currentTarget;
     76                var fixture = fixturelink.dataset.fixture;
     77                message.text('Retrieving Fixture Details');
     78                if (filter) filter.hide();
     79                wrapper.hide();
     80                message.show();
     81                loader.show();
     82                message[0].scrollIntoView();
     83                var team = filter ? filter.find('select[name="team"]').val() : null;
     84                var club_id = (wrapper.data('club_id') && !team) ? wrapper.data('club_id') : null;
     85                jQuery.post(eh_gms_feed_ajax_obj.ajax_url, { _ajax_nonce: eh_gms_feed_ajax_obj.nonce, action: "get_gms_table", method: 'api', show: 'fixture', club_id: club_id, options: 'id:' + fixture })
     86                    .always(function() {
     87                        loader.hide();
     88                    })
     89                    .done(function(data) {
     90                        message.hide();
     91                        detail.html(data);
     92                        detail.show();
     93                        detail[0].scrollIntoView();
     94                        if (filter && !team) club_team(message, filter, wrapper, detail);
     95                        var goback = jQuery('<button type="button" class="gms-button">Go Back</button>').appendTo(detail);
     96                        goback.on('click', function(e) {
     97                            detail.hide();
     98                            if (filter) filter.show();
     99                            wrapper.show();
     100                            fixturelink.scrollIntoView({ behavior: 'smooth', block: 'center' });
     101                        });
     102                    })
     103                    .fail(function(response) {
     104                        detail.html('');
     105                        message.text(error_message);
     106                        if (filter) filter.show();
     107                        wrapper.show();
     108                    });
     109            });
     110        });
     111    }
     112
    65113    jQuery('div.gms-ajax').each(function() {
    66114   
     
    69117        if (ele.attr('data-request') != 'true') {
    70118            ele.attr('data-request','true');
    71             var message = jQuery('<p style="text-align: center; display: none"></p>').insertBefore(ele);
     119            var message = jQuery('<p style="text-align: center; display: none; scroll-margin-top: 1rem"></p>').insertBefore(ele);
    72120            var loader = jQuery('<div class="gms-loader" style="display: none"></div>').insertBefore(ele);
    73121            message.text('Retrieving GMS Table');
     
    81129            .done(function(data) {
    82130                message.hide();
     131                var filter;
    83132                if (method=='api-dynamic') {
    84133                    ele.html(data.html);
    85134                    message.before(data.filter);
    86                     var filter = message.prev();
     135                    filter = message.prev();
    87136                    filter.find('select[name="team"]').on('change', function(e) {
    88137                        team_change(message, filter, ele, e.target.value);
     
    111160                            message.hide();
    112161                            ele.html(data);
    113                             club_team(message, filter, ele);
     162                            if (options && options.includes('showDetail:yes')) fixture_detail(message, filter, loader, ele);
     163                            else club_team(message, filter, ele);
    114164                        })
    115165                        .fail(function(response) {
     
    122172                        ele.html(refresh_message);
    123173                    });
    124                     club_team(message, filter, ele);
     174                    if (!(options && options.includes('showDetail:yes'))) club_team(message, filter, ele);
    125175                }
    126176                else ele.html(data);
    127                 if (options && options.includes('showCal:yes')) ele.on('click', '.gms-copy', function(event) {
    128                     var text = event.target.dataset.copy_text;
    129                     var ele = document.getElementById(event.target.dataset.copy_id);
    130                     if (text) ele.textContent = text;
    131                     var range = document.createRange();
    132                     var selection = window.getSelection();
    133                     range.selectNodeContents(ele);
    134                     selection.removeAllRanges();
    135                     selection.addRange(range);
    136                     document.execCommand('copy');
    137                 });
     177                if (options) {
     178                    if (options.includes('showDetail:yes')) {
     179                        jQuery('<div class="gms-fixture" style="scroll-margin-top: 1rem"></div>').insertAfter(ele);
     180                        fixture_detail(message, filter, loader, ele);
     181                    }
     182                    if (options.includes('showCal:yes')) ele.on('click', '.gms-copy', function(event) {
     183                        var text = event.target.dataset.copy_text;
     184                        var ele = document.getElementById(event.target.dataset.copy_id);
     185                        if (text) ele.textContent = text;
     186                        var range = document.createRange();
     187                        var selection = window.getSelection();
     188                        range.selectNodeContents(ele);
     189                        selection.removeAllRanges();
     190                        selection.addRange(range);
     191                        document.execCommand('copy');
     192                    });
     193                }
    138194            })
    139195            .fail(function(response) {
  • eh-gms-feed/trunk/readme.txt

    r3042119 r3046250  
    33Tags: hockey, GMS
    44Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&[email protected]&currency_code=GBP&item_name=Donation+for+EH+GMS+Feed
    5 Tested up to: 6.2
     5Tested up to: 6.3
    66Requires PHP: 5.3
    7 Stable tag: 3.9
     7Stable tag: 3.10
    88License: GPLv2
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    6363== Changelog ==
    6464
     65= 3.10 =
     66* Added option to click through to fixture details
     67* Added status to fixture card e.g. for walkover and shootout result
     68* Change to default CSS for fixture details
     69* Fix to filter when selecting club team in multiple competitions
     70
    6571= 3.9 =
    6672* Added option to provide link to WebCal with club teams list
Note: See TracChangeset for help on using the changeset viewer.