<?php

include_once './pages/PageInterface.inc.php';

include_once './includes/tournaments/TournamentFormatter.inc.php';
include_once './includes/tournaments/TournamentLister.inc.php';
include_once './includes/tournaments/Tournament.inc.php';

/**
 * This class represents the user part of the Tournament system.
 *
 * @author Thomas Schwery <thomas.schwery@epfl.ch>
 */
class TournamentsPage implements PageInterface {

    public function __construct() {
        if (key_exists("tournamentIdentifier", $_GET)) {
            $this->itemView();
        } else {
            $this->listing();
        }
    }

    private function itemView() {
        $tournamentIdentifier = $_GET['tournamentIdentifier'];
        $tournament = Tournament::Get($tournamentIdentifier);

        if ($tournament) {
            $this->title = $tournament->getName();
            $this->content = TournamentFormatter::getFull($tournament);
        }
    }

    private function listing() {
        $this->title = Localization::tournamentList;

        $content = "";
        $tournamentsArray = TournamentLister::getAllTournaments();

        foreach ($tournamentsArray as $tournament) {
            $content .=  TournamentFormatter::getSummary($tournament);
        }

        $this->content = $content;
    }

    public function getContent() {
        return $this->content;
    }

    public function getTitle() {
        return $this->title;
    }

    public static function getStaticTitle() {
        return Localization::tournamentList;
    }
}
?>
