more work. completed GalleryAlbum. started Gallery.

This commit is contained in:
Doug Bell 2007-11-06 04:13:43 +00:00
parent 2570980fa5
commit 55135c8147
5 changed files with 825 additions and 32 deletions

View file

@ -18,6 +18,14 @@ use WebGUI::International;
use WebGUI::Utility;
use base 'WebGUI::Asset::Wobject';
=head1 NAME
=head1 DESCRIPTION
=head1 SYNOPSIS
=head1 METHODS
#-------------------------------------------------------------------
=head2 definition ( )
@ -69,7 +77,7 @@ sub definition {
imageResolutions => {
tab => "properties",
fieldType => "checkList",
defaultValue => ['800','1024','1200','1600'],
defaultValue => ['800', '1024', '1200', '1600', '2880'],
options => \%imageResolutionOptions,
label => $i18n->get("imageResolutions label"),
hoverHelp => $i18n->get("imageResolutions description"),
@ -95,7 +103,7 @@ sub definition {
label => $i18n->get("maxSpacePerUser label"),
hoverHelp => $i18n->get("maxSpacePerUser description"),
},
richEditIdFileComment => {
richEditIdComment => {
tab => "properties",
fieldType => "selectRichEditor",
defaultValue => undef, # Rich Editor for Posts
@ -246,10 +254,197 @@ sub definition {
#----------------------------------------------------------------------------
=head2 getTemplateEditFile ( )
=head2 canAddFile ( [userId] )
Returns an instance of a WebGUI::Asset::Template for the template to edit
files in this gallery
Returns true if the user can add files to this Gallery. C<userId> is the
userId to check. If no userId is passed, will check the current user.
Users can add files to this gallery if they are part of the C<groupIdAddFile>
=cut
sub canAddFile {
my $self = shift;
my $userId = shift;
my $user = $userId
? WebGUI::User->new( $self->session, $userId )
: $self->session->user
;
return $user->isInGroup( $self->get("groupIdAddFile") );
}
#----------------------------------------------------------------------------
=head2 canComment ( [userId] )
Returns true if the user can comment on this Gallery. C<userId> is the userId
to check. If no userId is passed, will check the current user.
Users can comment on this gallery if they are part of the
C<groupIdAddComment> group.
=cut
sub canComment {
my $self = shift;
my $userId = shift;
my $user = $userId
? WebGUI::User->new( $self->session, $userId )
: $self->session->user
;
return $user->isInGroup( $self->get("groupIdAddComment") );
}
#----------------------------------------------------------------------------
=head2 canEdit ( [userId] )
Returns true if the user can edit this Gallery. C<userId> is the userId to
check. If no userId is passed, will check the current user.
Users can edit this gallery if they are part of the C<groupIdEdit> group.
=cut
sub canEdit {
my $self = shift;
my $userId = shift;
my $user = $userId
? WebGUI::User->new( $self->session, $userId )
: $self->session->user
;
return $user->isInGroup( $self->get("groupIdEdit") );
}
#----------------------------------------------------------------------------
=head2 canView ( [userId] )
Returns true if the user can view this Gallery. C<userId> is the userId to
check. If no userId is passed, will check the current user.
Users can view this gallery if they are part of the C<groupIdView> group.
=cut
sub canView {
my $self = shift;
my $userId = shift;
my $user = $userId
? WebGUI::User->new( $self->session, $userId )
: $self->session->user
;
return $user->isInGroup( $self->get("groupIdView") );
}
#----------------------------------------------------------------------------
=head2 getAlbumIds ( )
Gets an array reference of all the album IDs under this Gallery.
=cut
sub getAlbumIds {
my $self = shift;
return $self->getLineage(['descendants'], {
includeOnlyClasses => ['WebGUI::Asset::Wobject::GalleryAlbum'],
});
}
#----------------------------------------------------------------------------
=head2 getAlbumPaginator ( )
Gets a WebGUI::Paginator for all the albums in this Gallery.
=cut
sub getAlbumPaginator {
my $self = shift;
my $p = WebGUI::Paginator->new( $self->session, $self->getUrl );
$p->setDataByArrayRef( $self->getAlbumIds );
return $p;
}
#----------------------------------------------------------------------------
=head2 getAssetClassForFile ( filepath )
Gets the WebGUI Asset class for the file at the given C<filepath>. Returns
undef if the file cannot be saved under this Gallery.
=cut
sub getAssetClassForFile {
my $self = shift;
my $filepath = shift;
# Checks for Photo assets
if ( $filepath =~ /\.(jpe?g|gif|png)/i ) {
return "WebGUI::Asset::File::Image::Photo";
}
# No class found
return undef;
}
#----------------------------------------------------------------------------
=head2 getImageResolutions ( )
Gets an array reference of the image resolutions to create for image-type
assets in this gallery.
=cut
sub getImageResolutions {
my $self = shift;
return [ split /\n/, $self->get("imageResolutions") ];
}
#----------------------------------------------------------------------------
=head2 getSearchPaginator ( options )
Gets a WebGUI::Paginator for a search. C<options> is a hash reference of
options with the following keys:
keywords => Keywords to search on
Other keys are valid, see C<WebGUI::Search::search()> for details.
=cut
sub getSearchPaginator {
my $self = shift;
my $rules = shift;
$rules->{ lineage } = $self->get("lineage");
my $search = WebGUI::Search->new( $self->session );
$search->search( $rules );
my $paginator = $search->getPaginatorResultSet( $self->getUrl('func=search') );
return $paginator;
}
#----------------------------------------------------------------------------
=head2 getTemplateIdEditFile ( )
Returns the ID for the template to edit a file.
NOTE: This may need to change in the future to take into account different
classes of files inside of a Gallery.
@ -258,7 +453,72 @@ classes of files inside of a Gallery.
sub getTemplateEditFile {
my $self = shift;
return WebGUI::Asset::Template->new($self->session, $self->get("templateIdEditFile"));
return $self->get("templateIdEditFile");
}
#----------------------------------------------------------------------------
=head2 getTemplateVars ( )
Gets a hash reference of vars common to all templates.
=cut
sub getTemplateVars {
my $self = shift;
my $var = $self->get;
return $var;
}
#----------------------------------------------------------------------------
=head2 getUserFileIds ( [userId] )
Gets an array reference of assetIds for the files in this Gallery owned by
the specified C<userId>. If userId is not defined, will use the current user.
=cut
sub getUserFileIds {
my $self = shift;
my $userId = shift || $self->session->user->userId;
my $db = $self->session->db;
# Note: We use excludeClasses to avoid getting GalleryAlbum assets
my $assetIds
= $self->getLineage( ['descendants'], {
excludeClasses => [ 'WebGUI::Asset::Wobject::GalleryAlbum' ],
whereClause => "ownerUserId = " . $db->quote($userId),
});
return $assetIds;
}
#----------------------------------------------------------------------------
=head2 getUserAlbumIds ( [userId] )
Gets an array reference of assetIds for the GalleryAlbums in this Gallery
owned by the specified C<userId>. If userId is not defined, will use the
current user.
=cut
sub getUserAlbumIds {
my $self = shift;
my $userId = shift || $self->session->user->userId;
my $db = $self->session->db;
my $assetIds
= $self->getLineage( ['descendants'], {
includeOnlyClasses => [ 'WebGUI::Asset::Wobject::GalleryAlbum' ],
whereClause => "ownerUserId = " . $db->quote($userId),
});
return $assetIds;
}
#----------------------------------------------------------------------------
@ -277,7 +537,7 @@ sub prepareView {
$self->{_viewTemplate} = $template;
}
#-------------------------------------------------------------------
#----------------------------------------------------------------------------
=head2 view ( )
@ -294,4 +554,41 @@ sub view {
return $self->processTemplate($var, undef, $self->{_viewTemplate});
}
#----------------------------------------------------------------------------
=head2 www_listAlbums ( )
Show a paginated list of the albums in this gallery.
=cut
sub www_listAlbums {
my $self = shift;
}
#----------------------------------------------------------------------------
=head2 www_listAlbumsRss ( )
=cut
#----------------------------------------------------------------------------
=head2 www_search ( )
=cut
#----------------------------------------------------------------------------
=head2 www_userGallery ( )
=cut
#----------------------------------------------------------------------------
=head2 www_userGalleryRss ( )
=cut
1;