Skip to content

Commit

Permalink
StoryTopics 'Alphabetically' sort order option.
Browse files Browse the repository at this point in the history
  • Loading branch information
scottwalters committed Jul 27, 2010
1 parent c92d182 commit 8a40859
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 9 deletions.
1 change: 1 addition & 0 deletions docs/changelog/7.x.x.txt
Expand Up @@ -5,6 +5,7 @@
- fixed #11741: i18n Asset_Carousel ::carousel slideHeight description
- fixed #11742: linktag FilePump macro not xhtml valid
- fixed #11744: Default DataForm list template does not contain pagination
- added option for sort order of Alphabetically on title to StoryArchive, StoryTopic and Keyword

7.9.9
- fixed #11693: Shopping cart does not show for visitor user
Expand Down
19 changes: 19 additions & 0 deletions docs/upgrades/upgrade_7.9.9-7.9.10.pl
Expand Up @@ -33,6 +33,7 @@ BEGIN
# upgrade functions go here
addSpamStopWordsToConfig($session);
alterStoryArchiveTable($session);
alterStoryTopicTable($session);

finish($session); # this line required

Expand Down Expand Up @@ -74,6 +75,24 @@ sub alterStoryArchiveTable {
print "DONE!\n" unless $quiet;
}

#----------------------------------------------------------------------------
# Describe what our function does
sub alterStoryTopicTable {
my $session = shift;
print "\tAdd story sort order column to the StoryTopic table... " unless $quiet;

my $sth = $session->db->read('DESCRIBE `StoryTopic`');
while (my ($col) = $sth->array) {
if ($col eq 'storySortOrder') {
print "Skipped.\n" unless $quiet;
return;
}
}

$session->db->write("ALTER TABLE StoryTopic ADD COLUMN storySortOrder CHAR(22)");
$session->db->write("UPDATE StoryTopic SET storySortOrder = 'Chronologically' WHERE storySortOrder IS NULL");
print "DONE!\n" unless $quiet;
}

# -------------- DO NOT EDIT BELOW THIS LINE --------------------------------

Expand Down
21 changes: 17 additions & 4 deletions lib/WebGUI/Asset/Wobject/StoryTopic.pm
Expand Up @@ -37,6 +37,7 @@ sub definition {
my $session = shift;
my $definition = shift;
my $i18n = WebGUI::International->new($session, 'Asset_StoryTopic');
my $other_i18n = WebGUI::International->new($session, 'Asset_StoryArchive');
my %properties;
tie %properties, 'Tie::IxHash';
%properties = (
Expand Down Expand Up @@ -72,6 +73,17 @@ sub definition {
namespace => 'Story',
defaultValue => 'TbDcVLbbznPi0I0rxQf2CQ',
},
storySortOrder => {
fieldType => "selectBox",
tab => 'display',
defaultValue => 'Chronologically',
options => {
Alphabetically => $other_i18n->get('alphabetically'),
Chronologically => $other_i18n->get('chronologically')
},
label => $other_i18n->get('sortAlphabeticallyChronologically'),
hoverHelp => $other_i18n->get('sortAlphabeticallyChronologically description'),
},
);
push(@{$definition}, {
assetName=>$i18n->get('assetName'),
Expand Down Expand Up @@ -174,10 +186,11 @@ sub viewTemplateVariables {
my $wordList = WebGUI::Keyword::string2list($self->get('keywords'));
my $key = WebGUI::Keyword->new($session);
my $p = $key->getMatchingAssets({
keywords => $wordList,
isa => 'WebGUI::Asset::Story',
usePaginator => 1,
rowsPerPage => $numberOfStories,
sortOrder => $self->get('storySortOrder') || 'Chronologically',
keywords => $wordList,
isa => 'WebGUI::Asset::Story',
usePaginator => 1,
rowsPerPage => $numberOfStories,
});
my $storyIds = $p->getPageData();
$var->{story_loop} = [];
Expand Down
13 changes: 11 additions & 2 deletions lib/WebGUI/Keyword.pm
Expand Up @@ -367,9 +367,18 @@ sub getMatchingAssets {
push @clauses, 'keyword in ('.join(',', @placeholders).')';
}

my $sortOrder = $options->{sortOrder} || 'Chronologically';

my $orderBy = $sortOrder eq 'Alphabetically' ? ' order by upper(title), lineage' : ' order by creationDate desc, lineage';

# write the query
my $query = 'select distinct assetKeyword.assetId from assetKeyword left join asset using (assetId)
where '.join(' and ', @clauses).' order by creationDate desc, lineage';
my $query = q{
select distinct assetKeyword.assetId
from assetKeyword
left join asset using (assetId)
left join assetData using (assetId)
where } .
join(' and ', @clauses) . $orderBy;

# perform the search
if ($options->{usePaginator}) {
Expand Down
43 changes: 42 additions & 1 deletion t/Asset/Wobject/StoryTopic.t
Expand Up @@ -31,7 +31,7 @@ my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests

plan tests => 18;
plan tests => 19;

#----------------------------------------------------------------------------
# put your tests here
Expand Down Expand Up @@ -316,3 +316,44 @@ cmp_deeply(
],
'rssFeedItems'
);

################################################################
# Sort Order
################################################################

$pastStory->update( { title => "aaaay was history but isn't any more" } );
$pastStory->requestAutoCommit;

$topic->update({ storiesPer => 4, storiesShort => 4, }); $ storiesPer is used when _standAlone is true, storiesShort otherwise
$topic->{_standAlone} = 0;
$topic->update( { storySortOrder => 'Alphabetically' } );

$templateVars = $topic->viewTemplateVariables();

cmp_deeply(
$templateVars->{story_loop},
[
{
title => "aaaay was history but isn't any more",
url => ignore(),
creationDate => $yesterday,
},
{
title => 'andy',
url => ignore(),
creationDate => $now,
},
{
title => 'bogs',
url => ignore(),
creationDate => $now,
},
{
title => 'brooks',
url => ignore(),
creationDate => $now,
},
],
'viewTemplateVars has right number and contents in the story_loop in sort order Alphabetically mode'
);

17 changes: 15 additions & 2 deletions t/Keyword.t
Expand Up @@ -17,7 +17,7 @@ use WebGUI::Keyword;
use WebGUI::Asset;
# load your modules here

use Test::More tests => 15; # increment this value for each test you create
use Test::More tests => 16; # increment this value for each test you create
use Test::Deep;
use Data::Dumper;

Expand Down Expand Up @@ -76,10 +76,23 @@ my $assetIds = $keyword->getMatchingAssets({ keyword => 'webgui', });

cmp_deeply(
$assetIds,
[$snippet->getId, $home->getId, ],
[ $snippet->getId, $home->getId, ],
'getMatchingAssets, by keyword, assetIds in order by creationDate, descending'
);

# sorted by title, alphabetically

$home->update( { title => 'aaaa' } );
$home->commit;

$assetIds = $keyword->getMatchingAssets({ keyword => 'webgui', sortOrder => 'Alphabetically', });

cmp_deeply(
$assetIds,
[ $home->getId, $snippet->getId, ],
'getMatchingAssets, by keyword, assetIds in order by title'
);

$snippet->trash();

cmp_deeply(
Expand Down

0 comments on commit 8a40859

Please sign in to comment.