Fix RandomAssetProxy macro.
This commit is contained in:
parent
193d30ec41
commit
b3faecae9b
1 changed files with 24 additions and 22 deletions
|
|
@ -13,6 +13,7 @@ package WebGUI::Macro::RandomAssetProxy;
|
|||
use strict;
|
||||
use WebGUI::Asset;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Exception;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -34,28 +35,29 @@ if no asset exists at that url, or if the asset has no children.
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub process {
|
||||
my $session = shift;
|
||||
my $url = shift;
|
||||
my $i18n = WebGUI::International->new($session,'Macro_RandomAssetProxy');
|
||||
my $asset = WebGUI::Asset->newByUrl($session, $url);
|
||||
if (defined $asset) {
|
||||
my $children = $asset->getLineage(["children"]);
|
||||
#randomize;
|
||||
my $randomAssetId = $children->[int(rand(scalar(@{$children})))];
|
||||
my $randomAsset = WebGUI::Asset->newById($session,$randomAssetId);
|
||||
if (defined $randomAsset) {
|
||||
if ($randomAsset->canView) {
|
||||
$randomAsset->toggleToolbar;
|
||||
$randomAsset->prepareView;
|
||||
return $randomAsset->view;
|
||||
}
|
||||
return undef;
|
||||
} else {
|
||||
return $i18n->get('childless');
|
||||
}
|
||||
} else {
|
||||
return $i18n->get('invalid url');
|
||||
}
|
||||
my $session = shift;
|
||||
my $url = shift;
|
||||
my $i18n = WebGUI::International->new($session,'Macro_RandomAssetProxy');
|
||||
my $asset = eval { WebGUI::Asset->newByUrl($session, $url); };
|
||||
if (Exception::Class->caught()) {
|
||||
return $i18n->get('invalid url');
|
||||
}
|
||||
|
||||
my $children = $asset->getLineage(["children"]);
|
||||
#randomize;
|
||||
my $randomAssetId = $children->[int(rand(scalar(@{$children})))];
|
||||
my $randomAsset = eval { WebGUI::Asset->newById($session,$randomAssetId); };
|
||||
if (Exception::Class->caught()) {
|
||||
return $i18n->get('childless');
|
||||
}
|
||||
elsif ($randomAsset->canView) {
|
||||
$randomAsset->toggleToolbar;
|
||||
$randomAsset->prepareView;
|
||||
return $randomAsset->view;
|
||||
}
|
||||
else {
|
||||
return undef;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue