public static function generateUniqueName($title, $year) { $name_base = str_replace(array_keys(self::$TRANSLITERATABLE_CHARACTERS), array_values(self::$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 GameQuery(); $result = $query->findOneByName($name); if ($result != null) { $try++; } else { return $name; } } }
static function getInstance() { if (!self::$instance) { self::$instance = new GameQuery(); } return self::$instance; }
/** * Lists all the available games to start * * @param int $game_id ID of the game to start * @param string Name of your match * @return array The new match object **/ public function doCreateMatch($game_id, $game_name) { $this->mlog->debug('[' . __METHOD__ . ']'); $resp = new Response(); try { $game = GameQuery::findPk($game_id); if ($game instanceof Game) { $match = Match::create($game, $game_name); $resp->data = $match->__toArray(); } } catch (Exception $ex) { $resp->fail(Response::UNKNONWN_EXCEPTION, 'An error occured, please try again later'); } return $resp->__toArray(); }
/** * @param $id - gameId * @param $ps - performace rating * @param $fs - framerate rating * @param $rs - resolution rating * @param $ms - mods rating * @param $ss - server rating * @param $gs - glitch rating * @param $ses - settings rating * @param $cs - control rating * @param $ds - dlc rating * @param $vId - voterId */ function __construct($id, $ps, $fs, $rs, $ms, $ss, $gs, $ses, $cs, $ds, $vId) { $game = new Game('id', $id); $existingResult = $game->getTotalScore(); if (!$game->getMultiplayer()) { $serverScore = null; } else { $serverScore = $existingResult['servers'] + $ss; } $performanceScore = $existingResult['performance'] + $ps; $frameScore = $existingResult['framerate'] + $fs; $resScore = $existingResult['resolution'] + $rs; $modScore = $existingResult['mods'] + $ms; $glitchScore = $existingResult['glitches'] + $gs; $settingScore = $existingResult['settings'] + $ses; $controlScore = $existingResult['controls'] + $cs; $dlcScore = $existingResult['dlc'] + $ds; $voteCount = $existingResult['voteNumber']++; $mysql = GameQuery::getInstance(); $this->success = $mysql->query("UPDATE score SET framerate={$frameScore}, resolution={$resScore},\n performance={$performanceScore}, mods={$modScore}, servers={$serverScore}, glitches={$glitchScore},\n settings={$settingScore}, controls={$controlScore}, dlc={$dlcScore}, totalVotes={$voteCount} WHERE gameid={$id}"); }
function platformPush($platformID) { $platformID = pow(2, $platformID); if ($this->platformExists) { array_push($this->details['platform'], GameQuery::getInstance()->query('SELECT name FROM platform WHERE val = ' . $platformID)->fetch_assoc()['name']); } else { $this->details['platform'] = [GameQuery::getInstance()->query('SELECT name FROM platform WHERE val = ' . $platformID)->fetch_assoc()['name']]; } $this->platformExists = true; }
<?php require "res/include.php"; if (!array_key_exists("name", $_GET)) { header("Location: /"); /* Redirect browser */ exit; } else { $query = new GameQuery(); $game = $query->findOneByName($_GET["name"]); if ($game == null) { header("Location: /"); /* Redirect browser */ exit; } } if (!array_key_exists("platform", $_GET)) { $platform = "windows"; } else { $platform = $_GET["platform"]; } $query = new PlatformQuery(); $platform = $query->findOneByName($platform); if ($platform == null) { throw new Exception("Invalid platform specified"); } // Getting the rating queries the database each time, so we do it once here: $header = $game->getRatingHeaderForPlatform($platform); $rating = $game->getRatingForPlatform($platform); $user = Auth::getCurrentUser(); if (Auth::checkIfAuthenticated() && array_key_exists("submit_game_review", $_POST) && array_key_exists("submit_game_rating", $_POST)) {
<?php include "res/head.php"; ?> <title>PC Masterratings</title> </head> <body> <?php include "res/nav.php"; ?> <div class="container"> <div class="col-md-8"> <h1>Most recent games</h1> <?php $query = new GameQuery(); $query->limit(6); $query->innerJoinRatingHeader(); $query->orderById("DESC"); $games = $query->find(); $i = 1; ?> <?php foreach ($games as $game) { ?> <?php if ($i % 3 == 0) { ?> <div class="row"> <?php
public static function searchForGames($query, $limit = 10) { self::validateApiKey(); //Change these if we need to include more stuff. $fieldArr = ['id', 'name', 'original_release_date', 'image', 'api_detail_url', 'deck', 'image', 'platforms']; //sanitise query $query = trim(preg_replace('/ +/', ' ', preg_replace('/[^A-Za-z0-9 ]/', ' ', urldecode(html_entity_decode(strip_tags($query)))))); //generate url $url = self::$gb . 'games?api_key=' . self::$apikey . '&format=json' . self::formatFieldList($fieldArr) . '&limit=' . $limit . '&filter=platforms:17|94|152,name:' . $query; //Limit to Mac, PC, Linux respectively. try { $json = self::makeApiCall($url); } catch (Exception $e) { throw new GBApiException('Error contacting Giantbomb. Please try again later.'); } //QueryDb and try to find the object using the giantbomb unique id if ($json->results == null || count($json->results) < 1) { throw new GBApiException('No results found. Please try another search.'); } $games = []; //initialise as empty array foreach ($json->results as $result) { if (!isset($result->original_release_date) || $result->original_release_date == null) { continue; } //skip if not out yet. $game = GameQuery::create()->findOneByGbId($result->id); if (!isset($game)) { $game = new Game(); $game->setGbId($result->id); $game->setName(Game::generateUniqueName($result->name, $result->original_release_date)); } $game->setGbUrl($result->api_detail_url); $game->setTitle($result->name); $game->setDescription($result->deck); //We don't care if they don't have thumbs. Catch the exceptions and move on try { $game->setGbThumb($result->image->screen_url); } catch (Exception $e) { } try { $game->setGbImage($result->image->medium_url); } catch (Exception $e) { } $game->save(); //Fetch all of the title's platforms from the results we pulled from GB and push them into an array $gbplatforms = []; foreach ($result->platforms as $gbplatform) { array_push($gbplatforms, $gbplatform->id); } //Remove platforms no longer associated with the title $currentPlatforms = $game->getPlatforms(); foreach ($currentPlatforms as $plat) { if (!in_array($plat->getGbId(), $gbplatforms)) { $game->removePlatform($plat); } } //add new platforms associated with the title $allPlatforms = Platform::getAllPlatforms(); foreach ($allPlatforms as $plat) { if (in_array($plat->getGbId(), $gbplatforms)) { $found = false; foreach ($currentPlatforms as $curPlat) { if ($curPlat->getId() == $plat->getId()) { $found = true; break; } } if ($found) { continue; } $game->addPlatform($plat); } } //append result to list. $game->save(); array_push($games, $game); } return $games; }
require "res/include.php"; if (!Auth::checkIfAuthenticated() || !Auth::checkIfAdmin()) { header("Location: /"); /* Redirect browser */ } $user = Auth::getCurrentUser(); $game = null; $platform = null; $con = \Propel\Runtime\Propel::getConnection(); if (!array_key_exists("game", $_GET) || !array_key_exists("platform", $_GET)) { header("Location: /"); /* Redirect browser */ exit; } else { $con->beginTransaction(); $game = GameQuery::create()->filterByName($_GET["game"])->findOne($con); $platform = PlatformQuery::create()->filterByName($_GET["platform"])->findOne($con); if ($game == null || $platform == null) { header("Location: /"); /* Redirect browser */ exit; } } $header = RatingHeaderQuery::create()->filterByGame($game)->filterByPlatform($platform)->findOne($con); $categories = CategoryQuery::create()->orderBySequence()->find($con); $options = CategoryOptionQuery::create()->orderBySequence()->find($con); if (array_key_exists("rating_submit", $_POST)) { try { if ($header == null) { $header = new RatingHeader(); $header->setGame($game);