<?php

include_once './includes/users/Member.inc.php';
include_once './includes/users/MemberLister.inc.php';

/**
 * This class allows for easy formatting of complete lists of members.
 *
 * @author Thomas Schwery <thomas.schwery@epfl.ch>
 */
class MemberListFormatter {

    /**
     * Returns a select entries list containing the users for use in forms.
     *
     * @param string $inputName
     * @param string $selectedUsername
     * @return string
     */
    public static function getSelectMembers($inputName, $selectedUsername) {
        $usersArray = MemberLister::getAllMembers();

        $content = '<select name="'.$inputName.'">';

        foreach ($usersArray as $user) {
            $username = $user->getUsername();
            $fullName = $user->getFullname();

            if ($username == $selectedUsername) {
                $selected = "selected='selected'";
            } else {
                $selected = "";
            }

            $content .= '<option value="' . $username . '" ' . $selected . '>' . $fullName . '</option>';
        }

        $labelEmpty = Localization::generalDelete;

        if ($selectedUsername == "delete") {
            $content .= '<option value="delete" selected="selected">'.$labelEmpty.'</option>';
        } else {
            $content .= '<option value="delete">'.$labelEmpty.'</option>';
        }

        $content .= "</select>";

        return $content;
    }
}
?>
