From 39c95cb25be361810975cf4a1eff87b2fa6e7add Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Tue, 27 May 2008 20:41:26 +0000 Subject: [PATCH] added template variables to photo. added better getParent and getGallery to GalleryFile, for approval processes --- lib/WebGUI/Asset/File/GalleryFile.pm | 47 ++++++++++++++++++++-- lib/WebGUI/Asset/File/GalleryFile/Photo.pm | 7 +++- 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/lib/WebGUI/Asset/File/GalleryFile.pm b/lib/WebGUI/Asset/File/GalleryFile.pm index 85920567d..90503f5e0 100644 --- a/lib/WebGUI/Asset/File/GalleryFile.pm +++ b/lib/WebGUI/Asset/File/GalleryFile.pm @@ -338,9 +338,45 @@ Gets the Gallery asset this GalleryFile is a member of. sub getGallery { my $self = shift; - my $gallery = $self->getParent->getParent; - return $gallery if $gallery->isa("WebGUI::Asset::Wobject::Gallery"); - return undef; + + # We're using getLinage instead of getParent->getParent because of the + # overridden getParent, below. + # We need to be able to get the Gallery WITHOUT having to get the GalleryAlbum + my $gallery + = $self->getLineage( ['ancestors'], { + includeOnlyClasses => [ 'WebGUI::Asset::Wobject::Gallery' ], + returnObjects => 1, + invertTree => 1, + } )->[ 0 ]; + + return $gallery; +} + +#---------------------------------------------------------------------------- + +=head2 getParent ( ) + +Get the parent GalleryAlbum. If the only revision of the GalleryAlbum is +"pending", return that anyway. + +=cut + +sub getParent { + my $self = shift; + if ( my $album = $self->getParent ) { + return $album; + } + # Only get the pending version if we're allowed to see this photo in its pending status + elsif ( $self->getGallery->canEdit || $self->get( 'ownerUserId' ) eq $self->session->user->userId ) { + my $album + = $self->getLineage( ['ancestors'], { + includeOnlyClasses => [ 'WebGUI::Asset::Wobject::GalleryAlbum' ], + returnObjects => 1, + statusToInclude => [ 'pending', 'approved' ], + invertTree => 1, + } )->[ 0 ]; + return $album; + } } #---------------------------------------------------------------------------- @@ -376,6 +412,11 @@ sub getTemplateVars { $var->{ fileUrl } = $self->getFileUrl; $var->{ thumbnailUrl } = $self->getThumbnailUrl; + # Set a flag for pending files + if ( $self->get( "status" ) eq "pending" ) { + $var->{ 'isPending' } = 1; + } + # Fix 'undef' vars since HTML::Template does inheritence on them for my $key ( qw( synopsis ) ) { unless ( defined $var->{$key} ) { diff --git a/lib/WebGUI/Asset/File/GalleryFile/Photo.pm b/lib/WebGUI/Asset/File/GalleryFile/Photo.pm index 457fe471f..dc0785175 100644 --- a/lib/WebGUI/Asset/File/GalleryFile/Photo.pm +++ b/lib/WebGUI/Asset/File/GalleryFile/Photo.pm @@ -224,9 +224,12 @@ sub getTemplateVars { ### Download resolutions for my $resolution ( @{ $self->getResolutions } ) { + my $downloadUrl = $self->getStorageLocation->getPathFrag( $resolution ); push @{ $var->{ resolutions_loop } }, { - url_download => $self->getStorageLocation->getPathFrag($resolution) + resolution => $resolution, + url_download => $downloadUrl, }; + $var->{ "resolution_" . $resolution } = $downloadUrl; } ### Format exif vars @@ -392,7 +395,7 @@ sub updateExifDataFromFile { } # Remove other, pointless keys - for my $key ( qw( Directory ) ) { + for my $key ( qw( Directory NativeDigest ) ) { delete $info->{ $key }; }