Plugin Directory

Changeset 1928763


Ignore:
Timestamp:
08/22/2018 06:39:47 PM (8 years ago)
Author:
martindrapeau
Message:

Fixed bugs with Calendar and Rankings

File:
1 edited

Legend:

Unmodified
Added
Removed
  • amilia-store/trunk/amilia-store.php

    r1928745 r1928763  
    66Author: Martin Drapeau <martin.drapeau@amilia.com>
    77Copyright: 2014-2017 Amilia
    8 Version: 2.5.3
     8Version: 2.5.4
    99Author URI: http://www.amilia.com/
    1010License: Apache License 2.0
     
    311311    $view = $a['view'];
    312312    $date = $a['date'];
     313    if (empty($date)) $date = date('Y-m-d');
    313314    $time = $a['time'];
    314315    $api = $a['api'];
     
    608609    $label_GD = __("GD", 'amilia-store');
    609610    $label_Pts = __("Pts", 'amilia-store');
     611    $label_Location = __("Location", 'amilia-store');
     612    $label_Date = __("Date/time", 'amilia-store');
    610613    $pleaseWait = __("Please wait...", 'amilia-store');
     614    $rankings = __("Rankings", 'amilia-store');
     615    $games = __("Games", 'amilia-store');
    611616    $warning = __("Less or more than 2 teams meeting at same time and place", 'amilia-store');
    612617
     
    648653            return match && match.length >= 1 ? match[0].trim() : null;
    649654        }
     655        function formatGameDateTime(start, end) {
     656            var startDate = moment(start).format('YYYY-MM-DD');
     657            var startTime = moment(start).format('H:mm');
     658            var endDate = moment(end).format('YYYY-MM-DD');
     659            var endTime = moment(end).format('H:mm');
     660            return startDate + ' ' + startTime + ' - ' + (startDate == endDate ? endTime : (endDate + ' ' + endTime));
     661        }
    650662
    651663        function renderRankings() {
    652             console.log(events.length);
    653 
    654664            var ids = [];
    655665            var id2team = {};
     
    657667            var game2events = {};
    658668            var warnings = [];
     669            var gamesHtml = '';
    659670
    660671            for (var i = 0; i < events.length; i++) {
     
    668679                        }
    669680                    }
    670                     if (!found) break;
     681                    if (!found) continue;
    671682                }
    672683
     
    690701                    id2team[id] = team;
    691702                }
    692                 game = event.Location + ': ' + moment(event.start).format('YYYY-MM-DD hh:mm') + ' - ' + moment(event.end).format('YYYY-MM-DD hh:mm');
     703                game = event.Location + ': ' + formatGameDateTime(event.start, event.end);
    693704                if (!game2events[game]) {
    694705                    game2events[game] = [];
     
    697708                game2events[game].push(event);
    698709            }
     710            console.log(game2events);
    699711
    700712            for (var i = 0; i < games.length; i++) {
     
    707719                    var goals1 = event1.AttendanceSummary && event1.AttendanceSummary.ValueCounts && event1.AttendanceSummary.ValueCounts.GOAL ? event1.AttendanceSummary.ValueCounts.GOAL : 0;
    708720                    var goals2 = event2.AttendanceSummary && event2.AttendanceSummary.ValueCounts && event2.AttendanceSummary.ValueCounts.GOAL ? event2.AttendanceSummary.ValueCounts.GOAL : 0;
    709                     team1.GP += 1;
    710                     team2.GP += 1;
     721                    var gamePlayed = goals1 || goals2 ||
     722                                     (event1.AttendanceSummary && event1.AttendanceSummary.StatusCounts && event1.AttendanceSummary.StatusCounts.Present &&
     723                                      event2.AttendanceSummary && event2.AttendanceSummary.StatusCounts && event2.AttendanceSummary.StatusCounts.Present);
     724                    team1.GP += gamePlayed ? 1 : 0;
     725                    team2.GP += gamePlayed ? 1 : 0;
    711726                    if (goals1 == goals2) {
    712727                        team1.T += 1;
     
    727742                    team1.A += goals2;
    728743                    team2.A += goals1;
     744                    gamesHtml += '<tr>' +
     745                        '<td>' + event1.Location + '</td>' +
     746                        '<td>' + formatGameDateTime(event1.start, event1.end) + '</td>' +
     747                        '<td>' + team1.Name + ' ' + (gamePlayed ? goals1 : '') + '</td>' +
     748                        '<td>' + team2.Name + ' ' + (gamePlayed ? goals2 : '') + '</td>' +
     749                        '</tr>';
    729750                } else {
    730751                    var names = [];
     
    734755                }
    735756            }
     757            document.getElementById('amilia-store-games-tbody').innerHTML = gamesHtml;
     758
     759            var teams = [];
     760            for (var i = 0; i < ids.length; i++) {
     761                teams.push(id2team[ids[i]]);
     762            }
     763            teams.sort(function(a,b) {
     764                if (a.Pts == b.Pts) return 0;
     765                return a.Pts < b.Pts;
     766            });
    736767
    737768            var html = '';
    738             for (var i = 0; i < ids.length; i++) {
    739                 var id = ids[i];
    740                 var team = id2team[id];
     769            for (var i = 0; i < teams.length; i++) {
     770                var team = teams[i];
    741771                html += '<tr>' +
    742772                    '<td class="team">' + team.Name + '</td>' +
     
    751781                    '</tr>';
    752782            }
    753             document.getElementById('amilia-store-table-tbody').innerHTML = html;
     783            document.getElementById('amilia-store-rankings-tbody').innerHTML = html;
    754784
    755785            if (warnings.length) {
    756786                html = '<strong>Warnings!</strong><br/>' + warnings.join('<br/>');
    757                 document.getElementById('amilia-store-table-warnings').innerHTML = html;
     787                document.getElementById('amilia-store-rankings-warnings').innerHTML = html;
    758788            }
    759789        }
     
    808838</style>
    809839<div id="amilia-store-rankings-container">
     840    <h3>$rankings</h3>
    810841    <table class="amilia-store-table">
    811842        <thead>
     
    822853            </tr>
    823854        </thead>
    824         <tbody id="amilia-store-table-tbody">
     855        <tbody id="amilia-store-rankings-tbody">
    825856            <tr><td colspan="9" style="text-align:center;font-style:italic;">$pleaseWait</td></tr>
    826857        </tbody>
    827858    </table>
    828859    <p class="amilia-store-table-legend">$legend</p>
    829     <p id="amilia-store-table-warnings"></p>
     860    <p id="amilia-store-rankings-warnings"></p>
     861    <h3>$games</h3>
     862    <table class="amilia-store-table">
     863        <thead>
     864            <tr>
     865                <th class="location">$label_Location</th>
     866                <th class="date">$label_Date</th>
     867                <th>$label_Team 1</th>
     868                <th>$label_Team 2</th>
     869            </tr>
     870        </thead>
     871        <tbody id="amilia-store-games-tbody">
     872            <tr><td colspan="4" style="text-align:center;font-style:italic;">$pleaseWait</td></tr>
     873        </tbody>
     874    </table>
    830875</div>
    831876EOD;
Note: See TracChangeset for help on using the changeset viewer.