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

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

use lib '/app/tools/rps/lib';
use RPS::SearchCommand;
use base 'RPS::SearchCommand';


use constant kPageSize => 30;

sub cmd  { return "search"; }

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

	# Give any inherited methods the first crack at this.
	# (This checks for login and basic access permissions).
	#
	my $response;
	my %searchArgs = (xmlClass => $self->_publisherObj(),
					  xmlTag   => 'Publisher',
					  pageSize => kPageSize);

	if($self->getParam("AgentID") || $self->getParam("AdminID"))
	{
		my $collection;
		if($self->getParam("AgentID"))
		{
			$collection = $self->_publisherDB()->GetByAgentID($self->getParam("AgentID"));
		}
		elsif($self->getParam("AdminID"))
		{
			$collection = $self->_publisherDB()->GetByAdminID($self->getParam("AdminID"));
		}

		# admin or agent search
		#
		$searchArgs{collection} = $collection;
	}
	else
	{
		# regular search, either show all or search by Query
		#
		$searchArgs{dbClass} = $self->_publisherDB();
	}

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

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


1;
