#------------------------------------------------------------
# Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved
# $Id$
#------------------------------------------------------------
package RPS::Region::Command::List;

use lib '/app/tools/common/lib';
use RSApache::Response::XSLT;

use lib '/app/tools/rps/lib';
use RPS::Region::Region;
use RPS::Command;
use base 'RPS::Command';

use constant kTemplate => '/app/tools/rps/templates/region/index.xsl';

sub cmd  { return "list"; }
sub area { return "region"; }

sub execute {
    my ($self) = @_;

    # Give any inherited methods the first crack at this.
    # (This checks for login and basic access permissions).
    #
    my $response = $self->SUPER::execute();
    return $response if $response;

    my $regions = RPS::DB::Item::Region->GetAllEditable();

    while ( $regions->hasNext() ) {
        my $data = $regions->next();

        push @{ $self->{xml}{Region} }, RPS::Region::Region->new( _dbItem => $data );
    }

    $response = RSApache::Response::XSLT->new( $self->{xml}, kTemplate );

    return $response;
}

1;
