<?php
require_once('global.php');
require_once(ABSOLUTE_PATH.'/class/LiveMatchesManager.php');
require_once(ABSOLUTE_PATH.'/class/Paginator.php');
require_once(ABSOLUTE_PATH.'/class/SummonerManager.php');

$template_body_class.= 'background-global';

$db = db::getInstance();
$lmm = LiveMatchesManager::getInstance();
$sm = SummonerManager::getInstance();

$meta_title = 'Live Matches &ndash; LoLSkill';
$meta_description = 'Check out matches that are currently being played by other summoners!';
$template_og['url'] = DYNAMIC_PATH.'/live-matches';
$template_og['title'] = 'Live Matches &ndash; LoLSkill';
$template_og['description'] = 'Check out matches that are currently being played by other summoners!';

$page = ((isset($_GET['p']))&&($_GET['p']!='')) ? intval($_GET['p']) : 1;
$limit = 10;
$offset = ($page * $limit) - $limit;
$total = $lmm->getTotal();

$paginator = new Paginator();
$paginator->setTotalPages(ceil($total / $limit));
$paginator->setCurrentPage($page);
$paginator->setPaginationVariance(5);
$paginator->setLink('live-matches/page-%p');
$paginator->setShowFirst(true);
$paginator->setShowPrevious(true);
$paginator->setShowNext(true);
$pagination = $paginator->paginate();

$matchesFeatured = $lmm->getFeaturedLiveMatches();
$matches = $lmm->getLiveMatches($offset, $limit);

// Featured live matches
$template_content.= $am->getLeaderboard();
$template_content.= '		<section id="featuredmatches">
			<div class="container">
				<h1 class="headline">Featured Matches</h1>';
if($matchesFeatured===null){
	$template_content.= '				<div class="alert alert-info" role="alert">
					Currently there are no featured matches available.
				</div>';
}else{
	foreach($matchesFeatured as $match){
		$template_content.= $lmm->getPrintableMatch($match);
	}
}
$template_content.= '			</div>
		</section>';
$template_content.= $am->getLeaderboard();

// Live matches
$template_content.= '		<section id="livematches">
			<div class="container">
				<h1 class="headline">Live Matches</h1>';
$template_content.= $pagination;
if($matches===null){
	$template_content.= '				<div class="alert alert-info" role="alert">
					Currently there are no live matches available.
				</div>';
}else{
	foreach($matches as $match){
		$template_content.= $lmm->getPrintableMatch($match);
	}
}
$template_content.= $pagination.'
				</div>
		</section>';
$template_content.= $am->getLeaderboard();

include_once(ABSOLUTE_PATH.'/template.php');
?>