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

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

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

include_once './includes/users/userRights/MemberRightFormatter.inc.php';

/**
 * This class is responsible for easy formatting of users informations.
 *
 * @author Thomas Schwery <thomas.schwery@epfl.ch>
 */
class MemberFormatter {

    /**
     * Builds the HTML syntax for a summary box
     *
     * @return string
     */
    public static function getSummaryBox(Member $user) {
        return MemberFormatter::getHeaders($user, true, false);
    }

    public static function getFullView(Member $user) {
        $content = MemberFormatter::getHeaders($user, false, false);

        $userCategories = CategoryLister::GetCategoriesForMember($user);

        foreach ($userCategories as $category) {
            $content .= CategoryFormatter::getFullUser($category, $user);
        }

        return $content;
    }

    public static function GetAdminBox(Member $user) {
        return MemberFormatter::getHeaders($user, true, true);
    }

    /**
     * Returns a header box
     *
     * @param Member $user
     * @param boolean $linkOnName
     * @param boolean $displayRights
     * @return string
     */
    private static function getHeaders(Member $user, $linkOnName, $displayRights) {
        $identifier = $user->getIdentifier();
        $fullName = $user->getFullName();
        $birthday = DateFormatter::format($user->getBirthday());

        if ($displayRights) {
            $rights = MemberRightListFormatter::formatArray($user->getRights());
        } else {
            $rights = "";
        }

        if($linkOnName) {
            $nameLine = "<a href='./?page=Users&amp;userIdentifier=$identifier'>$fullName</a>";
        } else {
            $nameLine = $fullName;
        }

        $categoriesArray = CategoryLister::GetCategoriesForMember($user);
        $categories = "";

        foreach($categoriesArray as $category) {
            $categories .= " " . $category->getName();
        }

        $birthdayTitle = Localization::userBirthday;
        $categoriesTitle = Localization::userCategory;

        $content = <<<BOX
<div id='user-$identifier' class='user_box'>
    <h2>$nameLine</h2>
    <p>
        $birthdayTitle: $birthday\n<br>
        $categoriesTitle: $categories\n<br>
        $rights
    </p>
</div>
BOX;
        return $content;
    }
}
?>
