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

use strict;
use warnings;
use Carp;
use Data::Dumper;

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

use lib '/app/tools/rps/lib';
use RPS::ArtistRoyalty::ArtistRoyaltyRun;
use RPS::DB::Item::ArtistRoyaltyRun;

use Common::FormObject;
use base 'Common::FormObject';

sub _init {
    my ( $self, %args ) = @_;
    my $timer = Common::Timer->new();

    $self->SUPER::_init(%args);

    $self->{ArtistRoyaltyRun} = [];

    my $collection = RPS::DB::Item::ArtistRoyaltyRun->GetAll();

    if ($collection) {
        while ( $collection->hasNext() ) {
            my $obj = $collection->next();

            push @{ $self->{ArtistRoyaltyRun} }, RPS::ArtistRoyalty::ArtistRoyaltyRun->new( _dbItem => $obj, loadSubs => 0 );
        }
    }

    # These should be sorted by run id.
    #
    @{ $self->{ArtistRoyaltyRun} } = sort { $b->ArtistRoyaltyRunID() <=> $a->ArtistRoyaltyRunID() } @{ $self->{ArtistRoyaltyRun} };

    return $self;
}

1;

