diff --git a/lib/WebGUI/Asset/Story.pm b/lib/WebGUI/Asset/Story.pm index 6eea89d40..666ca8311 100644 --- a/lib/WebGUI/Asset/Story.pm +++ b/lib/WebGUI/Asset/Story.pm @@ -257,6 +257,40 @@ sub getAutoCommitWorkflowId { } +#------------------------------------------------------------------- + +=head2 getCrumbTrail ( ) + +Returns the crumb trail for this Story. If rendered from inside +a Topic, it will insert the Topic information into the crumb trail. + +The crumb trail will be a loop of variables, in order from this Story's +StoryArchive, the topic, if present, and then this story. + +=cut + +sub getCrumbTrail { + my $self = shift; + my $crumb_loop = []; + my $archive = $self->getArchive; + push @{ $crumb_loop }, { + title => $archive->getTitle, + url => $archive->getUrl, + }; + my $topic = $self->topic; + if ($topic) { + push @{ $crumb_loop }, { + title => $topic->getTitle, + url => $topic->getUrl, + }; + } + push @{ $crumb_loop }, { + title => $self->getTitle, + url => $self->getUrl, + }; + return $crumb_loop; +} + #------------------------------------------------------------------- =head2 getEditForm ( ) @@ -397,7 +431,6 @@ sub prepareView { my $self = shift; my $templateId = shift || $self->getArchive->get('storyTemplateId'); $self->SUPER::prepareView(); - $self->session->log->warn("storyTemplateId: $templateId"); my $template = WebGUI::Asset::Template->new($self->session, $templateId); $template->prepare; $self->{_viewTemplate} = $template; @@ -430,7 +463,8 @@ Cleaning up storage objects in all revisions. sub purge { my $self = shift; - my $sth = $self->session->db->read("select storageId from Story where assetId=".$self->session->db->quote($self->getId)); + ##Delete all storage locations from all revisions of the Asset + my $sth = $self->session->db->read("select storageId from Story where assetId=?",[$self->getId]); STORAGE: while (my ($storageId) = $sth->array) { next STORAGE unless $storageId; WebGUI::Storage->get($self->session,$storageId)->delete; @@ -552,6 +586,28 @@ sub setStorageLocation { #------------------------------------------------------------------- +=head2 topic ( $topicAsset ) + +Tells the Story that it is being viewed from a Topic, and to behave +accordingly. Returns a StoryTopic asset if set. + +=head3 $topicAsset + +The topic that is displaying this Story. + +=cut + +sub topic { + my $self = shift; + my $topic = shift; + if (defined $topic) { + $self->{_topic} = $topic; + } + return $self->{_topic}; +} + +#------------------------------------------------------------------- + =head2 update Extend the superclass to make sure that the asset always stays hidden from navigation. @@ -646,6 +702,8 @@ Web facing method which is the default edit page. Unless the method needs special handling or formatting, it does not need to be included in the module. +Overridden because the standard, autogenerated form is not used. + =cut sub www_edit { diff --git a/lib/WebGUI/Asset/Wobject/StoryTopic.pm b/lib/WebGUI/Asset/Wobject/StoryTopic.pm index 035f30b7b..6eef76d5d 100644 --- a/lib/WebGUI/Asset/Wobject/StoryTopic.pm +++ b/lib/WebGUI/Asset/Wobject/StoryTopic.pm @@ -120,12 +120,6 @@ sub view { return $self->processTemplate($var, undef, $self->{_viewTemplate}); } -sub www_view { - my $self = shift; - $self->{_standAlone} = 1; - return $self->SUPER::www_view; -} - #------------------------------------------------------------------- =head2 viewTemplateVars ( ) @@ -178,6 +172,48 @@ sub viewTemplateVariables { return $var; } +#------------------------------------------------------------------- + +=head2 www_view ( ) + +Overside the method inherited from Wobject to set the mode so template +variables are set correctly in viewTemplateVars. + +=cut + + +sub www_view { + my $self = shift; + $self->{_standAlone} = 1; + return $self->SUPER::www_view; +} + +#------------------------------------------------------------------- + +=head2 www_viewStory ( ) + +Display a story, set in the form variable assetId + +=cut + + +sub www_viewStory { + my $self = shift; + my $session = $self->session; + my $storyId = $session->form->get('assetId'); + my $story; + if ($storyId) { + $story = WebGUI::Asset->new($session, $storyId); + } + if (! $story) { + my $notFound = WebGUI::Asset->getNotFound($session); + $session->asset($notFound); + return $notFound->www_view; + } + $story->topic($self); + return $story->www_view; +} + 1; #vim:ft=perl diff --git a/t/Asset/Story.t b/t/Asset/Story.t index c363d23fc..70734e1c7 100644 --- a/t/Asset/Story.t +++ b/t/Asset/Story.t @@ -21,7 +21,7 @@ use Test::Deep; use Data::Dumper; my $tests = 1; -plan tests => 25 +plan tests => 27 + $tests ; @@ -32,7 +32,7 @@ my $session = WebGUI::Test->session; my $class = 'WebGUI::Asset::Story'; my $loaded = use_ok($class); my $story; -my $wgBday; +my $wgBday = WebGUI::Test->webguiBirthday; my $defaultNode = WebGUI::Asset->getDefault($session); my $archive = $defaultNode->addChild({ @@ -41,9 +41,17 @@ my $archive = $defaultNode->addChild({ #1234567890123456789012 assetId => 'TestStoryArchiveAsset1', }); -my $archiveTag = WebGUI::VersionTag->getWorking($session); +my $topic = $defaultNode->addChild({ + className => 'WebGUI::Asset::Wobject::StoryTopic', + title => 'Test Topic', + #1234567890123456789012 + assetId => 'TestStoryTopicAsset123', + keywords => 'tango yankee', +}); +my $archiveTag = WebGUI::VersionTag->getWorking($session); $archiveTag->commit; + SKIP: { skip "Unable to load module $class", $tests unless $loaded; @@ -144,11 +152,55 @@ cmp_deeply( is($story->formatDuration(time() - (24*3600+15)), '1 Day(s)', 'formatDuration, 1 day'); is($story->formatDuration(time() - (48*3600+15)), '2 Day(s)', 'formatDuration, 2 day'); -like($story->formatDuration(997966800), qr{Year.s.}, 'formatDuration: a long time ago'); +like($story->formatDuration($wgBday), qr{Year.s.}, 'formatDuration: a long time ago'); is($story->formatDuration(time() - (3600+5)), '1 Hour(s)', 'formatDuration: 1 hour'); is($story->formatDuration(time() - (60+5)), '1 Minute(s)', 'formatDuration: 1 minute'); is($story->formatDuration(time() - (7200+120)), '2 Hour(s), 2 Minute(s)', 'formatDuration: 2 hours, 2 minutes'); +############################################################ +# +# getCrumbTrail +# +############################################################ + +cmp_deeply( + $story->getCrumbTrail, + [ + { + title => $archive->getTitle, + url => $archive->getUrl, + }, + { + title => $story->getTitle, + url => $story->getUrl, + }, + ], + 'getCrumbTrail: with no topic set' +); + +$story->topic($topic); + +cmp_deeply( + $story->getCrumbTrail, + [ + { + title => $archive->getTitle, + url => $archive->getUrl, + }, + { + title => $topic->getTitle, + url => $topic->getUrl, + }, + { + title => $story->getTitle, + url => $story->getUrl, + }, + ], + 'getCrumbTrail: with no topic set' +); + +$story->topic(''); + ############################################################ # # viewTemplateVariables @@ -188,8 +240,8 @@ is ($viewVariables->{updatedTimeEpoch}, $story->get('revisionDate'), 'viewTempla END { $story->purge if $story; - $wgBday->purge if $wgBday; $archive->purge if $archive; + $topic->purge if $topic; $archiveTag->rollback; WebGUI::VersionTag->getWorking($session)->rollback; }