Changeset 14 for trunk/index.php


Ignore:
Timestamp:
Aug 29, 2019, 9:13:06 PM (5 years ago)
Author:
chronos
Message:
  • Modified: Improved summary to show total distance and money.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/index.php

    r13 r14  
    3939      '<a href="'.$this->Link('/runners').'">Runners</a> '.
    4040      '<a href="'.$this->Link('/teams').'">Teams</a> '.
    41       '<a href="'.$this->Link('/families').'">Families</a>'.
     41      '<a href="'.$this->Link('/families').'">Families</a> '.     
    4242      '</div>';
    4343    return($Output);
     
    199199            'Money' => $Item['Money'],
    200200          ));
     201        } else
     202        {
     203          echo('Unsupported type '.$Item['Type'].'. ');
    201204        }
    202205      }   
     
    280283    $PageList = GetPageList($DbRow[0]);
    281284
    282     $Gender = array('', 'Male', 'Female', 'Child');
     285    $Gender = array('', 'Man', 'Woman', 'Kid');
    283286    $Output .= '<div id="list_content">';
    284287    $Output .= $PageList['Output'];
    285288    $TableColumns = array(
    286289      array('Name' => 'Name', 'Title' => 'Name'),
    287       array('Name' => 'Gender', 'Title' => 'Gender'),
     290      array('Name' => 'Gender', 'Title' => 'Category'),
    288291      array('Name' => 'Distance', 'Title' => 'Distance'),
    289292      array('Name' => 'Money', 'Title' => 'Money'),
     
    393396    $PageList = GetPageList($DbRow[0]);
    394397
    395     $Gender = array('', 'Male', 'Female', 'Child');
     398    $Gender = array('', 'Men', 'Woman', 'Kid');
    396399    $Output .= '<div id="list_content">';
    397400    $Output .= $PageList['Output'];
    398401    $TableColumns = array(
    399402      array('Name' => 'Name', 'Title' => 'Name'),
    400       array('Name' => 'Gender', 'Title' => 'Gender'),
     403      array('Name' => 'Gender', 'Title' => 'Category'),
    401404      array('Name' => 'Distance', 'Title' => 'Distance'),
    402405      array('Name' => 'Money', 'Title' => 'Money'),
     
    441444    $PageList = GetPageList($DbRow[0]);
    442445
    443     $Gender = array('', 'Male', 'Female', 'Child');
     446    $Gender = array('', 'Man', 'Woman', 'Kid');
    444447    $Output .= '<div id="list_content">';
    445448    $Output .= $PageList['Output'];
    446449    $TableColumns = array(
    447450      array('Name' => 'Name', 'Title' => 'Name'),
    448       array('Name' => 'Gender', 'Title' => 'Gender'),
     451      array('Name' => 'Gender', 'Title' => 'Category'),
    449452      array('Name' => 'Distance', 'Title' => 'Distance'),
    450453      array('Name' => 'Money', 'Title' => 'Money'),
     
    591594  }
    592595
     596  function GetTotals($Where = '1', $Table = 'Runner')
     597  {
     598    $DbResult = $this->Database->query('SELECT (SELECT COUNT(*) FROM '.$Table.' WHERE '.$Where.') AS TotalCount, '.
     599      '(SELECT SUM(Distance) FROM '.$Table.'Stat LEFT JOIN '.$Table.' ON '.$Table.'.Id='.$Table.'Stat.'.$Table.' WHERE '.$Where.') AS TotalDistance, '.
     600      '(SELECT SUM(Money) FROM '.$Table.'Stat LEFT JOIN '.$Table.' ON '.$Table.'.Id='.$Table.'Stat.'.$Table.' WHERE '.$Where.') AS TotalMoney');     
     601    $DbRow = $DbResult->fetch_assoc();
     602    return $DbRow;
     603  }
     604
    593605  function ShowMain()
    594606  {
    595607    $Output = '';
    596     $DbResult = $this->Database->select('Runner', 'COUNT(*) AS Total');
    597     $DbRow = $DbResult->fetch_assoc();
    598     $RunnersCount = $DbRow['Total'];
    599 
    600     $Output = '';
    601     $DbResult = $this->Database->select('Runner', 'COUNT(*) AS Total', 'Gender=1');
    602     $DbRow = $DbResult->fetch_assoc();
    603     $MenCount = $DbRow['Total'];
    604 
    605     $Output = '';
    606     $DbResult = $this->Database->select('Runner', 'COUNT(*) AS Total', 'Gender=2');
    607     $DbRow = $DbResult->fetch_assoc();
    608     $WomenCount = $DbRow['Total'];
    609 
    610     $Output = '';
    611     $DbResult = $this->Database->select('Runner', 'COUNT(*) AS Total', 'Gender=3');
    612     $DbRow = $DbResult->fetch_assoc();
    613     $KidsCount = $DbRow['Total'];
    614 
    615     $DbResult = $this->Database->select('Team', 'COUNT(*) AS Total', 'IsFamily=0');
    616     $DbRow = $DbResult->fetch_assoc();
    617     $TeamsCount = $DbRow['Total'];
    618 
    619     $DbResult = $this->Database->select('Team', 'COUNT(*) AS Total', 'IsFamily=1');
    620     $DbRow = $DbResult->fetch_assoc();
    621     $FamiliesCount = $DbRow['Total'];
     608    $Runners = $this->GetTotals();
     609    $Men = $this->GetTotals('Runner.Gender=1', 'Runner');
     610    $Women = $this->GetTotals('Runner.Gender=2', 'Runner');
     611    $Kids = $this->GetTotals('Runner.Gender=3', 'Runner');
     612    $Teams = $this->GetTotals('Team.IsFamily=0', 'Team');
     613    $Families = $this->GetTotals('Team.IsFamily=1', 'Team');
    622614   
     615    $Output .= '<p>This website collects data from offical <a href="http://leaderboard.teribear.cz/">leaderboard</a> site and track and present progress of runners.</p>';
    623616    $Output .= '<div class="page-title">Summary</div>';
    624617    $Output .= '<table class="WideTable">';
    625     $Output .= '<tr><th>Category</th><th>Total count</th></tr>';
    626     $Output .= '<tr><td>Runners</td><td>'.$RunnersCount.'</td></tr>';
    627     $Output .= '<tr><td>Men</td><td>'.$MenCount.'</td></tr>';
    628     $Output .= '<tr><td>Women</td><td>'.$WomenCount.'</td></tr>';
    629     $Output .= '<tr><td>Kids</td><td>'.$KidsCount.'</td></tr>';
    630     $Output .= '<tr><td>Teams</td><td>'.$TeamsCount.'</td></tr>';
    631     $Output .= '<tr><td>Families</td><td>'.$FamiliesCount.'</td></tr>';
     618    $Output .= '<tr><th>Category</th><th>Count</th><th>Distance [km]</th><th>Money [Kč]</th></tr>';
     619    $Output .= '<tr><td>Everyone</td><td>'.$Runners['TotalCount'].'</td><td>'.$Runners['TotalDistance'].'</td><td>'.$Runners['TotalMoney'].'</td></tr>';
     620    $Output .= '<tr><td>Men</td><td>'.$Men['TotalCount'].'</td><td>'.$Men['TotalDistance'].'</td><td>'.$Men['TotalMoney'].'</td></tr>';
     621    $Output .= '<tr><td>Women</td><td>'.$Women['TotalCount'].'</td><td>'.$Women['TotalDistance'].'</td><td>'.$Women['TotalMoney'].'</td></tr>';
     622    $Output .= '<tr><td>Kids</td><td>'.$Kids['TotalCount'].'</td><td>'.$Kids['TotalDistance'].'</td><td>'.$Kids['TotalMoney'].'</td></tr>';
     623    $Output .= '<tr><td>Teams</td><td>'.$Teams['TotalCount'].'</td><td>'.$Teams['TotalDistance'].'</td><td>'.$Teams['TotalMoney'].'</td></tr>';
     624    $Output .= '<tr><td>Families</td><td>'.$Families['TotalCount'].'</td><td>'.$Families['TotalDistance'].'</td><td>'.$Families['TotalMoney'].'</td></tr>';
    632625    $Output .= '</table>';
    633626
Note: See TracChangeset for help on using the changeset viewer.