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

use lib '/app/tools/common/lib';

use lib '/app/tools/rps/lib';
use RPS::Command;
use RPS::AlphabeticalPagination;
use RPS::ArtistPayee::ArtistPayeeSimple;
use RPS::DB::Item::ArtistPayee;

use base 'RPS::Command';

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

sub cmd  { return 'list'; }
sub area { return 'artist_payee'; }

use constant kTemplate => "/app/tools/rps/templates/artist_payee/index.xsl";

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

    my $response = $self->SUPER::execute();
    return $response if $response;

    my %getArgs;

    # Get the pagination parameters
    #
    # jpk - note that I'm 'uc-ing' the parameter at the very end.
    # If you pass 'undef' to uc(), it returns '', which was screwing
    # things up.
    #
    my $page = $self->getParam("page");
    $page = 'A' if ( !defined $page );
    $page = uc($page);

    if ( 'ALL' ne $page ) {
        $getArgs{alpha} = $page;
    }

    my $searchCollection = RPS::DB::Item::ArtistPayee->Get(%getArgs);

    my $pagination = RPS::AlphabeticalPagination->new( currentPage => $page );

    while ( $searchCollection->hasNext() ) {
        my $obj = $searchCollection->next();
        push @{ $self->{xml}{ArtistPayee} }, RPS::ArtistPayee::ArtistPayeeSimple->new( _dbItem => $obj, loadSubs => 0 );
    }

    $self->{xml}{Pagination} = $pagination if $pagination;

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

1;
