|
Date: 10/20/2007 9:51 am · Subject: Re: Random Images · Rating: 0
It's really great. But i've experienced two issues when using RandomAssetProxy Marco. 1. When between the descendents of the Asset whose URL is supplied as the
argument there are an assets which are restricted to be seen by the current user, these assets are returned with value undef and nothing is displayed in this case, which is not what I expect to have. Therefore, I propose before the randomization is performed to check wich assets can be diplayed and the randomization to be performed only on these assets. For instance in this way: 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"]); my $childAsset; my @canViewAssets; my $i; foreach my $childId (@{$children}){ # walk through all children to see which one we can view $childAsset = WebGUI::Asset->newByDynamicClass($session,$childId); $canViewAssets[$i++] = $childAsset unless (!defined($childAsset) || !$childAsset->canView) ; } if (scalar(@canViewAssets) == 0) { return $i18n->get('childless'); } #randomize; srand; my $randomAsset = $canViewAssets[rand(scalar(@canViewAssets))]; $randomAsset->toggleToolbar; $randomAsset->prepareView; return $randomAsset->view; } else { return $i18n->get('invalid url'); } } or may be there is a better way. 2. When the page, where this macro is displayed, is requested by a "Visitor" user I still have a cache problem. A "Content Not Modified" is returned and the asset is not updated. Best regards, Todor Kouyoumdjiev ECoCoMS Ltd. www.ecocoms.com
--- (Edited on 10/20/2007 5:51 pm [GMT+0300] by todor_k) ---
|