Promote the getAllProducts to Asset.pm as getIsa. Move the tests

from Asset/Sku/Product.t into Asset/Asset.t, and add tests to check
that inheritance is respected.
This commit is contained in:
Colin Kuskie 2008-05-28 16:06:52 +00:00
parent 4aa428e927
commit 3ad1668a21
4 changed files with 73 additions and 52 deletions

View file

@ -1058,6 +1058,40 @@ sub getImportNode {
#-------------------------------------------------------------------
=head2 getIsa ( $session )
A class method to return an iterator for getting all Assets by class (and all sub-classes)
as Asset objects, one at a time. When the end of the assets is reached, then the iterator
will close the database handle that it uses and return undef.
It should be used like this:
my $productIterator = WebGUI::Asset::Product->getIsa($session);
while (my $product = $productIterator->()) {
##Do something useful with $product
}
=cut
sub getIsa {
my $class = shift;
my $session = shift;
my $def = $class->definition($session);
my $tableName = $def->[0]->{tableName};
my $sth = $session->db->read("select distinct(assetId) from $tableName");
return sub {
my ($assetId) = $sth->array;
if (!$assetId) {
$sth->finish;
return undef;
}
return WebGUI::Asset->newPending($session, $assetId);
};
}
#-------------------------------------------------------------------
=head2 getMedia ( session )

View file

@ -272,38 +272,6 @@ sub getAllCollateral {
}
#-------------------------------------------------------------------
=head2 getAllProducts ( $session )
A class method to return an iterator for getting all Products (and Product sub-classes)
as Asset objects, one at a time. The iterator will return undef when you've reached
the end of the list of products.
It should be used like this:
my $productIterator = WebGUI::Asset::Product->getAllProducts($session);
while (my $product = $productIterator->()) {
##Do something useful with $product
}
=cut
sub getAllProducts {
my $class = shift;
my $session = shift;
my $sth = $session->db->read('select distinct(assetId) from Product');
return sub {
my ($assetId) = $sth->array;
if (!$assetId) {
$sth->finish;
return undef;
}
return WebGUI::Asset->newPending($session, $assetId);
};
}
#-------------------------------------------------------------------
=head2 getCollateral ( tableName, keyName, keyValue )