Click here to register.
      
irc://irc.freenode.net#webgui

iPhoneGuy: WebGUI is a pile of crap.
rizen: If WebGUI is such a pile of crap, why do you use it?
iPhoneGuy: Because it's the best pile of crap out there.

If this is what people who hate us are saying, imagine what people who love us will say. Come join us on IRC.


     Discuss > Etcetera

Random Images

User fishingfan
Date 10/15/2007 5:39 am
Views 1092
Rating 0    Rate [
|
]
Previous · Next
User Message
fishingfan

Hello

I would like to know how to do the following in WebGUI.   I seem to recall we could do this in version 5, the randomimage macro but can't work out how to do it now.

Have say 3-4 pictures on the site (maybe in a certain folder) and have a random one of these but not others held elsewhere selected and displayed on the homepage or in an article. 

Chris

CA-Dev.co.uk 

--- (Edited on 10/15/2007 5:40 am [GMT-0500] by fishingfan) ---



Back to Top
Rate [
|
]
 
 
preaction
You can use the RandomAssetProxy macro. Lookup the docs on the Wiki.

--- (Edited on 10/15/2007 7:19 am [GMT-0500] by preaction) ---



Back to Top
Rate [
|
]
 
 
fishingfan

Thanks that's great.  

Just what I was looking for!Cool

Chris

CA-Dev.co.uk 

--- (Edited on 10/16/2007 7:22 am [GMT-0500] by fishingfan) ---



Back to Top
Rate [
|
]
 
 
todor_k

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) ---



Back to Top
Rate [
|
]
 
 
     Discuss > Etcetera




Re: Config File Changes by pwrightson - Fri @ 04:07pm

Re: IRC Logs by koen - Fri @ 02:08pm

Re: IRC Logs by patspam - Fri @ 02:01pm

Re: IRC Logs by koen - Fri @ 01:42pm

Re: How do I find al my submitted RFE's? by bartjol - Fri @ 01:39pm

Re: IRC Logs by kristi - Fri @ 01:27pm

Re: LastModified question by perlDreamer - Fri @ 12:57pm

Re: How do I find al my submitted RFE's? by bartjol - Fri @ 12:11pm

How do I find al my submitted RFE's? by koen - Fri @ 11:23am

Re: IRC Logs by koen - Fri @ 11:20am

IRC Logs by martink - Fri @ 10:51am

Re: cleaning out the wiki by koen - Fri @ 10:44am

Re: shop in 7.5.21 by kristi - Fri @ 09:03am

shop in 7.5.21 by erikms - Fri @ 08:07am