public static function run()
 {
     $tournament = null;
     if ($_SERVER["REQUEST_METHOD"] == "POST") {
         $tournament = new Tournament($_POST);
         if (is_null($tournament) || $tournament->getErrorCount() != 0) {
             TournamentCreateView::show($tournament);
         } else {
             $tournament = TournamentsDB::addTournament($tournament);
         }
         HomeView::show();
         header('Location: /' . $_SESSION['base']);
     } else {
         // Initial link
         TournamentCreateView::show(null);
     }
 }
 public static function run()
 {
     $tournament = null;
     $authenticatedUser = array_key_exists('authenticatedUser', $_SESSION) ? $_SESSION['authenticatedUser'] : null;
     if ($_SERVER["REQUEST_METHOD"] == "POST") {
         $tournament = new Tournament($_POST);
         $tournament->setCreatorID($authenticatedUser->getUserID());
         if (is_null($tournament) || $tournament->getErrorCount() != 0) {
             TournamentCreateView::show($tournament);
         } else {
             $tournament = TournamentsDB::addTournament($tournament);
         }
         HomeView::show();
         header('Location: /' . $_SESSION['base']);
     } else {
         // Initial link
         TournamentCreateView::show(null);
     }
 }
Esempio n. 3
0
$db = Database::getDB('ptest');
echo "Number of tournaments in db before added is: " . count(TournamentsDB::getTournamentsBy()) . "<br>";
$invalidTournament = new Tournament(array("name" => "newtourney\$"));
$newTournament = TournamentsDB::addTournament($newTournament);
echo "Number of tournaments in db after added is: " . count(TournamentsDB::getTournamentsBy()) . "<br>";
echo "New tournament is: {$newTournament}<br>";
?>

<h2>It should not add a duplicate tournament</h2>
// <?php 
DBMaker::create('ptest');
Database::clearDB();
$db = Database::getDB('ptest');
echo "Number of tournaments in db before added is: " . count(TournamentsDB::getTournamentsBy()) . "<br>";
$duplicateTournament = new Tournament(array("name" => "Champs", "hostedBy" => "The Host", "startTime" => "7:00", "startDate" => "12/01/2014", "numParticipants" => 2));
$tournamentID = TournamentsDB::addTournament($duplicateTournament);
echo "Number of tournaements in db after added is: " . count(TournamentsDB::getTournamentsBy()) . "<br>";
echo "Tournament ID of new tournament is: {$tournamentID}<br>";
?>

<h2>It should get a Tournament by name</h2>
<?php 
DBMaker::create('ptest');
Database::clearDB();
$db = Database::getDB('ptest');
$tournaments = TournamentsDB::getTournamentsBy('name', 'Champs');
echo "The value of Tournament Champs is:<br>{$tournaments['0']}<br>";
?>

<h2>It should get a Tournament by TournamentID</h2>
<?php