<?php

include_once './includes/tournaments/TournamentEntryFormatter.inc.php';
include_once './includes/tournaments/TournamentEntryLister.inc.php';

include_once './includes/tournaments/CategoryLister.inc.php';
include_once './includes/tournaments/CategoryFormatter.inc.php';

include_once './includes/utils/DateFormatter.inc.php';

/**
 * This class allows for easy formatting of tournaments.
 *
 * @author Thomas Schwery <thomas.schwery@epfl.ch>
 */
class TournamentFormatter {

    public static function getSummary(Tournament $tournament) {
        return TournamentFormatter::getHeaders($tournament, true);
    }

    public static function getFull(Tournament $tournament) {
        $content = TournamentFormatter::getHeaders($tournament, false);

        $tournamentCategories = CategoryLister::GetCategoriesForTournament($tournament);

        foreach ($tournamentCategories as $category) {
            $content .= CategoryFormatter::getFullTournament($category, $tournament);
        }

        return $content;
    }

    private static function getHeaders(Tournament $tournament, $linkOnName) {
        $identifier = $tournament->getIdentifier();
        $name = $tournament->getName();
        $location = $tournament->getLocation();
        $comments = $tournament->getComments();
        $type = $tournament->getType();
        $date = DateFormatter::formatDMY($tournament->getDate());

        $happenedOn = Localization::happenedOn($location, $date);

        if ($linkOnName) {
            $nameLine = "<a href='index.php?page=Tournaments&amp;tournamentIdentifier=$identifier'>$name</a>";
        } else {
            $nameLine = $name;
        }

        $content = <<<BOX
<div id='tournament-$identifier' class='tournament_box'>
    <h2>$nameLine</h2>
    <p>
        $type<br>
        $happenedOn
    </p>
</div>
BOX;
        return $content;
    }
}
?>
