Skip to content

Commit

Permalink
Merge branch 'master' into alt_names
Browse files Browse the repository at this point in the history
  • Loading branch information
Zer0xFF authored Feb 23, 2019
2 parents f2a544c + 9e71c44 commit fece964
Show file tree
Hide file tree
Showing 22 changed files with 637 additions and 152 deletions.
8 changes: 5 additions & 3 deletions API/include/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
$fields = Utils::parseRequestedFields();

$API = TGDB::getInstance();
if(isset($_REQUEST['filter']['platform']) && (!is_array($_REQUEST['filter']['platform'] || !in_array(0, $_REQUEST['filter']['platform']))))
if(isset($_REQUEST['filter']['platform']) && (!is_array($_REQUEST['filter']['platform']) || !in_array(0, $_REQUEST['filter']['platform'])))
{
if(!is_array($_REQUEST['filter']['platform']))
{
Expand Down Expand Up @@ -210,8 +210,10 @@
$list = $API->GetGameBoxartByID($GameIDs, $offset, $limit+1, $filters);

if($has_next_page = count($list) > $limit)
unset($list[end(array_keys($list))]);

{
$list_keys = array_keys($list);
unset($list[end($list_keys)]);
}
$JSON_Response = Utils::getStatus(200);
$JSON_Response['data'] = array("count" => count($list), 'base_url' => CommonUtils::getImagesBaseURL(), "images" => $list);
$JSON_Response['pages'] = Utils::getJsonPageUrl($page, $has_next_page);
Expand Down
152 changes: 142 additions & 10 deletions include/TGDB.API.php
Original file line number Diff line number Diff line change
Expand Up @@ -609,12 +609,28 @@ function GetGamesByPubID($IDs = 0, $offset = 0, $limit = 20, $fields = array(),
}
}

function GetMissingGames($field, $offset = 0, $limit = 20, $fields = array(), $OrderBy = '', $ASCDESC = 'ASC')
function GetMissingGames($field, $platform_ids = 0, $offset = 0, $limit = 20, $fields = array(), $OrderBy = '', $ASCDESC = 'ASC')
{
if(!$this->is_valid_games_col($field))
{
return array();
}

if(is_array($platform_ids))
{
if(!empty($platform_ids))
{
foreach($platform_ids as $platform_id)
if(is_numeric($platform_id))
$valid_platform_ids_arr[] = $platform_id;
}
$valid_platform_ids = implode(",", $valid_platform_ids_arr);
}
else if(is_numeric($platform_ids) && $platform_ids != 0)
{
$valid_platform_ids = $platform_ids;
}

$qry = "Select id, game_title, release_date, platform ";

if(!empty($fields))
Expand All @@ -631,7 +647,11 @@ function GetMissingGames($field, $offset = 0, $limit = 20, $fields = array(), $O
$qry .= " FROM games ";


$qry .= "WHERE $field = '' OR $field IS NULL ";
$qry .= "WHERE ($field = '' OR $field IS NULL) ";
if(isset($valid_platform_ids))
{
$qry .= "AND (platform IN ($valid_platform_ids)) ";
}
if(!empty($OrderBy) && $this->is_valid_games_col($OrderBy))
{
if($ASCDESC != 'ASC' && $ASCDESC != 'DESC')
Expand Down Expand Up @@ -674,8 +694,23 @@ function GetMissingGames($field, $offset = 0, $limit = 20, $fields = array(), $O
}
}

function GetMissingGamesImages($type, $sub_type = '', $offset = 0, $limit = 20, $fields = array(), $OrderBy = '', $ASCDESC = 'ASC')
function GetMissingGamesImages($type, $sub_type = '', $platform_ids = 0, $offset = 0, $limit = 20, $fields = array(), $OrderBy = '', $ASCDESC = 'ASC')
{

if(is_array($platform_ids))
{
if(!empty($platform_ids))
{
foreach($platform_ids as $platform_id)
if(is_numeric($platform_id))
$valid_platform_ids_arr[] = $platform_id;
}
$valid_platform_ids = implode(",", $valid_platform_ids_arr);
}
else if(is_numeric($platform_ids))
{
$valid_platform_ids = $platform_ids;
}
$qry = "Select id, game_title, release_date, platform ";

if(!empty($fields))
Expand All @@ -696,7 +731,11 @@ function GetMissingGamesImages($type, $sub_type = '', $offset = 0, $limit = 20,
{
$side = 'AND side=:side';
}
$qry .= "WHERE id NOT IN (select games_id from banners where type=:type $side) ";
$qry .= "WHERE (id NOT IN (select games_id from banners where type=:type $side)) ";
if($platform_id > 0)
{
$qry .= "AND (platform IN ($valid_platform_ids)) ";
}
if(!empty($OrderBy) && $this->is_valid_games_col($OrderBy))
{
if($ASCDESC != 'ASC' && $ASCDESC != 'DESC')
Expand Down Expand Up @@ -828,6 +867,48 @@ function GetGameBoxartByID($IDs = 0, $offset = 0, $limit = 20, $filters = 'boxar
}
}

function GetGameBoxartTypes()
{
$dbh = $this->database->dbh;
$sth = $dbh->prepare('SELECT DISTINCT type, side FROM `banners`;');

$sth->bindValue(':offset', $offset, PDO::PARAM_INT);
$sth->bindValue(':limit', $limit, PDO::PARAM_INT);

if($sth->execute())
{
$res = $sth->fetchAll(PDO::FETCH_OBJ);
return $res;
}
}

function GetLatestGameBoxartStats($limit = 20)
{
$type_list = $this->GetGameBoxartTypes();

$queries = array();
foreach($type_list as $type)
{
$qry = "(Select games_id as game_id, type, side, filename, resolution FROM banners WHERE type = '$type->type'";

if(!empty($type->side) && ($type->side == 'front' || $type->side == 'back'))
{
$qry .= " AND side = '$type->side' ";
}
$qry .= " ORDER BY id DESC LIMIT $limit)";
$queries[] = $qry;
}

$dbh = $this->database->dbh;
$sth = $dbh->prepare(implode(" Union ", $queries));

if($sth->execute())
{
$res = $sth->fetchAll(PDO::FETCH_OBJ);
return $res;
}
}

function GetLatestGameBoxart($offset = 0, $limit = 20, $filters = 'boxart', $side = '')
{
$qry = "Select games_id as game_id, type, side, filename, resolution FROM banners WHERE 1 ";
Expand Down Expand Up @@ -1462,27 +1543,65 @@ function is_valid_games_col($name)

/* Everything belowis not planned to be exposed through external API */

function InsertUserGameBookmark($users_id, $games_id, $is_booked)
function InsertUserGameBookmark($users_id, $Game, $is_booked)
{
$dbh = $this->database->dbh;

$sth = $dbh->prepare("INSERT INTO `user_games` (users_id, games_id, is_booked)
VALUES (:users_id, :games_id, :is_booked)
$sth = $dbh->prepare("INSERT INTO `user_games` (users_id, games_id, platforms_id, is_booked)
VALUES (:users_id, :games_id, :platforms_id, :is_booked)
ON DUPLICATE KEY UPDATE is_booked = :is_booked2");
$sth->bindValue(':games_id', $games_id);
$sth->bindValue(':games_id', $Game->id);
$sth->bindValue(':platforms_id', $Game->platform);
$sth->bindValue(':users_id', $users_id);
$sth->bindValue(':is_booked', $is_booked);
$sth->bindValue(':is_booked2', $is_booked);

return ($sth->execute());
}

function GetUserBookmarkedGames($users_id)
function GetUserBookmarkedGamesGroupByPlatform($users_id)
{
$dbh = $this->database->dbh;

$sth = $dbh->prepare("Select G.platform, G.id, G.game_title, G.release_date, G.platform FROM `user_games` UG, `games` G where UG.users_id=:users_id AND UG.is_booked=1 AND G.id = UG.games_id ORDER BY UG.added DESC");
$sth->bindValue(':users_id', $users_id);

if($sth->execute())
{
$res = $sth->fetchAll(PDO::FETCH_OBJ | PDO::FETCH_GROUP);
return $res;
}
}

function GetUserBookmarkedGamesByPlatformID($users_id, $platform_id, $offset = 0, $limit = 18)
{
$dbh = $this->database->dbh;

$sth = $dbh->prepare("Select G.id, G.game_title, G.release_date FROM `user_games` UG, `games` G where UG.users_id=:users_id AND UG.is_booked=1 AND G.id = UG.games_id ORDER BY UG.added DESC");
$sth = $dbh->prepare("Select G.platform, G.id, G.game_title, G.release_date, G.platform FROM `user_games` UG, `games` G
where UG.users_id=:users_id AND UG.is_booked=1 AND G.platform = :platform_id AND G.id = UG.games_id ORDER BY UG.added DESC LIMIT :limit OFFSET :offset");

$sth->bindValue(':users_id', $users_id);
$sth->bindValue(':platform_id', $platform_id);

$sth->bindValue(':offset', $offset);
$sth->bindValue(':limit', $limit);

if($sth->execute())
{
$res = $sth->fetchAll(PDO::FETCH_OBJ | PDO::FETCH_GROUP);
return $res;
}
}

function GetUserBookmarkedGames($users_id, $offset = 0, $limit = 18)
{
$dbh = $this->database->dbh;

$sth = $dbh->prepare("Select G.id, G.game_title, G.release_date, G.platform FROM `user_games` UG, `games` G where UG.users_id=:users_id AND UG.is_booked=1 AND G.id = UG.games_id ORDER BY UG.added DESC LIMIT :limit OFFSET :offset");
$sth->bindValue(':users_id', $users_id);

$sth->bindValue(':offset', $offset);
$sth->bindValue(':limit', $limit);

if($sth->execute())
{
Expand All @@ -1491,6 +1610,19 @@ function GetUserBookmarkedGames($users_id)
}
}

function GetUserBookmarkedGamesPlatforms($users_id)
{
$dbh = $this->database->dbh;

$sth = $dbh->prepare("Select DISTINCT platforms_id FROM `user_games` WHERE users_id=:users_id AND is_booked=1");
$sth->bindValue(':users_id', $users_id);
if($sth->execute())
{
$res = $sth->fetchAll(PDO::FETCH_COLUMN);
return $res;
}
}

function isUserGameBookmarked($users_id, $games_id)
{
$dbh = $this->database->dbh;
Expand Down
2 changes: 1 addition & 1 deletion website/actions/add_game_bookmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function returnJSONAndDie($code, $msg)
}

$is_booked = $_REQUEST['is_booked'] > 0 ? 1 : 0;
$res = $API->InsertUserGameBookmark($_user->GetUserID(), $_REQUEST['games_id'], $is_booked);
$res = $API->InsertUserGameBookmark($_user->GetUserID(), $Game, $is_booked);
if($res)
{
returnJSONAndDie(0, $is_booked);
Expand Down
52 changes: 27 additions & 25 deletions website/browse.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,23 @@
<div class="card">
<form class="card-body" method="get" action="./search.php">
<fieldset>
<legend>Search by name</legend>
<div class="form-group row">
<label for="name" class="col-sm-2 col-form-label">Name</label>
<div class="col-sm-10">
<input name="name" type="text" class="form-control-plaintext" id="name" placeholder="God Of War...">
<legend>Search by name</legend>
<div class="form-group row">
<label for="name" class="col-sm-2 col-form-label">Name</label>
<div class="col-sm-10">
<input name="name" type="text" class="form-control-plaintext" id="name" placeholder="God Of War...">
</div>
</div>
</div>
<div class="form-group">
<label for="platformselect">Select Platform</label>
<select name="platform_id[]" multiple class="form-control" id="platformselect">
<option value="0" selected>All</option>
<?php foreach($PlatformList as $id => $Platform) :?>
<option value="<?= $id ?>"><?= $Platform->name ?></option>
<?php endforeach; ?>
</select>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
<div class="form-group">
<label for="platformselect">Select Platform</label>
<select name="platform_id[]" multiple class="form-control" id="platformselect">
<option value="0" selected>All</option>
<?php foreach($PlatformList as $id => $Platform) :?>
<option value="<?= $id ?>"><?= $Platform->name ?></option>
<?php endforeach; ?>
</select>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</fieldset>
</form>
</div>
Expand All @@ -100,15 +100,17 @@
<div class="col-md-10">
<div class="card">
<div class="card-body">
<legend>Browse by platform</legend>
<div class="grid-container grid-col-config" style=" text-align: center">
<?php foreach($PlatformList as $id => $Platform) :?>
<a class="btn btn-link grid-item" href="./listgames.php?platform_id=<?= $id ?>">
<img src="<?= TGDBUtils::GetCover($Platform, 'icon', '', true, true, 'original') ?>">
<p><?= $Platform->name ?></p>
</a>
<?php endforeach; ?>
</div>
<fieldset>
<legend>Browse by platform</legend>
<div class="grid-container grid-col-config" style=" text-align: center">
<?php foreach($PlatformList as $id => $Platform) :?>
<a class="btn btn-link grid-item" href="./list_games.php?platform_id=<?= $id ?>">
<img alt="<?= $Platform->name ?>" src="<?= TGDBUtils::GetCover($Platform, 'icon', '', true, true, 'original') ?>">
<p><?= $Platform->name ?></p>
</a>
<?php endforeach; ?>
</div>
</fieldset>
</div>
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions website/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,7 @@ footer *
bottom: 95px !important;;
}

h1, h2, h3, h4, h5, h6
{
text-transform: none !important;
}
Loading

0 comments on commit fece964

Please sign in to comment.