PHP Classes

File: example_full.php

Recommend this page to a friend!
  Classes of Felix Stiehler   Round Robin Class   example_full.php   Download  
File: example_full.php
Role: Example script
Content type: text/plain
Description: all features
Class: Round Robin Class
Schedule season matches using round robin
Author: By
Last change: Minor changes due to match day feature added in the main class
Date: 14 years ago
Size: 2,307 bytes
 

Contents

Class file image Download
<?php
require('class.roundrobin.php');

// Let's see how 7 of the best british football teams fight against each other
$teams = array ('Banbury United',
               
'Bashley',
               
'Bedford Town',
               
'Brackley Town',
               
'Cambridge City',
               
'Chippenham Town',
               
'Clevedon Town');


$roundrobin = new roundrobin($teams);

// Generated matches with matchdays and free tickets - because we have an uneven number of teams
echo "<h3>Generated matches with matchdays and free tickets</h3><br />";
$roundrobin->free_ticket_identifer = "FREE TICKET"; //default is "free ticket"
$roundrobin->create_matches();

// Did everything went right?
if ($roundrobin->finished) {
   
$i = 1;
   
//Ok, iterating over the matchdays...
   
while ($roundrobin->next_matchday() !== false) {
        echo
"-------Matchday ".$i."-------<br />";
       
//...and the matches of one match day
       
while ($match = $roundrobin->next_match()) {
            echo
$match[0]." <b>vs</b> ".$match[1]."<br />";
        }
       
$i++;
        echo
"<br />";
    }
}



echo
"<br /><h3>Generated matches with 4 match days and without free tickets</h3><br />";
$roundrobin->free_ticket = false; // free tickets off
$roundrobin->matchday_count = 4;
$roundrobin->create_matches();

if (
$roundrobin->finished) {
   
$i = 1;
    while (
$roundrobin->next_matchday()) {
        echo
"-------Matchday ".$i."-------<br />";
        while (
$match = $roundrobin->next_match()) {
            echo
$match[0]." <b>vs</b> ".$match[1]."<br />";
        }
       
$i++;
        echo
"<br />";
    }
}



echo
"<br /><h3>Generated matches without matchdays and changed teams </h3><br />";
$teams = array('John',
              
'Mike',
              
'Martin',
              
'Ron',
              
'Richard');

$roundrobin->pass_teams($teams);
$roundrobin->create_raw_matches();

if (
$roundrobin->finished) {
    while (
$match = $roundrobin->next_match()) {
        echo
$match[0]." <b>vs</b> ".$match[1]."<br />";
    }
    echo
"<br />";
}


echo
"<h3>Simply accessing the matches/matchdays in array format (contains the result from the last match generation)</h3><br />";
print_r($roundrobin->matches);

?>