We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25486
    • 2 Posts
    This is my first post so greetings. I started using modx two days ago. Its the first CMS I’ve used and I have a site pretty much built already. So far its been a really excellent piece of kit and enjoyable to use.

    Anyways, my query is this - I’m building a site for a football team that requires a league table to be regularly updated by my dad (not the most computer literate) Can anyone point me in the right direction of the best course of action to achieve this?

    I’ve had a look at the datagrid widget which looks like it may be good for displaying the data. I don’t have anything other than rudimentary php knowledge.

    many thanks.
      • 25663 MODX Staff
      • 12,272 Posts
      You could use the datagrid widget and an Excel spreadsheet (saved as a CVS file) to accomplish this I suppose. Searching should turn up some interesting threads (and this was just recently discussed elsewhere). There’s a walkthrough I wrote somewhere, but it’s very persnickety and not tolerant of errors.
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 25486
        • 2 Posts
        I found the post about excel and csv and will investigate further.

        many thanks.
          • 25663 MODX Staff
          • 12,272 Posts
          Good luck! laugh
            Ryan Thrash, MODX Co-Founder
            Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
            • 10746
            • 126 Posts
            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
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              This would be a fun use for the CSSPlay calender, only use a TV instead of a chunk. Each day a game is played gets its own document, and the teams playing and the score would be TVs. This way the dates for the games would be displayed in advance, and the scores would be up for games after they are played.
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org