コード例 #1
0
ファイル: example_full.php プロジェクト: soi/paul
        $i++;
        echo "<br />";
    }
}
echo "<br /><h3>Generated matches with matchdays but without free tickets</h3><br />";
$roundrobin->free_ticket = false;
// free tickets off
$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);
コード例 #2
0
ファイル: complete_functions.php プロジェクト: soi/paul
function complete_add_season()
{
    if (valid_request(array(isset($_GET['league_id']), isset($_POST['name']), isset($_POST['start']), isset($_POST['schedule']), isset($_POST['max_teams_div'])))) {
        global $smarty;
        global $db;
        if (!preg_match(DATE_REGEX, $_POST['start'])) {
            display_errors(554);
            return true;
        }
        if (strlen($_POST['name']) > 100 || strlen($_POST['name']) < 1) {
            display_errors(552);
            return true;
        }
        if ($_POST['schedule'] > 255 || $_POST['schedule'] < 1) {
            display_errors(553);
            return true;
        }
        $new_div = array();
        foreach ($_POST as $team => $div) {
            //did we hit a team id?
            if (strpos($team, 'team') === 0) {
                $new_div[$div][] = substr($team, 4);
            }
        }
        // test for valid conditions
        foreach ($new_div as $div => $teams) {
            if ($div < 1) {
                display_errors(551);
                return true;
            }
            if (count($teams) > $_POST['max_teams_div']) {
                display_errors(550);
                return true;
            }
            if (count($teams) < 2) {
                display_errors(555);
                return true;
            }
            $div_nums[] = $div;
        }
        //creating the season and divisions
        $sql = "add_season_with_divisions(" . $_GET['league_id'] . ", \n                                              '" . $_POST['name'] . "',\n                                              " . $_POST['schedule'] . ", \n                                              '" . implode(',', $div_nums) . "')";
        $db->run($sql);
        // creating the matches
        require_once 'classes/class.roundrobin.php';
        $rr = new roundrobin();
        $rr->free_ticket = false;
        //iterating over the divisions
        foreach ($new_div as $div => $teams) {
            // getting the division_id of the related division that was just inserted
            $sql = "get_div_id(" . $_GET['league_id'] . ",\n                                   " . $div . ")";
            $db->run($sql);
            $division_id = $db->get_result_row();
            // putting the teams in the new divisions
            $sql = "add_teams_div(" . $division_id['division_id'] . ", \n                                      '" . implode(',', $teams) . "')";
            $db->run($sql);
            //deleting all signed up teams for this league
            $sql = "delete_signed_up_teams(" . $_GET['league_id'] . ")";
            $db->run($sql);
            // inserting the matches of this division one by one...
            shuffle($teams);
            $rr->pass_teams($teams);
            $rr->create_matches();
            if ($rr->finished) {
                $matchday = 1;
                while ($rr->next_matchday()) {
                    while ($match = $rr->next_match()) {
                        $sql = "add_match (" . $division_id['division_id'] . ", \n                                               " . $match[0] . ", \n                                               " . $match[1] . ",\n                                               " . $matchday . ", \n                                               '" . $_POST['start'] . "', \n                                               " . $_POST['schedule'] . ")";
                        $db->run($sql);
                    }
                    $matchday++;
                }
            }
        }
        unset($rr);
        display_success("add_season");
        $smarty->assign('content', $smarty->fetch("succes.tpl"));
    }
}