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

use strict;
use warnings;

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

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

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

# This is a read-only XMLObject, so we don't need any
# of the accessor methods, just create the list of
# items and be on your way.
#

sub _init {
    my ( $self, %args ) = @_;

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

    $self->{Label} = [];
    my $labelCollection;
    if ( $args{emi} ) {
        $labelCollection = RPS::DB::Item::Label->GetAllWithAlbums();
    } else {
        $labelCollection = RPS::DB::Item::Label->GetAll();
    }

    # !!! We require there to be a list of labels.
    # !!! If there isn't at least one, then we have not set up this client correctly.
    #
    assert( $labelCollection->size() > 0 );

    my $omitHash = $args{omit};
    while ( $labelCollection->hasNext() ) {
        my $labelObj = $labelCollection->next();
        if ( $omitHash && $omitHash->{ $labelObj->label_id } ) {
            next;
        }
        push @{ $self->{Label} }, RPS::Label->new( _dbItem => $labelObj );
    }

    return $self;
}

1;
