From 71d6a3bd282b01c138d9fb746091b63972c9c29c Mon Sep 17 00:00:00 2001 From: Frank Dillon Date: Thu, 7 Sep 2006 20:47:13 +0000 Subject: [PATCH] fixed "randomness" to only include CS's that are not empty. Returning an random CS that was empty would throw an error. --- lib/WebGUI/Macro/RandomThread.pm | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/WebGUI/Macro/RandomThread.pm b/lib/WebGUI/Macro/RandomThread.pm index d7badeb1d..c2258913e 100644 --- a/lib/WebGUI/Macro/RandomThread.pm +++ b/lib/WebGUI/Macro/RandomThread.pm @@ -93,6 +93,23 @@ sub process { $session->errorHandler->warn('Error: no Collaboration Systems found with current parameters. Check parameters of macro on page '.$session->asset->get('url')); return ''; } + + #Trim off any CS's that have no threads + my @llist = (); + foreach my $csid (@{$lineage}) { + my $cs = undef; + # Get random thread in that CS: + $cs = WebGUI::Asset->new($session,$csid,'WebGUI::Asset::Wobject::Collaboration'); + my $threads = $cs->getLineage(['children'],{includeOnlyClasses => ['WebGUI::Asset::Post::Thread']}); + push(@llist,$csid) if (scalar(@{$threads}) > 0); + } + $lineage = \@llist; + + unless ( scalar(@{$lineage}) ) { + $session->errorHandler->warn('Error: no Collaboration Systems found have any threads to display.'.$session->asset->get('url')); + return ''; + } + # Try to get a random thread that the user can see: my $randomThread = _getRandomThread($session, $lineage);