It’s a nice problem for which there are many possible solutions...
Here’s one very simple approach with negligible learning time for Dad, and not much for you...
Use a CHUNK to store the results in some simple format
A:4-B:0
C:2-D:1
A:3-C:3
B:2-D:0
A:1-D:3
B:2-C:2
Each week (or whatever), Dad edits the chunk and adds the latest round of results... the teams here are called ’A’, ’B’, ’C’ and ’D’ but use whatever you want..
Then use a snippet to PARSE the chunk, extract the results and produce as output the league table. It’s not hard to do, and I whipped up a sort of "proof of concept" as follows .. it doesn’t SORT the output of the league table, but that wouldn’t be hard to add..
(Although you didn’t mention what brand of football you were referring to, I am assuming soccer, hence 3 pts for a win, 1 for a draw etc)
This bit of code just shows how you might read each line of the chunk, then split it into the home team, away team and their respective scores. The array $table is a 2d-associative array with one subarray for each team, which is filled in as each result is parsed..
NOTE: This is not well written - it contains no comments or error-checking and is just a prototype to see how easy it would be to do. It is not reusable, templated or generally MODx-ified.
<?php
$results = explode("\n",$modx->getChunk('FootyResults'));
$initial = array ('played'=>0, 'win'=>0, 'lose'=>0, 'draw'=>0, 'for'=>0, 'against'=>0, 'points'=>0);
$table = array('A'=>$initial, 'B'=>$initial, 'C'=>$initial, 'D'=>$initial);
foreach ($results as $game) {
$game = trim($game);
if (strpos($game,"-")) {
$scores = explode("-",$game);
list($hometeam,$homescore) = explode(":",$scores[0]);
list($awayteam,$awayscore) = explode(":",$scores[1]);
$table[$hometeam]['played']++;
$table[$awayteam]['played']++;
$table[$hometeam]['for']+=$homescore;
$table[$awayteam]['for'] += $awayscore;
$table[$hometeam]['against']+=$awayscore;
$table[$awayteam]['against'] += $homescore;
if ($homescore > $awayscore) {
$table[$hometeam]['win']++;
$table[$awayteam]['lose']++;
$table[$hometeam]['points'] += 3;
}
if ($homescore < $awayscore) {
$table[$hometeam]['lose']++;
$table[$awayteam]['win']++;
$table[$awayteam]['points'] += 3;
}
if ($homescore == $awayscore) {
$table[$hometeam]['draw']++;
$table[$awayteam]['draw']++;
$table[$hometeam]['points'] += 1;
$table[$awayteam]['points'] += 1;
}
}
}
$output = "<table>";
$output .= "<tr><th>Team</th><th>P</th><th>W</th><th>L</th><th>D</th><th>F</th><th>A</th><th>Pts</th></tr>";
foreach ($table as $team=>$outcome) {
$output .= "<tr><td>$team</td>";
$output .= "<td>".$outcome['played']."</td>";
$output .= "<td>".$outcome['win']."</td>";
$output .= "<td>".$outcome['lose']."</td>";
$output .= "<td>".$outcome['draw']."</td>";
$output .= "<td>".$outcome['for']."</td>";
$output .= "<td>".$outcome['against']."</td>";
$output .= "<td>".$outcome['points']."</td></tr>";
}
$output .="</table>";
return $output;
?>
Call the chunk "FootyResults" and the snippet "FootyTable" and in your document just include
[[FootyTable]]
wherever you want it to be..
HTH
Gordon