From f2451e2f7e5e27a44fca721911ae8d73a360e146 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Wed, 22 Apr 2009 04:59:23 +0000 Subject: [PATCH] Add feed support to StoryTopic. --- lib/WebGUI/Asset/Wobject/StoryTopic.pm | 28 ++++++++++++++++++ t/Asset/Wobject/StoryTopic.t | 39 +++++++++++++++++++++++++- 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/lib/WebGUI/Asset/Wobject/StoryTopic.pm b/lib/WebGUI/Asset/Wobject/StoryTopic.pm index 4d84d0438..3edc29f37 100644 --- a/lib/WebGUI/Asset/Wobject/StoryTopic.pm +++ b/lib/WebGUI/Asset/Wobject/StoryTopic.pm @@ -103,6 +103,34 @@ sub exportHtml_view { #------------------------------------------------------------------- +=head2 getRssFeedItems ( ) + +Returns an arrayref of hashrefs, containing information on stories +for generating an RSS and Atom feeds. + +=cut + +sub getRssFeedItems { + my ($self) = @_; + my $session = $self->session; + my $wordList = WebGUI::Keyword::string2list($self->get('keywords')); + my $key = WebGUI::Keyword->new($session); + my $storyIds = $key->getMatchingAssets({ + keywords => $wordList, + isa => 'WebGUI::Asset::Story', + rowsPerPage => $self->get('storiesPer'), + }); + my $storyData = []; + STORY: foreach my $storyId (@{ $storyIds }) { + my $story = WebGUI::Asset->newByDynamicClass($session, $storyId); + next STORY unless $story; + push @{ $storyData }, $story->getRssData; + } + return $storyData; +} + +#------------------------------------------------------------------- + =head2 prepareView ( ) See WebGUI::Asset::prepareView() for details. diff --git a/t/Asset/Wobject/StoryTopic.t b/t/Asset/Wobject/StoryTopic.t index ec4b4887c..2f396941e 100644 --- a/t/Asset/Wobject/StoryTopic.t +++ b/t/Asset/Wobject/StoryTopic.t @@ -31,7 +31,7 @@ my $session = WebGUI::Test->session; #---------------------------------------------------------------------------- # Tests -my $tests = 17; +my $tests = 18; plan tests => 1 + $tests; #---------------------------------------------------------------------------- @@ -273,6 +273,43 @@ cmp_deeply( ); $topic->{_exportMode} = 0; +################################################################ +# +# getRssFeedItems +# +################################################################ + +$topic->update({ + storiesPer => 3, +}); +cmp_deeply( + $topic->getRssFeedItems(), + [ + { + title => 'bogs', + description => ignore(), + 'link' => ignore(), + date => ignore(), + author => ignore(), + }, + { + title => 'red', + description => ignore(), + 'link' => ignore(), + date => ignore(), + author => ignore(), + }, + { + title => 'brooks', + description => ignore(), + 'link' => ignore(), + date => ignore(), + author => ignore(), + }, + ], + 'rssFeedItems' +); + } #----------------------------------------------------------------------------