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

use lib '/app/tools/common/lib';
use base 'Common::DB::Item';

use constant kTable => 'label';
use constant kDB    => Common::DB::Item::kClientDB();

sub GetAll {
    my ($class) = @_;
    my $sql = "SELECT * FROM label ORDER BY label_name";

    return $class->SUPER::GetAll($sql);
}

sub GetDefault {
    my ($class) = @_;
    return RPS::DB::Item::Label->Lookup( is_default => 1 );
}

sub GetLabelNameFromTrackID {
    my ( $class, $trackID ) = @_;

    my $dbo = Common::RSApp::GetClientDB();

    my $sql =
      "SELECT label_name FROM track t,album a,label l WHERE t.track_id=$trackID AND t.album_id=a.album_id AND a.label_id=l.label_id";

    my $sth = $dbo->DoCmd($sql);

    my ($result) = $sth->fetchrow_array() if ($sth);

    return $result;
}

sub GetLabelsWithoutContracts {
    my ($class) = @_;

    my $sql = "select * from label left join label_contract_term using (label_id) where label_contract_term.label_id IS NULL";

    Common::Log::Debug("QUERY: $sql");

    return $class->GetAll($sql);
}

1;

