#------------------------------------------------------------
# Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved
#------------------------------------------------------------
package BookPub::Analytics::Command::GeoSummary;

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

use lib '/app/tools/bookpub/lib';
use BookPub::Analytics::GeoSummaryReport;

use BookPub::Command;
use base 'BookPub::Command';

sub cmd      { return "gs"; }
sub area     { return "analytics"; }
sub pageName { 'Geographic Summary'; }

use constant kTemplate => '/app/tools/bookpub/templates/analytics.xsl';

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 $periodType  = lc( $self->getParam("period_type") || 'q' );
    my $periodParam = $self->getParam("period");
    my $endPeriod   = $self->getParam("end_period");
    
    my $imprintID   = $self->getParam("imprint") || undef;
    my $publisherID = $self->getParam("publisher") || undef;
    my $countryCode = $self->getParam("country");

    $self->{xml}{Report} = BookPub::Analytics::GeoSummaryReport->new(
        periodType  => $periodType,
        periodParam => $periodParam,
        endPeriodParam => $endPeriod,
        imprintID   => $imprintID,
        publisherID => $publisherID,
        countryCode => $countryCode,
        commandObj  => $self,
    );

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

1;
