*/ class Tournament { private $identifier; private $name; private $location; private $date; private $type; private $comments; public static function Get($identifier) { $sql = "SELECT * FROM tournaments WHERE identifier = $identifier"; $result = MySQLDatabase::getInstance()->runRequest($sql); $result = $result[0]; return Tournament::GetSQL($result); } public static function GetSQL(array $sqlResponse) { $newTournament = new Tournament($sqlResponse['identifier']); $newTournament->name = $sqlResponse['name']; $newTournament->location = $sqlResponse['location']; $newTournament->date = DateParser::parseSQL($sqlResponse['date']); $newTournament->type = $sqlResponse['type']; $newTournament->comments = $sqlResponse['comments']; $newTournament->needsSaving = false; return $newTournament; } public static function Create($name, $location, $date, $type, $comments) { $name = InputSanitizer::Sanitize($name); $location = InputSanitizer::Sanitize($location); $date = InputSanitizer::Number($date); $type = InputSanitizer::Sanitize($type); $comments = InputSanitizer::Sanitize($comments); $dateSql = DateFormatter::formatSQL($date); $sql = "INSERT INTO `tournaments` ( `identifier`, `name`, `location`, `date`, `type`, `comments`) VALUES ( NULL, '$name', '$location', '$dateSql', '$type', '$comments');"; $result = MySQLDatabase::getInstance()->runOperation($sql); return $result; } public static function Remove($identifier) { $tournament = Tournament::Get($identifier); $tournamentEntries = TournamentEntryLister::getAllEntries($tournament); foreach($tournamentEntries as $tournamentEntry) { $tournamentId = $identifier; $userId = $tournamentEntry->getUserId(); $categoryId = $tournamentEntry->getCategoryId(); TournamentEntry::Remove($tournamentId, $userId, $categoryId); } $sql = "DELETE FROM `tournaments` WHERE `identifier` = $identifier"; $result = MySQLDatabase::getInstance()->runOperation($sql); return $result; } private function __construct($identifier) { $this->identifier = $identifier; } public function __destruct() { if ($this->needsSaving) { $this->save(); } } private function save() { $dateSql = DateFormatter::formatSQL($this->date); $sql = "UPDATE `tournaments` SET `name` = '$this->name', `location` = '$this->location', `date` = '$dateSql', `type` = '$this->type', `comments` = '$this->comments' WHERE `identifier` = $this->identifier;"; $result = MySQLDatabase::getInstance()->runOperation($sql); } public function getIdentifier() { return $this->identifier; } public function getName() { return $this->name; } public function getLocation() { return $this->location; } public function getDate() { return $this->date; } public function getType() { return $this->type; } public function getComments() { return $this->comments; } /** * Sets the informations about the Tournament * * @param string $name * @param string $location * @param int $date * @param string $type * @param string $comments */ public function setInformations($name, $location, $date, $type, $comments) { $name = InputSanitizer::Sanitize($name); $location = InputSanitizer::Sanitize($location); $date = InputSanitizer::Number($date); $type = InputSanitizer::Sanitize($type); $comments = InputSanitizer::Sanitize($comments); $this->name = $name; $this->location = $location; $this->date = $date; $this->type = $type; $this->comments = $comments; $this->needsSaving = true; } } ?>