Added additional navigation to the photo asset (RFE 11412).

This commit is contained in:
kimd 2010-03-24 22:07:41 +01:00 committed by Doug Bell
parent 5ded2ea89d
commit 8104338da7
10 changed files with 505 additions and 2 deletions

View file

@ -438,6 +438,76 @@ sub getParent {
#----------------------------------------------------------------------------
=head2 getFirstFile ( )
Get the first file in the GalleryAlbum. Returns an instance of a GalleryFile
or undef if there is no first file.
=cut
sub getFirstFile {
my $self = shift;
my $allFileIds = $self->getParent->getFileIds;
return undef unless @{ $allFileIds };
return WebGUI::Asset->newByDynamicClass( $self->session, shift @{ $allFileIds });
}
#----------------------------------------------------------------------------
=head2 getLastFile ( )
Get the last file in the GalleryAlbum. Returns an instance of a GalleryFile
or undef if there is no last file.
=cut
sub getLastFile {
my $self = shift;
my $allFileIds = $self->getParent->getFileIds;
return undef unless @{ $allFileIds };
return WebGUI::Asset->newByDynamicClass( $self->session, pop @{ $allFileIds });
}
#----------------------------------------------------------------------------
=head2 getNextFile ( )
Get the next file in the GalleryAlbum. Returns an instance of a GalleryFile,
or undef if there is no next file.
=cut
sub getNextFile {
my $self = shift;
return $self->{_nextFile} if $self->{_nextFile};
my $nextId = $self->getParent->getNextFileId( $self->getId );
return undef unless $nextId;
$self->{_nextFile} = WebGUI::Asset->newByDynamicClass( $self->session, $nextId );
return $self->{_nextFile};
}
#----------------------------------------------------------------------------
=head2 getPreviousFile ( )
Get the previous file in the GalleryAlbum. Returns an instance of a GalleryFile,
or undef if there is no previous file.
=cut
sub getPreviousFile {
my $self = shift;
return $self->{_previousFile} if $self->{_previousFile};
my $previousId = $self->getParent->getPreviousFileId( $self->getId );
return undef unless $previousId;
$self->{_previousFile} = WebGUI::Asset->newByDynamicClass( $self->session, $previousId );
return $self->{_previousFile};
}
#----------------------------------------------------------------------------
=head2 getThumbnailUrl ( )
Gets the URL to the thumbnail for this GalleryFile. This should probably be
@ -512,10 +582,30 @@ sub getTemplateVars {
= $self->getGallery->getUrl('func=listFilesForUser;userId=' . $self->get("ownerUserId"));
$var->{ url_promote } = $self->getUrl('func=promote');
if ( my $firstFile = $self->getFirstFile ) {
$var->{ firstFile_url } = $firstFile->getUrl;
$var->{ firstFile_title } = $firstFile->get( "title" );
$var->{ firstFile_thumbnailUrl } = $firstFile->getThumbnailUrl;
}
if ( my $nextFile = $self->getNextFile ) {
$var->{ nextFile_url } = $nextFile->getUrl;
$var->{ nextFile_title } = $nextFile->get( "title" );
$var->{ nextFile_thumbnailUrl } = $nextFile->getThumbnailUrl;
}
if ( my $prevFile = $self->getPreviousFile ) {
$var->{ previousFile_url } = $prevFile->getUrl;
$var->{ previousFile_title } = $prevFile->get( "title" );
$var->{ previousFile_thumbnailUrl } = $prevFile->getThumbnailUrl;
}
if ( my $lastFile = $self->getLastFile ) {
$var->{ lastFile_url } = $lastFile->getUrl;
$var->{ lastFile_title } = $lastFile->get( "title" );
$var->{ lastFile_thumbnailUrl } = $lastFile->getThumbnailUrl;
}
return $var;
}
#----------------------------------------------------------------------------
=head2 isFriendsOnly ( )

View file

@ -460,6 +460,58 @@ sub getFileIds {
#----------------------------------------------------------------------------
=head2 getNextFileId ( fileId )
Gets the next fileId from the list of fileIds. C<fileId> is the base
fileId we want to find the next file for.
Returns C<undef> if there is no next fileId.
=cut
sub getNextFileId {
my $self = shift;
my $fileId = shift;
my $allFileIds = $self->getFileIds;
while ( my $checkId = shift @{ $allFileIds } ) {
# If this is the last albumId
return undef unless @{ $allFileIds };
if ( $fileId eq $checkId ) {
return shift @{ $allFileIds };
}
}
}
#----------------------------------------------------------------------------
=head2 getPreviousFileId ( fileId )
Gets the previous fileId from the list of fileIds. C<fileId> is the base
fileId we want to find the previous file for.
Returns C<undef> if there is no previous fileId.
=cut
sub getPreviousFileId {
my $self = shift;
my $fileId = shift;
my $allFileIds = $self->getFileIds;
while ( my $checkId = pop @{ $allFileIds } ) {
# If this is the last albumId
return undef unless @{ $allFileIds };
if ( $fileId eq $checkId ) {
return pop @{ $allFileIds };
}
}
}
#----------------------------------------------------------------------------
=head2 getFilePaginator ( paginatorUrl )
Gets a WebGUI::Paginator for the files in this album. C<paginatorUrl> is the

View file

@ -174,6 +174,54 @@ our $HELP = {
name => 'album_url',
description => 'helpvar album_url',
},
{
name => 'firstFile_url',
description => 'helpvar firstFile_url',
},
{
name => 'firstFile_title',
description => 'helpvar firstFile_title',
},
{
name => 'firstFile_thumbnailUrl',
description => 'helpvar firstFile_thumbnailUrl',
},
{
name => 'nextFile_url',
description => 'helpvar nextFile_url',
},
{
name => 'nextFile_title',
description => 'helpvar nextFile_title',
},
{
name => 'nextFile_thumbnailUrl',
description => 'helpvar nextFile_thumbnailUrl',
},
{
name => 'previousFile_url',
description => 'helpvar previousFile_url',
},
{
name => 'previousFile_title',
description => 'helpvar previousFile_title',
},
{
name => 'previousFile_thumbnailUrl',
description => 'helpvar previousFile_thumbnailUrl',
},
{
name => 'lastFile_url',
description => 'helpvar lastFile_url',
},
{
name => 'lastFile_title',
description => 'helpvar lastFile_title',
},
{
name => 'lastFile_thumbnailUrl',
description => 'helpvar lastFile_thumbnailUrl',
},
],
},

View file

@ -307,6 +307,66 @@ our $I18N = {
lastUpdated => 0,
},
'helpvar firstFile_url' => {
message => 'The URL of the first file in the album.',
lastUpdated => 0,
},
'helpvar firstFile_title' => {
message => 'The title of the first file in the album.',
lastUpdated => 0,
},
'helpvar firstFile_thumbnailUrl' => {
message => 'The URL of the thumbnail of the first file in the album.',
lastUpdated => 0,
},
'helpvar nextFile_url' => {
message => 'The URL of the next file in the album. Undefined if no next file.',
lastUpdated => 0,
},
'helpvar nextFile_title' => {
message => 'The title of the next file in the album. Undefined if no next file.',
lastUpdated => 0,
},
'helpvar nextFile_thumbnailUrl' => {
message => 'The URL of the thumbnail of the next file in the album. Undefined if no next file.',
lastUpdated => 0,
},
'helpvar previousFile_url' => {
message => 'The URL of the previous file in the album. Undefined if no previous file.',
lastUpdated => 0,
},
'helpvar previousFile_title' => {
message => 'The title of the previous file in the album. Undefined if no previous file.',
lastUpdated => 0,
},
'helpvar previousFile_thumbnailUrl' => {
message => 'The URL of the thumbnail of the previous file in the album. Undefined if no previous file.',
lastUpdated => 0,
},
'helpvar lastFile_url' => {
message => 'The URL of the last file in the album.',
lastUpdated => 0,
},
'helpvar lastFile_title' => {
message => 'The title of the last file in the album.',
lastUpdated => 0,
},
'helpvar lastFile_thumbnailUrl' => {
message => 'The URL of the thumbnail of the last file in the album.',
lastUpdated => 0,
},
'template view title' => {
message => 'Photo Details',
lastUpdated => 0,

View file

@ -0,0 +1,111 @@
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use FindBin;
use strict;
use lib "$FindBin::Bin/../../../../lib";
## The goal of this test is to test the creation and deletion of photo assets
use WebGUI::Test;
use WebGUI::Session;
use Test::More;
#----------------------------------------------------------------------------
# Init
my $session = WebGUI::Test->session;
my $node = WebGUI::Asset->getImportNode($session);
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->set({name=>"Photo Test"});
# Create gallery and a single album
my $gallery
= $node->addChild({
className => "WebGUI::Asset::Wobject::Gallery",
},
undef,
undef,
{
skipAutoCommitWorkflows => 1,
});
my $album
= $gallery->addChild({
className => "WebGUI::Asset::Wobject::GalleryAlbum",
},
undef,
undef,
{
skipAutoCommitWorkflows => 1,
});
# Create 5 photos inside the gallery
my @photo;
for (my $i = 0; $i < 5; $i++)
{
$photo[$i]
= $album->addChild({
className => "WebGUI::Asset::File::GalleryFile::Photo",
},
undef,
undef,
{
skipAutoCommitWorkflows => 1,
});
}
# Commit all changes
$versionTag->commit;
#----------------------------------------------------------------------------
# Tests
plan tests => 11;
#----------------------------------------------------------------------------
# Test module compiles okay
# plan tests => 1
use_ok("WebGUI::Asset::File::GalleryFile::Photo");
#----------------------------------------------------------------------------
# Test getFirstFile method
diag('getFirstFile');
is( $photo[2]->getFirstFile->getId, $photo[0]->getId, 'First file is photo no. 1' );
is( $photo[0]->getFirstFile->getId, $photo[0]->getId, 'First file is still photo no. 1' );
#----------------------------------------------------------------------------
# Test getFirstFile method
diag('getLastFile');
is( $photo[2]->getLastFile->getId, $photo[4]->getId, 'Last file is photo no. 5' );
is( $photo[4]->getLastFile->getId, $photo[4]->getId, 'Last file is still photo no. 5' );
#----------------------------------------------------------------------------
# Test getPreviousFile method
diag('getPreviousFile');
is( $photo[2]->getPreviousFile->getId, $photo[1]->getId, 'Photo previous of photo no. 3 is photo no. 2' );
is( $photo[1]->getPreviousFile->getId, $photo[0]->getId, 'Photo previous of photo no. 2 is photo no. 1' );
is( $photo[0]->getPreviousFile, undef, 'Photo previous of photo no. 1 is undef' );
#----------------------------------------------------------------------------
# Test getNextFile method
diag('getNextFile');
is( $photo[2]->getNextFile->getId, $photo[3]->getId, 'Photo next of photo no. 3 is photo no. 4' );
is( $photo[3]->getNextFile->getId, $photo[4]->getId, 'Photo next of photo no. 4 is photo no. 5' );
is( $photo[4]->getNextFile, undef, 'Photo next of photo no. 5 is undef' );
#----------------------------------------------------------------------------
# Cleanup
END {
$versionTag->rollback;
}

View file

@ -42,6 +42,16 @@ my $album
{
skipAutoCommitWorkflows => 1,
});
my $previousPhoto
= $album->addChild({
className => "WebGUI::Asset::File::GalleryFile::Photo",
ownerUserId => 3,
},
undef,
undef,
{
skipAutoCommitWorkflows => 1,
});
my $photo
= $album->addChild({
className => "WebGUI::Asset::File::GalleryFile::Photo",
@ -52,6 +62,16 @@ my $photo
{
skipAutoCommitWorkflows => 1,
});
my $nextPhoto
= $album->addChild({
className => "WebGUI::Asset::File::GalleryFile::Photo",
ownerUserId => 3,
},
undef,
undef,
{
skipAutoCommitWorkflows => 1,
});
$versionTag->commit;
$photo->setFile( WebGUI::Test->getTestCollateralPath('page_title.jpg') );
@ -87,7 +107,23 @@ my $testTemplateVars = {
numberOfComments => scalar @{ $photo->getCommentIds },
exifLoop => ignore(), # Tested elsewhere
isPending => ( $photo->get("status") eq "pending" ),
firstFile_url => $previousPhoto->getUrl,
firstFile_thumbnailUrl
=> $previousPhoto->getThumbnailUrl,
firstFile_title => $previousPhoto->get("title"),
previousFile_url => $previousPhoto->getUrl,
previousFile_thumbnailUrl
=> $previousPhoto->getThumbnailUrl,
previousFile_title => $previousPhoto->get("title"),
nextFile_url => $nextPhoto->getUrl,
nextFile_thumbnailUrl
=> $nextPhoto->getThumbnailUrl,
nextFile_title => $nextPhoto->get("title"),
firstFile_title => $previousPhoto->get("title"),
lastFile_url => $nextPhoto->getUrl,
lastFile_thumbnailUrl
=> $nextPhoto->getThumbnailUrl,
lastFile_title => $nextPhoto->get("title"),
};
# Ignore all EXIF tags, they're tested in exif.t

View file

@ -0,0 +1,106 @@
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use FindBin;
use strict;
use lib "$FindBin::Bin/../../../lib";
## The goal of this test is to test the creation and deletion of album assets
use WebGUI::Test;
use WebGUI::Session;
use Test::More;
#----------------------------------------------------------------------------
# Init
my $session = WebGUI::Test->session;
my $node = WebGUI::Asset->getImportNode($session);
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->set({name=>"Album Test"});
# Create gallery and a single album
my $gallery
= $node->addChild({
className => "WebGUI::Asset::Wobject::Gallery",
},
undef,
undef,
{
skipAutoCommitWorkflows => 1,
});
my $album
= $gallery->addChild({
className => "WebGUI::Asset::Wobject::GalleryAlbum",
},
undef,
undef,
{
skipAutoCommitWorkflows => 1,
});
# Create 5 photos inside the gallery
my @photo;
for (my $i = 0; $i < 5; $i++)
{
$photo[$i]
= $album->addChild({
className => "WebGUI::Asset::File::GalleryFile::Photo",
},
undef,
undef,
{
skipAutoCommitWorkflows => 1,
});
}
# Commit all changes
$versionTag->commit;
#----------------------------------------------------------------------------
# Tests
plan tests => 15;
#----------------------------------------------------------------------------
# Test module compiles okay
use_ok("WebGUI::Asset::Wobject::GalleryAlbum");
#----------------------------------------------------------------------------
# Test getPreviousFileId
diag('getPreviousFileId');
is( $album->getPreviousFileId($photo[2]->getId), $photo[1]->getId, 'Id of photo previous of photo no. 3 equals id of photo no. 2' );
is( $album->getPreviousFileId($photo[1]->getId), $photo[0]->getId, 'Id of photo previous of photo no. 2 equals id of photo no. 1' );
is( $album->getPreviousFileId($photo[0]->getId), undef, 'Id of photo previous of photo no. 3 is undef' );
is( $album->getPreviousFileId(undef), undef, 'Return undef if undef specified');
is( $album->getPreviousFileId(''), undef, 'Return undef if empty string specified');
is( $album->getPreviousFileId('123456'), undef, 'Return undef if non-existing id specified');
is( $album->getPreviousFileId($album->getId), undef, 'Return undef if non-child id specified');
#----------------------------------------------------------------------------
# Test getNextFileId
diag('getNextFileId');
is( $album->getNextFileId($photo[2]->getId), $photo[3]->getId, 'Id of photo next of photo no. 3 equals id of photo no. 4' );
is( $album->getNextFileId($photo[3]->getId), $photo[4]->getId, 'Id of photo next of photo no. 4 equals id of photo no. 5' );
is( $album->getNextFileId($photo[4]->getId), undef, 'Id of photo next of photo no. 5 is undef' );
is( $album->getNextFileId(undef), undef, 'Return undef if undef specified');
is( $album->getNextFileId(''), undef, 'Return undef if empty string specified');
is( $album->getNextFileId('123456'), undef, 'Return undef if non-existing id specified');
is( $album->getNextFileId($album->getId), undef, 'Return undef if non-child id specified');
#----------------------------------------------------------------------------
# Cleanup
END {
$versionTag->rollback();
}