<?php

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

include_once './includes/users/MemberFormatter.inc.php';
include_once './includes/tournaments/TournamentEntryLister.inc.php';

/**
 * This class represents the public list of users.
 *
 * @author Thomas Schwery <thomas.schwery@epfl.ch>
 */
class UsersPage implements PageInterface {

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

    private function itemView() {
        $userIdentifier = $_GET['userIdentifier'];
        $member = Member::Get($userIdentifier);

        if ($member) {
            $this->title = $member->getFullName();
            $this->content = MemberFormatter::getFullView($member);
        }
    }

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

        $content = "";
        $userArray = MemberLister::getAllMembers();

        foreach ($userArray as $user) {
            $content .=  MemberFormatter::getSummaryBox($user);
        }

        $this->content = $content;
    }

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

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

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