diff --git a/docs/upgrades/upgrade_7.9.4-7.9.5.pl b/docs/upgrades/upgrade_7.9.4-7.9.5.pl
index 56cfae539..52e1d2faa 100644
--- a/docs/upgrades/upgrade_7.9.4-7.9.5.pl
+++ b/docs/upgrades/upgrade_7.9.4-7.9.5.pl
@@ -31,10 +31,10 @@ my $quiet; # this line required
my $session = start(); # this line required
# upgrade functions go here
+modifySortItems();
finish($session); # this line required
-
#----------------------------------------------------------------------------
# Describe what our function does
#sub exampleFunction {
@@ -44,6 +44,33 @@ finish($session); # this line required
# print "DONE!\n" unless $quiet;
#}
+#----------------------------------------------------------------------------
+# Changes sortItems to a SelectBox
+sub modifySortItems {
+ my $session = shift;
+ print "\tUpdating SyndicatedContent...\n" unless $quiet;
+
+ require WebGUI::Form::SelectBox;
+
+ print "\t\tModifying table...\n" unless $quiet;
+ my $type = WebGUI::Form::SelectBox->getDatabaseFieldType;
+ $session->db->write("ALTER TABLE SyndicatedContent MODIFY sortItems $type");
+
+ print "\t\tConverting old values...\n" unless $quiet;
+ $session->db->write(q{
+ UPDATE SyndicatedContent
+ SET sortItems = 'none'
+ WHERE sortItems <> '1'
+ });
+ $session->db->write(q{
+ UPDATE SyndicatedContent
+ SET sortItems = 'pubDate_des'
+ WHERE sortItems = '1'
+ });
+
+ # and here's our code
+ print "DONE!\n" unless $quiet;
+}
# -------------- DO NOT EDIT BELOW THIS LINE --------------------------------
diff --git a/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm b/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm
index 9b65c9f81..d9ed64724 100644
--- a/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm
+++ b/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm
@@ -109,8 +109,17 @@ sub definition {
},
sortItems => {
tab => 'properties',
- fieldType => 'yesNo',
- defaultValue => 1,
+ fieldType => 'selectBox',
+ options => do {
+ tie my %o, 'Tie::IxHash', (
+ none => $i18n->get('no order'),
+ feed => $i18n->get('feed order'),
+ pubDate_asc => $i18n->get('publication date ascending'),
+ pubDate_des =>
+ $i18n->get('publication date descending'),
+ ); \%o;
+ },
+ defaultValue => 'none',
label => $i18n->get('sortItemsLabel'),
hoverHelp => $i18n->get('sortItemsLabel description'),
},
@@ -136,10 +145,13 @@ Combines all feeds into a single XML::FeedPP object.
=cut
sub generateFeed {
- my $self = shift;
+ my $self = shift;
my $limit = shift || $self->get('maxHeadlines');
- my $feed = XML::FeedPP::Atom->new();
- my $log = $self->session->log;
+ my $log = $self->session->log;
+ my $sort = $self->get('sortItems');
+
+ my @opt = (use_ixhash => 1) if $sort eq 'feed';
+ my $feed = XML::FeedPP::Atom->new(@opt);
# build one feed out of many
my $newlyCached = 0;
@@ -160,7 +172,7 @@ sub generateFeed {
# care of any encoding specified in the XML prolog
utf8::downgrade($value, 1);
eval {
- my $singleFeed = XML::FeedPP->new($value, utf8_flag => 1, -type => 'string');
+ my $singleFeed = XML::FeedPP->new($value, utf8_flag => 1, -type => 'string', @opt);
$feed->merge_channel($singleFeed);
$feed->merge_item($singleFeed);
};
@@ -192,9 +204,14 @@ sub generateFeed {
}
# sort them by date and remove any duplicate from the OR based term matching above
- if ($self->get('sortItems')) {
+ if ($sort =~ /^pubDate/) {
$feed->sort_item();
}
+ if ($sort =~ /_asc$/) {
+ my @items = $feed->get_item;
+ $feed->clear_item;
+ $feed->add_item($_) for (reverse @items);
+ }
# limit the feed to the maximum number of headlines (or the feed generator limit).
$feed->limit_item($limit);
diff --git a/lib/WebGUI/i18n/English/Asset_SyndicatedContent.pm b/lib/WebGUI/i18n/English/Asset_SyndicatedContent.pm
index e12422299..2633ce226 100644
--- a/lib/WebGUI/i18n/English/Asset_SyndicatedContent.pm
+++ b/lib/WebGUI/i18n/English/Asset_SyndicatedContent.pm
@@ -245,11 +245,33 @@ our $I18N = {
},
'sortItemsLabel' => {
- message => q{Sort feed items by date?},
+ message => q{Sort items by},
},
'sortItemsLabel description' => {
- message => q{If enabled, items will be sorted by date. If disabled, items will be left in the order they appear in the original feed.},
+ message => q{No order: items will be in semi-random order
+Publication Date: sort by item pubDate
+Feed Order: Items will be in the order they appeared in the feed}
+ },
+
+ 'no order' => {
+ message => 'No Order',
+ context => 'name for the sortItems value that indicates that no sorting should be done '
+ },
+
+ 'feed order' => {
+ message => 'Feed Order',
+ context => 'name for the sortItems value that indicates items should be in the order they appeared in the feed'
+ },
+
+ 'publication date ascending' => {
+ message => 'Publication Date (oldest first)',
+ context => 'name for the sortItems value that indicates items should be sorted by publication date from oldest to newest'
+ },
+
+ 'publication date descending' => {
+ message => 'Publication Date (newest first)',
+ context => 'name for the sortItems value that indicates items should be sorted by publication date from newest to oldest'
},
'syndicated content asset template variables title' => {
diff --git a/t/Asset/Wobject/SyndicatedContent.t b/t/Asset/Wobject/SyndicatedContent.t
index 84fb34d2d..c4eafdb40 100644
--- a/t/Asset/Wobject/SyndicatedContent.t
+++ b/t/Asset/Wobject/SyndicatedContent.t
@@ -20,7 +20,7 @@ use Data::Dumper;
use WebGUI::Test;
use WebGUI::Session;
-use Test::More tests => 22; # increment this value for each test you create
+use Test::More tests => 25; # increment this value for each test you create
use Test::Deep;
use WebGUI::Asset::Wobject::SyndicatedContent;
use XML::FeedPP;
@@ -147,32 +147,40 @@ ok( defined $vars->{item_loop}->[0]->{description}, 'getTemplateVariables: descr
#
####################################################################
-my $tbbUrl = 'http://www.plainblack.com/tbb.rss';
-$syndicated_content->update({
- rssUrl => $tbbUrl,
- hasTerms => 'WebGUI',
-});
+sub withCachedFeed {
+ my ($url, $path, $block) = @_;
+ $syndicated_content->update({ rssUrl => $url });
-my $cache = WebGUI::Cache->new($session, $tbbUrl, 'RSS');
-open my $rssFile, '<', WebGUI::Test->getTestCollateralPath('tbb.rss')
- or die "Unable to get RSS file";
-my $rssContent = do { local $/; <$rssFile>; };
-close $rssFile;
-$cache->set($rssContent, 60);
+ open my $file, '<', WebGUI::Test->getTestCollateralPath($path)
+ or die "Unable to get RSS file: $path";
+ my $content = do { local $/; <$file> };
+ close $file;
-my $filteredFeed = $syndicated_content->generateFeed();
+ my $cache = WebGUI::Cache->new($session, $url, 'RSS');
+ $cache->set($content, 60);
+ $block->();
+ $cache->delete;
+}
-cmp_deeply(
- [ map { $_->title } $filteredFeed->get_item() ],
- [
- 'Google Picasa Plugin for WebGUI Gallery',
- 'WebGUI Roadmap',
- 'WebGUI 8 Performance',
- ],
- 'generateFeed: filters items based on the terms being in title, or description'
-);
+sub titles_are {
+ my ($expected, $message) = @_;
+ my $feed = $syndicated_content->generateFeed;
+ my @got = map { $_->title } $feed->get_item;
+ cmp_deeply \@got, $expected, $message;
+}
-$cache->delete;
+$syndicated_content->update({ hasTerms => 'WebGUI' });
+
+withCachedFeed 'http://www.plainblack.com/tbb.rss', 'tbb.rss', sub {
+ titles_are(
+ [
+ 'Google Picasa Plugin for WebGUI Gallery',
+ 'WebGUI Roadmap',
+ 'WebGUI 8 Performance',
+ ],
+ 'generateFeed: filters items based on the terms being in title, or description'
+ );
+};
####################################################################
#
@@ -180,27 +188,47 @@ $cache->delete;
#
####################################################################
-
##Feed with no links or pubDates.
-my $oncpUrl = 'http://www.oncp.gob.ve/oncp.xml';
$syndicated_content->update({
- rssUrl => $oncpUrl,
hasTerms => '',
maxHeadlines => 50,
});
-my $cache = WebGUI::Cache->new($session, $oncpUrl, 'RSS');
-open my $rssFile, '<', WebGUI::Test->getTestCollateralPath('oncp.xml')
- or die "Unable to get RSS file: oncp.xml";
-my $rssContent = do { local $/; <$rssFile>; };
-close $rssFile;
-$cache->set($rssContent, 60);
+withCachedFeed 'http://www.oncp.gob.ve/oncp.xml', 'oncp.xml', sub {
+ my $oddFeed1 = $syndicated_content->generateFeed();
-my $oddFeed1 = $syndicated_content->generateFeed();
+ my @oddItems = $oddFeed1->get_item();
+ is (@oddItems, 13, 'feed has items even without pubDates or links');
+};
-my @oddItems = $oddFeed1->get_item();
-is (@oddItems, 13, 'feed has items even without pubDates or links');
-
-$cache->delete;
+####################################################################
+#
+# sorting
+#
+####################################################################
+withCachedFeed 'http://www.plainblack.com/tbb.rss', 'tbb_odd.rss', sub {
+ my @ascending = (
+ 'I have arrived in Lisboa!',
+ 'WebGUI 8 Performance',
+ 'WebGUI Roadmap',
+ 'Google Picasa Plugin for WebGUI Gallery',
+ );
+ my @descending = reverse @ascending;
+ my @feed = (
+ 'WebGUI Roadmap',
+ 'Google Picasa Plugin for WebGUI Gallery',
+ 'I have arrived in Lisboa!',
+ 'WebGUI 8 Performance',
+ );
+
+ $syndicated_content->update({ sortItems => 'pubDate_asc' });
+ titles_are \@ascending, 'ascending sort';
+
+ $syndicated_content->update({ sortItems => 'pubDate_des' });
+ titles_are \@descending, 'descending sort';
+
+ $syndicated_content->update({ sortItems => 'feed' });
+ titles_are \@feed, 'feed order';
+};
diff --git a/t/supporting_collateral/tbb_odd.rss b/t/supporting_collateral/tbb_odd.rss
new file mode 100644
index 000000000..9d7515f5e
--- /dev/null
+++ b/t/supporting_collateral/tbb_odd.rss
@@ -0,0 +1,66 @@
+
+
+
+ The Black Blog
+ /tbb
+
+ Mon, 12 Oct 2009 11:54:28 -0500
+
+
+ WebGUI Roadmap
+ http://www.plainblack.com/tbb/webgui-roadmap
+ JT
+ 1254325377
+ http://www.plainblack.com/tbb/webgui-roadmap
+ Wed, 30 Sep 2009 10:42:57 -0500
+
+
+
+
+
+ The new roadmap is online.
+
+
+ Google Picasa Plugin for WebGUI Gallery
+ http://www.plainblack.com/tbb/google-picasa-plugin-for-webgui-gallery
+ JT
+ 1254854387
+ http://www.plainblack.com/tbb/google-picasa-plugin-for-webgui-gallery
+ Tue, 06 Oct 2009 13:39:47 -0500
+
+
+
+
+
+ Today we unveil the Google Picasa plugin for WebGUI Gallery.
+
+
+ I have arrived in Lisboa!
+ http://www.plainblack.com/tbb/i-have-arrived-in-lisboa
+ JT
+ 1249140064
+ http://www.plainblack.com/tbb/i-have-arrived-in-lisboa
+ Sat, 01 Aug 2009 10:21:04 -0500
+
+
+
+
+
+ I'm in Lisbon, Portugal for YAPC::EU.
+
+
+ WebGUI 8 Performance
+ http://www.plainblack.com/tbb/webgui-8-performance
+ JT
+ 1254236976
+ http://www.plainblack.com/tbb/webgui-8-performance
+ Tue, 29 Sep 2009 10:09:36 -0500
+
+
+
+
+
+ WebGUI 8 is going to be the fastest version of WebGUI ever released.
+
+
+