Example #1
0
 public function run()
 {
     DB::table('matches')->delete();
     Match::create(array('myChar' => 'Akuma', 'opponentChar' => 'Cammy', 'result' => 'Win'));
     Match::create(array('myChar' => 'Juri', 'opponentChar' => 'Chun-li', 'result' => 'Draw'));
     Match::create(array('myChar' => 'Ryu', 'opponentChar' => 'Rose', 'result' => 'Loss'));
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('matches')->delete();
     Match::create(array('team_a' => 'England', 'team_b' => 'Fiji', 'pool' => 'A', 'match_date' => new DateTime('2015-09-18')));
     Match::create(array('team_a' => 'Tonga', 'team_b' => 'Georgia', 'pool' => 'C', 'match_date' => new DateTime('2015-09-19')));
     Match::create(array('team_a' => 'Ireland', 'team_b' => 'Canada', 'pool' => 'D', 'match_date' => new DateTime('2015-09-19')));
     Match::create(array('team_a' => 'South Africa', 'team_b' => 'Japan', 'pool' => 'B', 'match_date' => new DateTime('2015-09-19')));
     Match::create(array('team_a' => 'France', 'team_b' => 'Italy', 'pool' => 'D', 'match_date' => new DateTime('2015-09-19')));
     Match::create(array('team_a' => 'Samoa', 'team_b' => 'USA', 'pool' => 'B', 'match_date' => new DateTime('2015-09-20')));
     Match::create(array('team_a' => 'Wales', 'team_b' => 'Uruguay', 'pool' => 'A', 'match_date' => new DateTime('2015-09-20')));
     Match::create(array('team_a' => 'New Zealand', 'team_b' => 'Argentina', 'pool' => 'C', 'match_date' => new DateTime('2015-09-20')));
     Match::create(array('team_a' => 'Scotland', 'team_b' => 'Japan', 'pool' => 'B', 'match_date' => new DateTime('2015-09-23')));
     Match::create(array('team_a' => 'Australia', 'team_b' => 'Fiji', 'pool' => 'A', 'match_date' => new DateTime('2015-09-23')));
     Match::create(array('team_a' => 'France', 'team_b' => 'Romania', 'pool' => 'D', 'match_date' => new DateTime('2015-09-23')));
     Match::create(array('team_a' => 'New Zealand', 'team_b' => 'Namibia', 'pool' => 'C', 'match_date' => new DateTime('2015-09-24')));
     Match::create(array('team_a' => 'Argentina', 'team_b' => 'Georgia', 'pool' => 'C', 'match_date' => new DateTime('2015-09-25')));
     Match::create(array('team_a' => 'Italy', 'team_b' => 'Canada', 'pool' => 'D', 'match_date' => new DateTime('2015-09-26')));
     Match::create(array('team_a' => 'South Africa', 'team_b' => 'Samoa', 'pool' => 'B', 'match_date' => new DateTime('2015-09-26')));
     Match::create(array('team_a' => 'England', 'team_b' => 'Wales', 'pool' => 'A', 'match_date' => new DateTime('2015-09-26')));
     Match::create(array('team_a' => 'Australia', 'team_b' => 'Uruguay', 'pool' => 'A', 'match_date' => new DateTime('2015-09-27')));
     Match::create(array('team_a' => 'Scotland', 'team_b' => 'USA', 'pool' => 'B', 'match_date' => new DateTime('2015-09-27')));
     Match::create(array('team_a' => 'Ireland', 'team_b' => 'Romania', 'pool' => 'D', 'match_date' => new DateTime('2015-09-27')));
     Match::create(array('team_a' => 'Tonga', 'team_b' => 'Namibia', 'pool' => 'C', 'match_date' => new DateTime('2015-09-29')));
     Match::create(array('team_a' => 'Wales', 'team_b' => 'Fiji', 'pool' => 'A', 'match_date' => new DateTime('2015-10-01')));
     Match::create(array('team_a' => 'France', 'team_b' => 'Canada', 'pool' => 'D', 'match_date' => new DateTime('2015-10-01')));
     Match::create(array('team_a' => 'New Zealand', 'team_b' => 'Georgia', 'pool' => 'C', 'match_date' => new DateTime('2015-10-02')));
     Match::create(array('team_a' => 'Samoa', 'team_b' => 'Japan', 'pool' => 'B', 'match_date' => new DateTime('2015-10-03')));
     Match::create(array('team_a' => 'South Africa', 'team_b' => 'Scotland', 'pool' => 'B', 'match_date' => new DateTime('2015-10-03')));
     Match::create(array('team_a' => 'England', 'team_b' => 'Australia', 'pool' => 'A', 'match_date' => new DateTime('2015-10-03')));
     Match::create(array('team_a' => 'Argentina', 'team_b' => 'Tonga', 'pool' => 'C', 'match_date' => new DateTime('2015-10-04')));
     Match::create(array('team_a' => 'Ireland', 'team_b' => 'Italy', 'pool' => 'D', 'match_date' => new DateTime('2015-10-04')));
     Match::create(array('team_a' => 'Canada', 'team_b' => 'Romania', 'pool' => 'D', 'match_date' => new DateTime('2015-10-06')));
     Match::create(array('team_a' => 'Fiji', 'team_b' => 'Uruguay', 'pool' => 'A', 'match_date' => new DateTime('2015-10-06')));
     Match::create(array('team_a' => 'South Africa', 'team_b' => 'USA', 'pool' => 'B', 'match_date' => new DateTime('2015-10-07')));
     Match::create(array('team_a' => 'Namibia', 'team_b' => 'Georgia', 'pool' => 'C', 'match_date' => new DateTime('2015-10-07')));
     Match::create(array('team_a' => 'New Zealand', 'team_b' => 'Tonga', 'pool' => 'C', 'match_date' => new DateTime('2015-10-09')));
     Match::create(array('team_a' => 'Samoa', 'team_b' => 'Scotland', 'pool' => 'B', 'match_date' => new DateTime('2015-10-10')));
     Match::create(array('team_a' => 'Australia', 'team_b' => 'Wales', 'pool' => 'A', 'match_date' => new DateTime('2015-10-10')));
     Match::create(array('team_a' => 'England', 'team_b' => 'Uruguay', 'pool' => 'A', 'match_date' => new DateTime('2015-10-10')));
     Match::create(array('team_a' => 'Argentina', 'team_b' => 'Namibia', 'pool' => 'C', 'match_date' => new DateTime('2015-10-11')));
     Match::create(array('team_a' => 'Italy', 'team_b' => 'Romania', 'pool' => 'D', 'match_date' => new DateTime('2015-10-11')));
     Match::create(array('team_a' => 'France', 'team_b' => 'Ireland', 'pool' => 'D', 'match_date' => new DateTime('2015-10-11')));
     Match::create(array('team_a' => 'USA', 'team_b' => 'Japan', 'pool' => 'B', 'match_date' => new DateTime('2015-10-11')));
 }
Example #3
0
if (strlen($hteam) == 0 || strlen($ateam) == 0) {
    $mess = "Missing teams?";
    include 'php/wrongentry.php';
}
$dat = new Matchdate();
$dat->frompost();
$mtch = new Match(0, $div);
$mtch->set_hometeam($hteam);
$mtch->set_awayteam($ateam);
$mtch->Date = $dat;
$mtch->Slackdays = $slack;
try {
    // Fetch the team details not because we need them, but
    // so as to check for garbled team names.
    $mtch->fetchteams();
    $mtch->create();
    // That sets the match ind in $mtch which the updmatch call uses later.
} catch (MatchException $e) {
    $mess = $e->getMessage();
    include 'php/dataerror.php';
    exit(0);
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<?php 
$Title = "Add Match division {$div} OK";
include 'php/head.php';
?>
<body>
<script language="javascript" src="webfn.js"></script>
 public function parse($jsonString)
 {
     $event = json_decode($jsonString);
     if (!is_object($event)) {
         throw new Exception("Could not create a JSON object from '" . $jsonString . "'");
     }
     /**
      * Server
      */
     if (isset($event->server) && isset($event->server->name) && isset($event->server->port)) {
         $server = Database::getServer($event->server->name, gethostbyname($_SERVER['REMOTE_ADDR']), $event->server->port);
     } else {
         throw new Exception("No server found from JSON!");
     }
     /**
      * Player
      */
     if (isset($event->player, $event->player->name, $event->player->ip, $event->player->skill)) {
         $player = Database::getPlayer($event->player->name, $event->player->ip, $event->player->skill);
     }
     if (false) {
         /**
          * Connect event
          */
     } else {
         if ($event->type == "connect" && $server && $player) {
             $connectEvent = new ConnectEvent();
             $connectEvent->setPlayer($player);
             $connectEvent->setServer($server);
             $connectEvent->insert();
             if (Config::$debug) {
                 echo "type[{$event->type}], {$server}, {$player}\n";
             }
             /**
              * Name change event
              */
         } else {
             if ($event->type == "namechange" && $server && $player) {
                 $nameChangeEvent = new NameChangeEvent();
                 $nameChangeEvent->setPlayer($player);
                 $nameChangeEvent->setServer($server);
                 $nameChangeEvent->setOldName($event->oldName);
                 $nameChangeEvent->setNewName($event->newName);
                 $nameChangeEvent->insert();
                 if (Config::$debug) {
                     echo "type[{$event->type}], {$server}, {$player}, {$event->oldName} -> {$event->newName}\n";
                 }
                 /**
                  * Disconnect event
                  */
             } else {
                 if ($event->type == "disconnect" && $server && $player && isset($event->connectionTime)) {
                     $disconnectEvent = new DisconnectEvent();
                     $disconnectEvent->setPlayer($player);
                     $disconnectEvent->setServer($server);
                     $disconnectEvent->setConnectionTime($event->connectionTime);
                     $disconnectEvent->insert();
                     if (Config::$debug) {
                         echo "type[{$event->type}], {$server}, {$player}, connectionTime[{$disconnectEvent->getConnectionTime()}]\n";
                     }
                     /**
                      * Kick event
                      */
                 } else {
                     if ($event->type == "kick" && $server && $player && isset($event->target, $event->target->name, $event->target->ip, $event->target->skill)) {
                         $target = Database::getPlayer($event->target->name, $event->target->ip, $event->target->skill);
                         $kickEvent = new KickEvent();
                         $kickEvent->setServer($server);
                         $kickEvent->setPlayer($player);
                         $kickEvent->setTarget($target);
                         $kickEvent->insert();
                         if (Config::$debug) {
                             echo "type[{$event->type}], {$server}, kicker {$player}, target {$target}\n";
                         }
                         /**
                          * Kill event
                          */
                     } else {
                         if ($event->type == "kill" && $server && $player && isset($event->target, $event->target->name, $event->target->ip, $event->target->skill) && isset($event->gun)) {
                             $target = Database::getPlayer($event->target->name, $event->target->ip, $event->target->skill);
                             $killEvent = new KillEvent();
                             $killEvent->setServer($server);
                             $killEvent->setPlayer($player);
                             $killEvent->setTarget($target);
                             $killEvent->setGun($event->gun);
                             $killEvent->insert();
                             if (Config::$debug) {
                                 echo "type[{$event->type}], {$server}, killer {$player}, target {$target}\n";
                             }
                             /**
                              * Suicide event
                              */
                         } else {
                             if ($event->type == "suicide" && $server && $player) {
                                 $suicideEvent = new SuicideEvent();
                                 $suicideEvent->setServer($server);
                                 $suicideEvent->setPlayer($player);
                                 $suicideEvent->insert();
                                 if (Config::$debug) {
                                     echo "type[{$event->type}], {$server}, {$player}\n";
                                 }
                                 /**
                                  * Intermission event
                                  */
                             } else {
                                 if ($event->type == "intermission") {
                                     if (isset($event->server->map) && isset($event->server->gamemode)) {
                                         $match = Match::create($server, $event->server->map, $event->server->gamemode);
                                         if (isset($event->players)) {
                                             foreach ($event->players as $jsonMatchPlayer) {
                                                 if (isset($jsonMatchPlayer->name, $jsonMatchPlayer->ip, $jsonMatchPlayer->skill)) {
                                                     $player = Database::getPlayer($jsonMatchPlayer->name, $jsonMatchPlayer->ip, $jsonMatchPlayer->skill);
                                                     if ($player) {
                                                         $matchPlayer = new MatchPlayer();
                                                         $matchPlayer->setMatch($match);
                                                         $matchPlayer->setPlayer($player);
                                                         $matchPlayer->setParametersFromJSON($jsonMatchPlayer);
                                                         $matchPlayer->insert();
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 } else {
                                     if (Config::$debug) {
                                         echo "type[{$event->type}], {$server}\n";
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Example #5
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     Match::create(array('myChar' => Input::get('myChar'), 'opponentChar' => Input::get('opponentChar'), 'result' => Input::get('result')));
     return Response::json(array('success' => true));
 }
Example #6
0
File: Batch.php Project: xJakub/LCE
    public function makeMatches() {

        $teams = Team::find('1=1');
        $teamIdByName = Model::pluck($teams, 'teamid', 'name');

        $week = 0;
        $matches = [];

        foreach (explode("\n", file_get_contents("matches.txt")) as $line) {
            $parts = explode("VS", $line);
            if (count($parts) == 1 && substr(trim($line), 0, 2) == '--') {
                $week++;
            }
            if (count($parts) != 2) continue;

            list($name1, $name2) = $parts;
            $name1 = trim($name1);
            $name2 = trim($name2);

            $match = Match::create();
            $match->team1id = $teamIdByName[$name1];
            $match->team2id = $teamIdByName[$name2];
            $match->week = $week;
            $matches[] = $match;

            if (!$match->team1id) {
                die("Equipo desconocido: $name1");
            }
            if (!$match->team2id) {
                die("Equipo desconocido: $name2");
            }

        }

        if (count($matches) >= 1 && count($matches) != count(Match::find('1=1'))) {
            Match::truncate(true);
            Model::saveAll($matches);
            ?>Enfrentamientos actualizados.<br><?
        }
        else {
            ?>No hay cambios en los enfrentamientos.<br><?
        }

    }
Example #7
0
    public static function userSched()
    {
        global $lng, $coach, $settings, $leagues, $divisions, $tours;
        if (!is_object($coach)) {
            status(false, "You must be logged in to schedule games");
            return;
        }
        if (isset($_POST['creategame'])) {
            // Test input
            $trid = (int) $_POST['trid'];
            $round = (int) $_POST['round'];
            $own_team = (int) $_POST['own_team'];
            $errmsg = '';
            // Logged in coach has access to the tour?
            if (!in_array($trid, array_keys($tours))) {
                $errmsg = 'You do not have access to the tournament ' . $tours[$trid]['tname'];
            }
            // Is the team is really owned by the logged in coach?
            if ($coach->coach_id != get_alt_col('teams', 'team_id', $own_team, 'owned_by_coach_id')) {
                $errmsg = 'The team ' . get_alt_col('teams', 'team_id', $own_team, 'name') . ' is not owned by you';
            }
            // Create match
            if (!$errmsg) {
                list($exitStatus, $mid) = Match::create(array('team1_id' => $own_team, 'team2_id' => get_alt_col('teams', 'name', $_POST['opposing_team_autocomplete'], 'team_id'), 'round' => $round, 'f_tour_id' => $trid));
                $backFromMatchLink = Mobile::isMobile() ? "index.php?mobile=1" : "index.php?section=matches&amp;type=report&amp;mid={$mid}";
                status(!$exitStatus, $exitStatus ? Match::$T_CREATE_ERROR_MSGS[$exitStatus] : "<a href='{$backFromMatchLink}'>Click here</a> to open the match report");
                if (!$exitStatus) {
                    echo "<br>";
                }
            } else {
                status(false, $errmsg);
            }
        }
        $trid = isset($_GET['trid']) && is_numeric($_GET['trid']) ? (int) $_GET['trid'] : 0;
        $lid = $trid ? get_parent_id(T_NODE_TOURNAMENT, $trid, T_NODE_LEAGUE) : false;
        $lname = $lid ? get_parent_name(T_NODE_TOURNAMENT, $trid, T_NODE_LEAGUE) : '- N/A -';
        $did = $trid && get_alt_col('leagues', 'lid', $lid, 'tie_teams') == 1 ? get_parent_id(T_NODE_TOURNAMENT, $trid, T_NODE_DIVISION) : false;
        $dname = $did ? get_parent_name(T_NODE_TOURNAMENT, $trid, T_NODE_DIVISION) : false;
        $_DISABLED = !$trid ? 'DISABLED' : '';
        #print_r(array($trid, $lid, $lname, $did));
        title($lng->getTrn('menu/matches_menu/usersched'));
        $LOCK_FORMS = false;
        ?>
    <div class='boxCommon'>
        <h3 class='boxTitle<?php 
        echo T_HTMLBOX_MATCH;
        ?>
'><?php 
        echo $lng->getTrn('menu/matches_menu/usersched');
        ?>
</h3>
        <div class='boxBody'>
            <form method="POST" id="usersched">
                <?php 
        echo "In tournament ";
        echo HTMLOUT::nodeList(T_NODE_TOURNAMENT, 'trid', array(T_NODE_TOURNAMENT => array('locked' => 0, 'type' => TT_FFA, 'allow_sched' => 1)), array(), array('sel_id' => $trid, 'extra_tags' => array('onChange="document.location.href = \'' . getFormAction('?section=matches&type=usersched') . '&trid=\' + $(this).val();"'), 'init_option' => '<option value="0">- ' . $lng->getTrn('matches/usersched/selecttour') . " -</option>\n"));
        echo ' as ';
        echo '<select name="round" id="round" ' . $_DISABLED . '>';
        $T_ROUNDS = Match::getRounds();
        foreach ($T_ROUNDS as $r => $d) {
            echo "<option value='{$r}' " . ($r == 1 ? 'SELECTED' : '') . ">" . $d . "</option>\n";
        }
        ?>
                </select>
                <br><br>
                Your team
                <?php 
        $teams = array();
        foreach ($coach->getTeams($lid, $did, array('sortby' => 'team_id DESC')) as $t) {
            if (!$t->rdy || $t->is_retired) {
                continue;
            }
            $teams[] = $t;
        }
        ?>
                <select name='own_team' id='own_team' <?php 
        echo $_DISABLED;
        ?>
>
                    <?php 
        echo "<optgroup class='leagues' label='{$lname}'>\n";
        if ($dname) {
            echo "<optgroup class='divisions' label='&nbsp;&nbsp;{$dname}'>\n";
        }
        foreach ($teams as $t) {
            echo "<option style='background-color: white; margin-left: -1em;' value='{$t->team_id}'>&nbsp;&nbsp;&nbsp;{$t->name}</option>\n";
        }
        ?>
                </select>
                &nbsp;
                VS.
                <input type="text" id='opposing_team_autoselect' name="opposing_team_autocomplete" size="30" maxlength="50" <?php 
        echo $_DISABLED;
        ?>
>
                <script>
                    $(document).ready(function(){
                        var options, b;

                        options = {
                            minChars:2,
                            serviceUrl:'handler.php?type=autocomplete&obj=<?php 
        echo T_OBJ_TEAM;
        ?>
&trid=<?php 
        echo $trid;
        ?>
',
                        };
                        b = $('#opposing_team_autoselect').autocomplete(options);
                    });
                </script>
                <br><br><br>
                <input type="submit" name="creategame" value="<?php 
        echo $lng->getTrn('menu/matches_menu/usersched');
        ?>
" <?php 
        if (empty($teams) || $_DISABLED) {
            echo 'DISABLED';
        }
        ?>
>
                
                <?php 
        if (Mobile::isMobile()) {
            echo '<a href="' . getFormAction('') . '">' . $lng->getTrn('common/back') . '</a>';
        }
        ?>
            </form>
        </div>
    </div>
    <?php 
    }
Example #8
0
 }
 // When creating a new FFA tour the "rounds" input is intepreted as the round number of the initial match being created in the new tour.
 if ($mkNewFFA) {
     $_POST['rounds'] = $_POST['round'];
 }
 /*
     Create the requested matches.
 */
 if ($STATUS) {
     # Did all input pass verification?
     // Add match to existing FFA?
     if ($addMatchToFFA) {
         $rnd = !isset($_POST['round']) ? 1 : (int) $_POST['round'];
         $status = true;
         for ($i = 0; $i < $teamsCount / 2; $i++) {
             list($exitStatus, $mid) = Match::create(array('team1_id' => $team_ids[$i * 2], 'team2_id' => $team_ids[$i * 2 + 1], 'round' => $rnd, 'f_tour_id' => (int) $_POST['existTour']));
             $status &= !$exitStatus;
             if ($exitStatus) {
                 break;
             }
         }
         status($status, $exitStatus ? Match::$T_CREATE_ERROR_MSGS[$exitStatus] : null);
     } else {
         switch ($_POST['type']) {
             case 'FFA_TOUR':
                 $TOUR_TYPE = TT_FFA;
                 break;
             case 'RR_TOUR':
                 $TOUR_TYPE = TT_RROBIN;
                 break;
         }
Example #9
0
    /**
     * @return void
     */
    public function show()
    {
        if (!Team::isSuperAdmin()) {
            HTMLResponse::exitWithRoute('/');
        }

        if (!($csrf = $_SESSION['csrf'])) {
            $_SESSION['csrf'] = $csrf = rand(1, 1000000);
        }
        $postCsrf = HTMLResponse::fromPOST('csrf', '');

        $totalWeeks = $this->season->getWeeksCount();
        if ($csrf == $postCsrf) {
            $this->season->mainweeks = HTMLResponse::fromPOST('mainweeks', $this->season->mainweeks);
            $this->season->playoffsweeks = HTMLResponse::fromPOST('playoffsweeks', $this->season->playoffsweeks);
            $this->season->save();
        }

        ?>
        <div class="inblock middle">
        <form action="<?=HTMLResponse::getRoute()?>" method="post">
            <table style="width:640px; margin: 0 auto; text-align: left">
                <thead>
                <tr style="text-align: center">
                    <td>
                        Propiedad
                    </td>
                    <td>
                        Valor
                    </td>
                </tr>
                </thead>
                <tr>
                    <td>
                        <b>Número de jornadas (principales)</b>
                    </td><td>
                        <input name="mainweeks" type="number" value="<?=htmlentities($this->season->mainweeks)?>">
                    </td>
                </tr>
                <tr>
                    <td>
                        <b>Número de jornadas (playoffs)</b>
                    </td><td>
                        <input name="playoffsweeks" type="number" value="<?=htmlentities($this->season->playoffsweeks)?>">
                    </td>
                </tr>
            </table>

            <?
            $teams = $this->season->getTeams(false);
            $maxMatches = ceil(count($teams)/2);

            $matches =
                Model::groupBy(
                    Match::find('seasonid = ? order by week asc, matchid asc', [$this->season->seasonid]),
                    'week'
                );

            if ($csrf == $postCsrf) {
                for ($week=1; $week<=$totalWeeks; $week++) {
                    $name = HTMLResponse::fromPOST("week{$week}name");
                    $date = HTMLResponse::fromPOST("week{$week}date");
                    $this->season->setWeekName($week, $name);
                    $this->season->setWeekDate($week, $date);
                }
                $this->season->save();

                $newMatches = [];
                $oldMatches = [];
                for ($week=1; $week<=$this->season->getWeeksCount(); $week++) {
                    for ($i=0; $i<$maxMatches; $i++) {
                        $team1id = HTMLResponse::fromPOST("week{$week}match{$i}team1id");
                        $team2id = HTMLResponse::fromPOST("week{$week}match{$i}team2id");
                        if ($team1id === null || $team2id === null) continue;

                        $team1id *= 1;
                        $team2id *= 1;

                        if ($team1id && $team2id) {
                            if (isset($matches[$week][$i])) {
                                $match = $matches[$week][$i];
                                $match->team1id = "$team1id";
                                $match->team2id = "$team2id";
                                $oldMatches[] = $match;
                            }
                            else {
                                $match = Match::create();
                                $match->result = 0;
                                $match->week = $week;
                                $match->seasonid = $this->season->seasonid;
                                $match->team1id = $team1id;
                                $match->team2id = $team2id;
                                $newMatches[] = $match;
                            }
                        }
                        else {
                            if (isset($matches[$week][$i])) {
                                $matches[$week][$i]->delete();
                            }
                        }
                    }
                }
                Model::saveAll($newMatches);
                Model::saveAll($oldMatches);

                $matches =
                    Model::groupBy(
                        Match::find('seasonid = ? order by week asc, matchid asc', [$this->season->seasonid]),
                        'week'
                    );
            }


            for ($week=1; $week<=$totalWeeks; $week++) {
                ?>
                <br>
                <table style="width:640px; margin: 0 auto; text-align: left">
                    <thead>
                    <tr>
                        <td colspan="2" style="text-align: center">Jornada Nº<?=$week?></td>
                    </tr>
                    </thead>
                    <tr>
                        <td>
                            <b>Nombre de la jornada</b>
                        </td><td>
                            <input name="week<?=$week?>name" value="<?=htmlentities($this->season->getWeekName($week))?>">
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <b>Fecha de publicación</b>
                        </td><td>
                            <input name="week<?=$week?>date" type="date" value="<?=htmlentities($this->season->getWeekDate($week))?>">
                        </td>
                    </tr>
                    <?
                    for ($i=0; $i<$maxMatches; $i++) {
                        ?>
                        <tr>
                            <td>
                                <b>- Enfrentamiento #<?=$i+1?></b>
                            </td>
                            <td>
                                <select name="week<?=$week?>match<?=$i?>team1id">
                                    <option value="0">-- Elige equipo --</option>
                                    <?
                                    foreach($teams as $team) {
                                        $selected = isset($matches[$week][$i])
                                            ? (
                                            $matches[$week][$i]->team1id == $team->teamid
                                                ? 'selected'
                                                : ''
                                            )
                                            : '';
                                        ?>
                                        <option value="<?=$team->teamid?>" <?=$selected?>>
                                            <?=htmlentities($team->name)?>
                                        </option>
                                        <?
                                    }
                                    ?>
                                </select>
                                VS
                                <select name="week<?=$week?>match<?=$i?>team2id">
                                    <option value="0">-- Elige equipo --</option>
                                    <?
                                    foreach($teams as $team) {
                                        $selected = isset($matches[$week][$i])
                                            ? (
                                            $matches[$week][$i]->team2id == $team->teamid
                                                ? 'selected'
                                                : ''
                                            )
                                            : '';
                                        ?>
                                        <option value="<?=$team->teamid?>" <?=$selected?>>
                                            <?=htmlentities($team->name)?>
                                        </option>
                                        <?
                                    }
                                    ?>
                                </select>
                            </td>
                        </tr>
                        <?
                    }
                    ?>
                </table>
                <?
            }
            ?>

            <input type="hidden" name="csrf" value="<?= $csrf ?>"><br>
            <button type="submit">Guardar cambios</button><br><br>

        </form>
        </div><?
    }
Example #10
0
 /**
  * Test that an exception is thrown when a bad match type
  * 	is provided
  *
  * @expectedException \InvalidArgumentException
  */
 public function testCreateInvalidMatchInstance()
 {
     $instance = Match::create('bad.matchType', []);
 }
Example #11
0
 public function doSyncFromFeed($data, $form)
 {
     $feeds = $this->Feeds();
     foreach ($feeds as $feed) {
         $feedreader = new ICSReader($feed->URL);
         $events = $feedreader->getEvents();
         foreach ($events as $event) {
             // translate iCal schema into Match schema
             $uid = strtok($event['UID'], '@');
             if ($match = Match::get()->filter(array("UID" => $uid))->First()) {
                 $feedevent = $match;
             } else {
                 $feedevent = Match::create();
                 $feedevent->UID = $uid;
             }
             $feedevent->Title = $event['SUMMARY'];
             //Get opposition with some string fun
             $feedevent->Opposition = trim(str_replace(array("-", "Black Doris Rovers", "vs"), "", $event['SUMMARY']));
             if (preg_match('/Round/', $feedevent->Opposition)) {
                 $opp = explode(" ", $feedevent->Opposition);
                 $opp = array_slice($opp, 2);
                 $feedevent->Opposition = trim(implode(" ", $opp));
             }
             if (isset($event['DESCRIPTION']) && !empty($event['DESCRIPTION']) && $event['DESCRIPTION'] != " ") {
                 $scores = str_replace("Result\n", "", $event['DESCRIPTION']);
                 $scores = explode("-", $scores);
                 foreach ($scores as $score) {
                     $score = trim($score);
                     $bits = explode(" ", $score);
                     if (preg_match('/Black Doris Rovers/', $score)) {
                         $feedevent->BDRScore = end($bits);
                     } else {
                         $feedevent->OppositionScore = end($bits);
                     }
                 }
                 if (intval($feedevent->BDRScore) > intval($feedevent->OppositionScore)) {
                     $feedevent->Result = 'Win';
                 } elseif (intval($feedevent->BDRScore) < intval($feedevent->OppositionScore)) {
                     $feedevent->Result = 'Loss';
                 } else {
                     $feedevent->Result = 'Draw';
                 }
             } else {
                 $feedevent->BDRScore = NULL;
                 $feedevent->OppositionScore = NULL;
                 $feedevent->Result = NULL;
             }
             $startdatetime = $this->iCalDateToDateTime($event['DTSTART']);
             if (array_key_exists('DTEND', $event) && $event['DTEND'] != NULL) {
                 $enddatetime = $this->iCalDateToDateTime($event['DTEND']);
             } elseif (array_key_exists('DURATION', $event) && $event['DURATION'] != NULL) {
                 $enddatetime = $this->iCalDurationToEndTime($event['DTSTART'], $event['DURATION']);
             }
             $new = false;
             if ($feedevent->DateTimes()->Count() == 0) {
                 $cdt = CalendarDateTime::create();
                 $new = true;
             } else {
                 $cdt = $feedevent->DateTimes()->First();
             }
             $cdt->StartDate = $startdatetime->format('Y-m-d');
             $cdt->StartTime = $startdatetime->format('H:i:s');
             $cdt->EndDate = $enddatetime->format('Y-m-d');
             $cdt->EndTime = $enddatetime->format('H:i:s');
             if ($new == true) {
                 $feedevent->DateTimes()->add($cdt);
             } else {
                 $cdt->write();
             }
             $feedevent->ParentID = $this->ID;
             $feedevent->write();
             $feedevent->publish('Stage', 'Live');
         }
     }
     $form->sessionMessage('Sync Succeeded', 'good');
     $data = $this->data();
     $data->LastSyncDate = date("Y-m-d H:i:s");
     $data->write();
     $data->publish('Stage', 'Live');
     return $this->redirectBack();
 }
Example #12
0
require "common.php";
if (!empty($_POST['process'])) {
    $valid = false;
    if (!empty($_POST['form_time']) && !empty($_POST['form_hash'])) {
        $valid = sha1($site_key . $_POST['form_time'] . $current_user->user_id) == $_POST['form_hash'];
    }
    if (empty($_POST['vote_starts'])) {
        // if vote_starts is empty by default 7 days before
        $_POST['vote_starts'] = 7 * 24;
    }
    if (is_numeric($_POST['vote_starts'])) {
        // if the input is a number we assume they are hours
        $_POST['vote_starts'] = date("Y-m-d H:i:s", strtotime($_POST['date']) - intval($_POST['vote_starts']) * 3600);
    }
    if ($valid && empty($_POST['match_id'])) {
        Match::create($_POST);
    } else {
        if ($valid) {
            $league = new Match($_POST['match_id']);
            if (!$league->read()) {
                die(_("No se puede encontrar el equipo"));
            }
            $league->league_id = $_POST['league'];
            $league->local = $_POST['local'];
            $league->visitor = $_POST['visitor'];
            $league->date = $_POST['date'];
            $league->vote_starts = $_POST['vote_starts'];
            if (is_numeric($_POST['score_local']) && is_numeric($_POST['score_visitor'])) {
                $league->score_local = $_POST['score_local'];
                $league->score_visitor = $_POST['score_visitor'];
            }
Example #13
0
 /**
  * buildBracket 
  * Create the bracket for the tournament.
  * This will add and associate all other fields / tables
  * 
  */
 public function buildBracket()
 {
     /*
     	Calculate the number of matches for the first round.
     	All we need is the first round, every round after that is half the amount of matches as the previous. (for single elim)
     */
     $matchesThisRound = $this->firstRoundMatches();
     $teams = $this->bracket->teams;
     // We're building a new bracket.
     // Let's delete the existing rounds and matches.
     // This will also remove matches and relationship through foreign key cascades.
     $this->bracket->rounds()->delete();
     // assign matches for all rounds.
     for ($r = 1; $r <= $this->getRoundCount(); $r++) {
         // INSERT the round data into the database and associate it with the bracket.
         $round = Round::create(array('name' => $this->getRoundName($r), 'index' => $r));
         // associate the new round with the existing bracket.
         $this->bracket->rounds()->insert($round);
         // If this is the first round let's make it the "current_round", in the bracket table.
         if ($r === 1) {
             $this->bracket->current_round = $round->id;
             $this->bracket->save();
         }
         for ($i = 0; $i < $matchesThisRound; $i++) {
             // Create the match.
             $match = Match::create(array('status' => $r === 1 ? 'Ready to play' : 'Waiting for team assignment'));
             // Associate the new match with the round.
             $round->matches()->insert($match);
             // Also associate the match with the current bracket.
             $this->bracket->matches()->attach($match);
             // If this is the first round then we can assign teams to the match.
             if ($r === 1) {
                 // Add two teams to the match.
                 for ($c = 0; $c < 2; $c++) {
                     if (current($teams)) {
                         $match->teams()->attach(current($teams));
                         next($teams);
                     }
                 }
             }
         }
         $matchesThisRound = $matchesThisRound / 2;
         //  Half the people lost...
     }
     return count($this->bracket->matches);
 }
Example #14
0
	else
	{
		//The user is matched
		$User->setMatched(true);
	}

    if($Match->ID == '' && $PQ->count() > 0)
    {
    	$matchingUserID = $PQ->top();
    	$newUser = new User($matchingUserID, $PDOconn);
		
    	if($debug) echo "Popped ".$newUser->row['fName'].", making a match...";
		$newMatch = new Match(NULL, $PDOconn);
		$newMatch->istest = true;
		// if($debug) echo "<br>new match is test: ".$newMatch->istest;
		$newMatch->create($User->ID, $matchingUserID);
		if($debug) echo "Match created... ";
					
		$User->setMatched(true);
		$User->setLastRow($nextRow);
		$newUser->setMatched(true);
					
		$Match = $newMatch;
    }


	//Add this match to data
	$response['data']['matchID'] = $Match->ID;
	
	//Set the status to 1 (success)
	$response['meta']['status'] = 1;
Example #15
0
public static function schedule_custom_game() {
	global $lng;
	
	$teams = json_decode($_POST['teams']);
	$teamsClean = array();
	foreach($teams->teams as $team) {
		$teamsClean[] = str_replace("pool","", $team);
	}
	
	$t1 = new Team($teamsClean[0]);
	$t2 = new Team($teamsClean[1]);
	$rnd = (int) str_replace('round_', '', $_POST['round']);
	
	list($exitStatus, $mid) = Match::create(
		array(
			'team1_id' => $t1->team_id, 
			'team2_id' => $t2->team_id, 
			'round' => $rnd, 
			'f_tour_id' => (int) $_POST['f_tour_id']
		)
	);
	
	if     ($rnd == RT_FINAL)         $round = $lng->getTrn('matches/tourmatches/roundtypes/final');
	elseif ($rnd == RT_3RD_PLAYOFF)   $round = $lng->getTrn('matches/tourmatches/roundtypes/thirdPlayoff');
	elseif ($rnd == RT_SEMI)          $round = $lng->getTrn('matches/tourmatches/roundtypes/semi');
	elseif ($rnd == RT_QUARTER)       $round = $lng->getTrn('matches/tourmatches/roundtypes/quarter');
	elseif ($rnd == RT_ROUND16)       $round = $lng->getTrn('matches/tourmatches/roundtypes/rnd16');
	else                              $round = $lng->getTrn('matches/tourmatches/roundtypes/rnd').": $rnd";
		
	
	if ($exitStatus == '') {
		$status =  $lng->getTrn('schedule_successfull', __CLASS__);
		$htmlclass = 'success';
	} else {
		$status = Match::$T_CREATE_ERROR_MSGS[$exitStatus];
		$htmlclass = 'error';
	}
	
	?>
	<div class="<? echo $htmlclass; ?>">
		<? echo $round ?> - <? echo $t1->name; ?> vs. <? echo $t2->name; ?> - <? echo $status; ?>
	</div>
	<?
	
	
}
Example #16
0
 public static function create(array $input)
 {
     /**
      * Creates a new tournament.
      *
      * Arguments:
      * ----------
      *  name, type, rs, teams => array(team_ids, ...), 'rounds'
      **/
     /* Check input */
     // Done in in scheduler section code.
     /* Create tournament */
     // Quit if can't make tournament entry.
     $query = "INSERT INTO tours (name, f_did, type, rs, date_created, allow_sched) VALUES ('" . mysql_real_escape_string($input['name']) . "', {$input['did']}, {$input['type']}, {$input['rs']}, NOW(), {$input['allow_sched']})";
     if (!mysql_query($query)) {
         return false;
     }
     $tour_id = mysql_insert_id();
     /* Generate matches depending on type */
     // FFA match(es)?
     if ($input['type'] == TT_FFA) {
         $status = true;
         for ($i = 0; $i < count($input['teams']) / 2; $i++) {
             list($exitStatus, $mid) = Match::create(array('team1_id' => $input['teams'][$i * 2], 'team2_id' => $input['teams'][$i * 2 + 1], 'round' => $input['rounds'] ? $input['rounds'] : 1, 'f_tour_id' => $tour_id));
             $status &= !$exitStatus;
         }
         return $status;
     } elseif ($input['type'] == TT_RROBIN) {
         if (sizeof($input['teams']) == 0) {
             return true;
         }
         // Quit if can't make tournament schedule.
         $robin = new RRobin();
         if (!$robin->create($input['teams'])) {
             # If can't create Round-Robin tour -> quit.
             return false;
         }
         // Okey, so $input['rounds'] is incorrect in the sense that this is the multiplier of times to schedule the same round-set comprising the RR tour.
         // Instead we denote $real_rounds to be the actual number of rounds in the scheduled RR tour.
         $real_rounds = count($robin->tour);
         // Create inverse depiction round.
         foreach ($robin->tour as $ridx => $r) {
             foreach ($r as $idx => $m) {
                 $robin->tour_inv[$ridx][$idx] = array($m[1], $m[0]);
             }
         }
         $status = true;
         for ($i = 1; $i <= $input['rounds']; $i++) {
             $rounds = $robin->{$i % 2 ? 'tour' : 'tour_inv'};
             # Invert pair-up?
             // Shuffle the order of rounds in the bracket seeding, $i.
             $rounds_k = array_keys($rounds);
             $rounds_v = array_values($rounds);
             shuffle($rounds_k);
             shuffle($rounds_v);
             $rounds = array_combine($rounds_k, $rounds_v);
             ksort($rounds);
             // Create new bracket.
             foreach ($rounds as $ridx => $r) {
                 foreach ($r as $match) {
                     // Depict round's match compets inversely for every other round.
                     list($exitStatus, $mid) = Match::create(array('team1_id' => $match[0], 'team2_id' => $match[1], 'round' => $ridx + ($i - 1) * $real_rounds, 'f_tour_id' => $tour_id));
                     $status &= !$exitStatus;
                 }
             }
         }
         return $status;
     }
     return false;
     # Return false if tournament type was not recognized.
 }