Skip to content

Instantly share code, notes, and snippets.

@John2496
Created June 17, 2010 19:06
Show Gist options
  • Save John2496/442596 to your computer and use it in GitHub Desktop.
Save John2496/442596 to your computer and use it in GitHub Desktop.
<?php
include dirname(__FILE__) . '/../BucketsManagement/Main.class.php';
class FeaturedContentManagement extends BucketsManagement
{
protected $daos = array(
'GameDAO',
'ResourceDAO',
'AssetDAO',
'SourceDAO',
'CategoryDAO',
);
protected $modules = array(
'AssetsManagement',
'ResourcesManagement',
'GameManagement',
);
public function index()
{
return array();
}
public function showTopFeaturedGames()
{
$games = $this->db->fetchAll('SELECT * FROM gm_games ORDER BY title ASC');
return array(
'games' => $games,
);
}
public function createXmlFiles()
{
ob_start();
$this->load('showFeaturedContentXml');
$featuredContentXml = ob_get_clean();
$path = $this->Settings->get('game_nav_xml_file_path') . '/' . 'games_featured_content.xml';
//$path = 'games_featured_content.xml';
file_put_contents($path, $featuredContentXml);
ob_start();
$this->load('showTopFeaturedContentXml');
$topFeaturedContentXml = ob_get_clean();
$path = $this->Settings->get('game_nav_xml_file_path') . '/' . 'games_topfeature.xml';
//$path = 'games_topfeature.xml';
file_put_contents($path, $topFeaturedContentXml);
}
public function showFeaturedContentXml()
{
$this->Theme->disable();
$sources = $this->db->fetchAll('SELECT * FROM rm_sources', 'source_id');
$categories = $this->CategoryDAO->findWhere('category_id != 1 ORDER BY sort_order ASC');
array_unshift($categories, new VO(array('category_id' => 9999, 'name' => 'Featured')));
// Dl mod
$dlCatId = -1;
foreach ($categories as $cat)
{
if ($cat->get('name') == 'Downloadable')
{
$dlCatId = $cat->get('category_id');
break;
}
}
$cId = 0;
$gamesSortedByCategory = array();
foreach ($categories as $cat)
{
$gamesSortedByCategory[$cat->get('name')] = array();
if ($cat->get('category_id') == 9999)
{
$games = $this->GameDAO->findWhere('is_featured = 1 ORDER BY featured_sort_order ASC');
}
else
{
$games = $this->GameDAO->findWhere('category_id = ' . $cat->get('category_id') . ' ORDER BY sort_order ASC');
}
foreach ($games as $game)
{
if ($game->get('is_active'))
{
$gameName = strtolower($game->get('friendly_url'));
//$gameName = strtolower(str_replace(' ', '-', $game->get('title')));
$gameHref = '';
$gameIcon = '';
if (($game->get('category_id') == $dlCatId || $game->get('type') == 'downloadable') && $this->Settings->get('game_nav_xml_dl_js'))
{
$gameHref = "javascript:sn_display('" . $game->get('uuid') . "');";
$gameIcon = 'download';
}
else
{
if ($game->get('is_external') || $game->get('type') == 'external')
{
$gameHref = $game->get('external_url');
}
else
{
$source = $sources[4];
$gameHref = '/' . $source['uri'] . $gameName;
}
}
$coverArt = $this->db->fetchRow('SELECT * FROM gm_assets, am_assets, rm_resources
WHERE gm_assets.game_id = ' . $game->get('game_id') . '
AND gm_assets.asset_id = am_assets.asset_id
AND am_assets.type = \'cover-art-medium\'
AND am_assets.resource_id != 0
AND am_assets.resource_id = rm_resources.resource_id');
///$source = $sources[$coverArt['source_id']];
$source = $sources[5];
//$url = 'http://' . $source['hostname'] . '/' . $source['uri'] . $coverArt['relative_path'] . $coverArt['name'];
//$url = $source['uri'] . $coverArt['relative_path'] . $coverArt['name'];
$url = '/' . $source['uri'] . $coverArt['relative_path'] . $coverArt['name'];
$gameDetails = array(
'title' => $game->get('title'),
'icon' => $gameIcon,
'short_description' => $game->get('short_description'),
'link_href' => $gameHref,
'thumb_src' => $url,
);
$gamesSortedByCategory[$cat->get('name')][] = $gameDetails;
}
}
}
return array(
'gamesSortedByCategory' => $gamesSortedByCategory,
);
}
public function showTopFeaturedContentXml()
{
$this->Theme->disable();
$categories = $this->db->fetchAll('SELECT * FROM gm_categories ORDER BY name', 'category_id');
$assetsSortedByType = $this->getAssetsSortedByType();
$items = array();
for ($i = 1; $i <= 4; $i++)
{
$largeAsset = $assetsSortedByType['static-homepage-game-large-' . $i][0];
$largeAssetVars = $largeAsset->get('vars');
$smallAsset = $assetsSortedByType['static-homepage-game-small-' . $i][0];
$game = $this->GameDAO->retrieve($largeAssetVars['game_id']);
$gameAssets = $this->ModuleLoader->initialize('GameManagement')->getAssetsSortedByType($largeAssetVars['game_id']);
$items[$i]['game'] = $game;
$items[$i]['category_name'] = $categories[$game->get('category_id')]['name'];
$items[$i]['game_title'] = $game->get('title');
if ($game->get('type') == 'external' || $game->get('type') == 'downloadable')
{
$items[$i]['game_friendly_url'] = $game->get('external_url');
}
else
{
$items[$i]['game_friendly_url'] = $game->get('friendly_url');
}
$items[$i]['game_short_description'] = $game->get('short_description');
$items[$i]['game_long_description'] = $game->get('long_description');
$items[$i]['color'] = $largeAssetVars['color'];
$items[$i]['small_asset_url'] = $smallAsset->getResource()->getUri() . $smallAsset->getResource()->get('name');
$items[$i]['large_asset_url'] = $largeAsset->getResource()->getUri() . $largeAsset->getResource()->get('name');
//$items[$i]['small_asset_url'] = $gameAssets['cover-art-small'][0]->getResource()->getUri() . $gameAssets['cover-art-small'][0]->getResource()->get('name');
//$items[$i]['large_asset_url'] = $gameAssets['cover-art-large'][0]->getResource()->getUri() . $gameAssets['cover-art-large'][0]->getResource()->get('name');
}
return array(
'items' => $items,
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment