From 8b071cb8921aa6d089f2865d1a9f7197385af4a5 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 23 Mar 2009 15:08:54 +0000 Subject: [PATCH] Add template variables for determining if a story has photos, and how many it has. Tests, help, i18n. --- lib/WebGUI/Asset/Story.pm | 9 +++++++-- lib/WebGUI/Help/Asset_Story.pm | 2 ++ lib/WebGUI/i18n/English/Asset_Story.pm | 18 ++++++++++++++++++ t/Asset/Story.t | 8 +++++++- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/lib/WebGUI/Asset/Story.pm b/lib/WebGUI/Asset/Story.pm index 9a514a0f2..c298cdb5d 100644 --- a/lib/WebGUI/Asset/Story.pm +++ b/lib/WebGUI/Asset/Story.pm @@ -763,8 +763,10 @@ sub viewTemplateVariables { $var->{updatedTimeEpoch} = $self->get('revisionDate'); $var->{crumb_loop} = $self->getCrumbTrail(); + my $photoData = $self->getPhotoData; $var->{photo_loop} = []; - PHOTO: foreach my $photo (@{ $self->getPhotoData}) { + my $photoCounter = 0; + PHOTO: foreach my $photo (@{ $photoData }) { next PHOTO unless $photo->{storageId}; my $storage = WebGUI::Storage->get($session, $photo->{storageId}); my $file = $storage->getFiles->[0]; @@ -777,8 +779,11 @@ sub viewTemplateVariables { imageAlt => $photo->{alt}, imageTitle => $photo->{title}, imageLink => $photo->{url}, - } + }; + ++$photoCounter; } + $var->{hasPhotos} = $photoCounter; + $var->{singlePhoto} = $photoCounter == 1; return $var; } diff --git a/lib/WebGUI/Help/Asset_Story.pm b/lib/WebGUI/Help/Asset_Story.pm index 6652e1747..d6f8bf6fa 100644 --- a/lib/WebGUI/Help/Asset_Story.pm +++ b/lib/WebGUI/Help/Asset_Story.pm @@ -80,6 +80,8 @@ our $HELP = { }, ], }, + { name => 'hasPhotos', }, + { name => 'singlePhoto', }, { name => 'photo_loop', 'variables' => [ { name => 'imageUrl', }, diff --git a/lib/WebGUI/i18n/English/Asset_Story.pm b/lib/WebGUI/i18n/English/Asset_Story.pm index 96d929d69..05105409c 100644 --- a/lib/WebGUI/i18n/English/Asset_Story.pm +++ b/lib/WebGUI/i18n/English/Asset_Story.pm @@ -428,6 +428,24 @@ our $I18N = { lastUpdated => 0, }, + 'hasPhotos' => { + message => q|This template variable will be true if the Story has photos uploaded to it.|, + context => q|Template variable|, + lastUpdated => 0, + }, + + 'singlePhoto' => { + message => q|This template variable will be true if the Story has just 1 photo uploaded to it.|, + context => q|Template variable|, + lastUpdated => 0, + }, + + 'imageLink' => { + message => q|A URL for the image to link to.|, + context => q|Template variable|, + lastUpdated => 0, + }, + }; 1; diff --git a/t/Asset/Story.t b/t/Asset/Story.t index fab9bc2c3..8257333bc 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 => 28 +plan tests => 32 + $tests ; @@ -285,6 +285,9 @@ cmp_deeply( 'viewTemplateVariables: photo_loop is okay' ); +ok(! $viewVariables->{singlePhoto}, 'viewVariables: singlePhoto: there is more than 1'); +ok( $viewVariables->{hasPhotos}, 'viewVariables: hasPhotos: it has photos'); + ##Simulate someone deleting the file stored in the storage object. $storage2->deleteFile('lamp.jpg'); $viewVariables = $story->viewTemplateVariables; @@ -304,6 +307,9 @@ cmp_deeply( 'viewTemplateVariables: photo_loop: if the storage has no files, it is not shown' ); +ok($viewVariables->{singlePhoto}, 'viewVariables: singlePhoto: there is just 1'); +ok($viewVariables->{hasPhotos}, 'viewVariables: hasPhotos: it has photos'); + } END {