<?php
/**
 * available variables:
 * category_form = form to select ranking category
 * results = array of results
 * selected = selected category
 */
?>
<h2><?= t("Ranking"); ?></h2>
<h3><?= t("Najlepsi z najlepszych"); ?></h3>
<?= drupal_render($category_form); ?>
<div class="rank">
	<?php if ($selected == 'general-points' || $selected == 'general'): ?>
		<?php $i = 1; ?>
		<h2><?= t('Klasyfikacja') . ' : ' . $selected; ?></h2>
		<div class="row row-init">
			<div class="col-md-1">
				<span><?= t("Miejsce"); ?></span>
			</div>
			<div class="col-md-3">
				<span><?= t("Nick"); ?></span>
			</div>
			<div class="col-md-1">
				<span><?= t("Poziom"); ?></span>
			</div>
			<div class="col-md-1">
				<span><?= t("Punkty"); ?></span>
			</div>
			<div class="col-md-2">
				<span><?= t("Wypełnione Quizy"); ?></span>
			</div>
			<div class="col-md-4">
				<span><?= t("Średni czas odpowiedzi po opublikowaniu quizu"); ?></span>
			</div>
		</div>
		<?php foreach ($results as $key => $winner): ?>
			<div class="row row-<?= $i; ?>">
				<div class="col-md-1">
					<span><?= $i; ?></span>
				</div>
				<div class="col-md-3">
					<span><?= $winner['username']; ?></span>
				</div>
				<div class="col-md-1">
					<span><?= $winner['level']; ?></span>
				</div>
				<div class="col-md-1">
					<span><?= $winner['points']; ?></span>
				</div>
				<div class="col-md-2">
					<span><?= $winner['quiz']; ?></span>
				</div>
				<div class="col-md-4">
					<span><?= $winner['average_time_human_readable']; ?></span>
				</div>
			</div>
			<?php $i++; ?>
		<?php endforeach; ?>
	<?php endif; ?>
	<?php if ( $selected == 'category'): ?>
		<?php if (!empty($results)): ?>
			<?php foreach ($results as $name => $winners): ?>
				<h2><?= t('Klasyfikacja') . ' : ' . $name; ?></h2>
				<?php if (!empty($winners)): ?>
					<div class="row row-init">
						<div class="col-md-1">
							<span><?= t("Miejsce"); ?></span>
						</div>
						<div class="col-md-3">
							<span><?= t("Nick"); ?></span>
						</div>
						<div class="col-md-1">
							<span><?= t("Poziom"); ?></span>
						</div>
						<div class="col-md-1">
							<span><?= t("Punkty"); ?></span>
						</div>
						<div class="col-md-2">
							<span><?= t("Wypełnione Quizy"); ?></span>
						</div>
						<div class="col-md-4">
							<span><?= t("Średni czas odpowiedzi po opublikowaniu quizu"); ?></span>
						</div>
					</div>
					<?php $i = 1; ?>
					<?php foreach ($winners as $key => $winner): ?>
						<div class="row row-<?= $i; ?>">
							<div class="col-md-1">
								<span><?= $i; ?></span>
							</div>
							<div class="col-md-3">
								<span><?= $winner['username']; ?></span>
							</div>
							<div class="col-md-1">
								<span><?= $winner['level']; ?></span>
							</div>
							<div class="col-md-1">
								<span><?= $winner['points']; ?></span>
							</div>
							<div class="col-md-2">
								<span><?= $winner['quiz']; ?></span>
							</div>
							<div class="col-md-4">
								<span><?= $winner['average_time_human_readable']; ?></span>
							</div>
						</div>
						<?php $i++; ?>
					<?php endforeach; ?>
			<?php endif; ?>
		<?php endforeach; ?>
		<?php else: ?>
			<div class="row no-result">
				<span><?= t('Brak zwycięzców, czekamy na ciebie!') ;?></span>
			</div>
		<?php endif; ?>
	<?php endif; ?>
</div>
