<?php

include_once './includes/menu/MenuEntry.inc.php';
include_once './includes/database/MySQLDatabase.inc.php';

include_once './includes/utils/MapperUtils.inc.php';

/**
 * This class allows for easy listing of menu entries.
 *
 * @author Thomas Schwery <thomas.schwery@epfl.ch>
 */
class MenuEntryLister {

    public static function getAllEntries() {
        return MenuEntryLister::getEntries("");
    }

    public static function getAllFromMenu($menuIdentifier) {
        return MenuEntryLister::getEntries("WHERE menuId = $menuIdentifier");
    }

    private static function getEntries($restriction) {
        $sql = "SELECT identifier FROM menuEntries $restriction ORDER BY weight;";
        $result = MySQLDatabase::getInstance()->runRequest($sql);

        if ($result) {
            $result1 = array_map("mapIdentifierToMenuEntry", $result);
            return $result1;
        } else {
            return array();
        }
    }
}
?>
