<?php

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

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

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

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

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

    public static function GetAll() {
       $sql = "SELECT rightId FROM userRight;";

        $result = MySQLDatabase::getInstance()->runRequest($sql);

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

    public static function GetForMember(Member $user) {
        return MemberRightLister::GetEntries("WHERE userId = " . $user->getIdentifier());
    }

    private static function GetEntries($restriction) {
        $sql = "SELECT rightId FROM userRightEntries $restriction;";

        $result = MySQLDatabase::getInstance()->runRequest($sql);

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