#------------------------------------------------------------
# Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved
# $Id$
#------------------------------------------------------------
package Support::DB::Item::ModuleAccess;
use strict;
use warnings;

use lib '/app/tools/rps/lib';

use lib '/app/tools/common/lib';
use Common::Assert;

use base 'Common::DB::Item';

use constant kTable => 'module_access';
use constant kDB    => Common::DB::Item::kCommonDB();

sub LookupSupportRole {
    my $class           = shift;
    my $support_role_id = shift;
    my $module_id       = shift;
    my $dbo             = Common::RSApp::GetCommonDB();

    return unless ($support_role_id);
    return unless ($module_id);

    my $sql =
        "SELECT * FROM "
      . kTable
      . " WHERE "
      . " module_id = "
      . $dbo->DBQuote($module_id) . " AND "
      . " support_role_id = "
      . $dbo->DBQuote($support_role_id) . " AND "
      . " user_id IS NULL ";

    my $collection = $class->GetAll($sql);
    return $collection->next();
}

sub LookupUser {
    my $class     = shift;
    my $user_id   = shift;
    my $module_id = shift;
    my $dbo       = Common::RSApp::GetCommonDB();

    return unless ($user_id);
    return unless ($module_id);

    my $sql =
        "SELECT * FROM "
      . kTable
      . " WHERE "
      . " module_id = "
      . $dbo->DBQuote($module_id) . " AND "
      . " user_id = "
      . $dbo->DBQuote($user_id) . " AND "
      . " support_role_id IS NULL ";

    my $collection = $class->GetAll($sql);
    return $collection->next();
}

1;
