public static function generateUniqueName($title, $year) { $name_base = str_replace(array_keys(Games::$TRANSLITERATABLE_CHARACTERS), array_values(Games::$TRANSLITERATABLE_CHARACTERS), $title); $name_base = strtolower($name_base); $name_base = preg_replace("/[']/", '', $name_base); $name_base = preg_replace("/[^a-z0-9]/", '_', $name_base); $name_base = preg_replace('/_+/', '_', $name_base); if (strlen($year) > 4) { $year = date_parse($year); $year = $year["year"]; } $approved = false; $try = 0; while (!$approved) { $number_length = 0; if ($try > 0) { $number_length = strlen($try) + 1; } $name = substr($name_base, 0, 254 - strlen($year) - $number_length); $name .= '_' . $year; if ($try > 0) { $name .= '_' . $try; } $result = null; $query = new GamesQuery(); $result = $query->findOneByName($name); if ($result != null) { $try++; } else { return $name; } } }
require "res/include.php"; if (!Auth::checkIfAdmin()) { header("Location: /"); /* Redirect browser */ } $user = Auth::getCurrentUser(); $game = null; $platform = null; if (!array_key_exists("game", $_GET) || !array_key_exists("platform", $_GET)) { header("Location: /"); /* Redirect browser */ exit; } else { $query = new GamesQuery(); $game = $query->findOneByName($_GET["game"]); $query = new PlatformsQuery(); $platform = $query->findOneByName($_GET["platform"]); if ($game == null || $platform == null) { header("Location: /"); /* Redirect browser */ exit; } } $header = RatingHeadersQuery::create()->filterByGames($game)->filterByPlatforms($platform)->findOne(); if (array_key_exists("category_options_1", $_POST)) { $con = \Propel\Runtime\Propel::getConnection(); $con->beginTransaction(); try { if (!Auth::checkIfAuthenticated()) { throw new Exception("User not authenticated");