Example #1
0
 public static function saveSchedule($tournament, Schedule $schedule)
 {
     $req = DataBase::getInstance()->prepare('INSERT INTO tournament_schedule (tournament, start, stop) VALUES (:id, :start, :stop)');
     $req->bindvalue('id', $tournament, PDO::PARAM_INT);
     $req->bindvalue('start', $schedule->getStart(), PDO::PARAM_INT);
     $req->bindvalue('stop', $schedule->getEnd(), PDO::PARAM_INT);
     $req->execute();
     $req->closeCursor();
 }
Example #2
0
 public static function saveTournament(Tournament $tournament)
 {
     //Aiguilleur Insert/Update
     $req = DataBase::getInstance()->prepare('SELECT COUNT(id) FROM tournament WHERE id = :id');
     $req->bindvalue('id', $tournament->getId(), PDO::PARAM_INT);
     $req->execute();
     $count = $req->fetchColumn();
     $req->closeCursor();
     if ($count == 0) {
         $req = DataBase::getInstance()->prepare('INSERT INTO tournament (name, description) VALUES (:name, :description)');
     } else {
         $req = DataBase::getInstance()->prepare('UPDATE tournament SET (name = :name, description = :description) WHERE id = :id');
         $req->bindvalue('id', $tournament->getId(), PDO::PARAM_INT);
     }
     $req->bindValue('name', $tournament->name, PDO::PARAM_STR);
     $req->bindValue('description', $tournament->description, PDO::PARAM_STR);
     $req->execute();
     $req->closeCursor();
     if ($count == 0) {
         $tournament->setId(DataBase::getInstance()->lastInsertId());
     }
     //Jeu associƩ
     $req = DataBase::getInstance()->prepare('DELETE FROM tournament_game WHERE tournament = :id');
     $req->bindvalue('id', $tournament->getId(), PDO::PARAM_INT);
     $req->execute();
     $req->closeCursor();
     $req = DataBase::getInstance()->prepare('INSERT INTO tournament_game (game, tournament) VALUES (:game, :tournament)');
     $req->bindvalue('game', $tournament->getGame()->getId(), PDO::PARAM_INT);
     $req->bindvalue('tournament', $tournament->getId(), PDO::PARAM_INT);
     $req->execute();
     $req->closeCursor();
     //Horaires associƩs
     Schedule::deleteSchedules($tournament->getId());
     foreach ($tournament->getSchedules() as $schedule) {
         Schedule::saveSchedule($tournament->getId(), $schedule);
     }
 }