<?php

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

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

    /**
     * Returns a select entries list containing the categories.
     *
     * @param string $inputName
     * @param string $selectedCategory
     * @return string
     */
    public static function getSelectCategories($inputName, $selectedCategory) {
        $categoryArray = CategoryLister::GetAllCategories();

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

        foreach ($categoryArray as $category) {
            $name = $category->getName();

            if ($name == $selectedCategory) {
                $selected = "selected='selected'";
            } else {
                $selected = "";
            }

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

        $content .= "</select>";

        return $content;
    }
}
?>
