public static function updateTournament()
 {
     $tournaments = TournamentsDB::getTournamentsBy('tournamentID', $_SESSION['arguments']);
     if (empty($tournaments)) {
         HomeView::show();
         header('Location: /' . $_SESSION['base']);
     } elseif ($_SERVER["REQUEST_METHOD"] == "GET") {
         $_SESSION['tournament'] = $tournaments[0];
         TournamentView::showUpdate();
     } else {
         $parms = $tournaments[0]->getParameters();
         $parms['name'] = array_key_exists('name', $_POST) ? $_POST['name'] : $tournaments[0]->getName();
         $parms['startDate'] = array_key_exists('startDate', $_POST) ? $_POST['startDate'] : $tournaments[0]->getDate();
         $parms['startTime'] = array_key_exists('startTime', $_POST) ? $_POST['startTime'] : $tournaments[0]->getTime();
         $parms['numParticipants'] = array_key_exists('numParticipants', $_POST) ? $_POST['numParticipants'] : $tournaments[0]->getName();
         $newTournament = new Tournament($parms);
         $newTournament->setTournamentID($tournaments[0]->getTournamentID());
         $tournament = TournamentsDB::updateTournament($newTournament);
         if ($tournament->getErrorCount() != 0) {
             $_SESSION['tournament'] = $newTournament;
             TournamentView::showUpdate();
         } else {
             HomeView::show();
             header('Location: /' . $_SESSION['base']);
         }
     }
 }
 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);
     }
 }
Ejemplo n.º 4
0
 public static function updateTournament($tournament)
 {
     // Update a tournament
     try {
         $db = Database::getDB();
         if (is_null($tournament) || $tournament->getErrorCount() > 0) {
             return $tournament;
         }
         $checkTournament = TournamentsDB::getTournamentsBy('tournamentID', $tournament->getTournamentID());
         if (empty($checkTournament)) {
             $tournament->setError('tournamentID', 'TOURNAMENT_DOES_NOT_EXIST');
         }
         if ($tournament->getErrorCount() > 0) {
             return $tournament;
         }
         // 	    	$query = "UPDATE Tournaments SET tournament = :name, hostedBy = :hostedBy, startDate = :startDate, startTime = :startTime, numParticipants = :numParticipants
         // 	    			                 WHERE tournamentID = :tournamentID";
         $query = "UPDATE Tournaments SET name = :name, startDate = :startDate, startTime = :startTime, numParticipants = :numParticipants\r\n \t    \t\t\t                 WHERE tournamentID = :tournamentID";
         // 	    	$query = "UPDATE Tournaments SET name = :name
         // 	    			                 WHERE tournamentID = :tournamentID";
         $statement = $db->prepare($query);
         $statement->bindValue(":name", $tournament->getName());
         // 			$statement->bindValue(":hostedBy", $tournament->getHostedBy());
         $statement->bindValue(":startDate", $tournament->getDate());
         $statement->bindValue(":startTime", $tournament->getTime());
         $statement->bindValue(":numParticipants", $tournament->getNumParticipants());
         $statement->bindValue(":tournamentID", $tournament->getTournamentID());
         $statement->execute();
         $statement->closeCursor();
     } catch (Exception $e) {
         // Not permanent error handling
         echo "<p>Error updating tournament" . $e->getMessage() . "</p>";
     }
     return $tournament;
 }
Ejemplo n.º 5
0
    echo "No Tournament with this telephone number";
} else {
    echo "The value of Tournament with a specified telephone number is:<br>{$tournaments}<br>";
}
?>

<h2>It should get a tournament name by tournament id</h2>
<?php 
DBMaker::create('ptest');
Database::clearDB();
$db = Database::getDB('ptest');
$tournamentNames = TournamentsDB::getTournamentValuesBy('name', 'tournamentID', 1);
print_r($tournamentNames);
?>
<h2>It should allow update of the tournament name</h2>
<?php 
DBMaker::create('ptest');
Database::clearDB();
$db = Database::getDB('ptest');
$tournaments = TournamentsDB::getTournamentsBy('tournamentID', 1);
$tournament = $tournaments[0];
echo "<br>Before update: {$tournament} <br>";
$parms = $tournament->getParameters();
$parms['name'] = 'Champ1';
$newTournament = new Tournament($parms);
$newTournament->setTournamentID(1);
$tournament = TournamentsDB::updateTournament($newTournament);
echo "<br>After update: {$tournament} <br>";
?>
</body>
</html>