bug 2047: refactoring icon manipulation logic
I'm extracting some of the icon manipulation logic so that I can get to it from the authorized values pages. There should be no functionality or documentation changes with this commit. Signed-off-by: Joshua Ferraro <jmf@liblime.com>
This commit is contained in:
parent
b4573483e4
commit
aef807a937
113
C4/Koha.pm
113
C4/Koha.pm
|
|
@ -479,6 +479,119 @@ sub getitemtypeimagesrc {
|
|||
}
|
||||
}
|
||||
|
||||
=head3 _getImagesFromDirectory
|
||||
|
||||
Find all of the image files in a directory in the filesystem
|
||||
|
||||
parameters:
|
||||
a directory name
|
||||
|
||||
returns: a list of images in that directory.
|
||||
|
||||
Notes: this does not traverse into subdirectories. See
|
||||
_getSubdirectoryNames for help with that.
|
||||
Images are assumed to be files with .gif or .png file extensions.
|
||||
The image names returned do not have the directory name on them.
|
||||
|
||||
=cut
|
||||
|
||||
sub _getImagesFromDirectory {
|
||||
my $directoryname = shift;
|
||||
return unless defined $directoryname;
|
||||
return unless -d $directoryname;
|
||||
|
||||
if ( opendir ( my $dh, $directoryname ) ) {
|
||||
my @images = grep { /\.(gif|png)$/i } readdir( $dh );
|
||||
closedir $dh;
|
||||
return @images;
|
||||
} else {
|
||||
warn "unable to opendir $directoryname: $!";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
=head3 _getSubdirectoryNames
|
||||
|
||||
Find all of the directories in a directory in the filesystem
|
||||
|
||||
parameters:
|
||||
a directory name
|
||||
|
||||
returns: a list of subdirectories in that directory.
|
||||
|
||||
Notes: this does not traverse into subdirectories. Only the first
|
||||
level of subdirectories are returned.
|
||||
The directory names returned don't have the parent directory name
|
||||
on them.
|
||||
|
||||
=cut
|
||||
|
||||
sub _getSubdirectoryNames {
|
||||
my $directoryname = shift;
|
||||
return unless defined $directoryname;
|
||||
return unless -d $directoryname;
|
||||
|
||||
if ( opendir ( my $dh, $directoryname ) ) {
|
||||
my @directories = grep { -d File::Spec->catfile( $directoryname, $_ ) && ! ( /^\./ ) } readdir( $dh );
|
||||
closedir $dh;
|
||||
return @directories;
|
||||
} else {
|
||||
warn "unable to opendir $directoryname: $!";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
=head3 getImageSets
|
||||
|
||||
returns: a listref of hashrefs. Each hash represents another collection of images.
|
||||
{ imagesetname => 'npl', # the name of the image set (npl is the original one)
|
||||
images => listref of image hashrefs
|
||||
}
|
||||
|
||||
each image is represented by a hashref like this:
|
||||
{ KohaImage => 'npl/image.gif',
|
||||
StaffImageUrl => '/intranet-tmpl/prog/img/itemtypeimg/npl/image.gif',
|
||||
OpacImageURL => '/opac-tmpl/prog/itemtypeimg/npl/image.gif'
|
||||
checked => 0 or 1: was this the image passed to this method?
|
||||
Note: I'd like to remove this somehow.
|
||||
}
|
||||
|
||||
=cut
|
||||
|
||||
sub getImageSets {
|
||||
my %params = @_;
|
||||
my $checked = $params{'checked'} || '';
|
||||
|
||||
my $paths = { staff => { filesystem => getitemtypeimagedir('intranet'),
|
||||
url => getitemtypeimagesrc('intranet'),
|
||||
},
|
||||
opac => { filesystem => getitemtypeimagedir('opac'),
|
||||
url => getitemtypeimagesrc('opac'),
|
||||
}
|
||||
};
|
||||
|
||||
my @imagesets = (); # list of hasrefs of image set data to pass to template
|
||||
my @subdirectories = _getSubdirectoryNames( $paths->{'staff'}{'filesystem'} );
|
||||
|
||||
foreach my $imagesubdir ( @subdirectories ) {
|
||||
my @imagelist = (); # hashrefs of image info
|
||||
my @imagenames = _getImagesFromDirectory( File::Spec->catfile( $paths->{'staff'}{'filesystem'}, $imagesubdir ) );
|
||||
foreach my $thisimage ( @imagenames ) {
|
||||
push( @imagelist,
|
||||
{ KohaImage => "$imagesubdir/$thisimage",
|
||||
StaffImageUrl => join( '/', $paths->{'staff'}{'url'}, $imagesubdir, $thisimage ),
|
||||
OpacImageUrl => join( '/', $paths->{'opac'}{'url'}, $imagesubdir, $thisimage ),
|
||||
checked => "$imagesubdir/$thisimage" eq $checked ? 1 : 0,
|
||||
}
|
||||
);
|
||||
}
|
||||
push @imagesets, { imagesetname => $imagesubdir,
|
||||
images => \@imagelist };
|
||||
|
||||
}
|
||||
return \@imagesets;
|
||||
}
|
||||
|
||||
=head2 GetPrinters
|
||||
|
||||
$printers = &GetPrinters();
|
||||
|
|
|
|||
|
|
@ -64,35 +64,6 @@ sub StringSearch {
|
|||
# like [ fetchrow_hashref(), fetchrow_hashref() ... ]
|
||||
}
|
||||
|
||||
sub getImagesFromDirectory {
|
||||
my $directoryname = shift;
|
||||
return unless defined $directoryname;
|
||||
return unless -d $directoryname;
|
||||
|
||||
if ( opendir ( my $dh, $directoryname ) ) {
|
||||
my @images = grep { /\.(gif|png)$/i } readdir( $dh );
|
||||
closedir $dh;
|
||||
return @images;
|
||||
} else {
|
||||
warn "unable to opendir $directoryname: $!";
|
||||
return;
|
||||
}
|
||||
}
|
||||
sub getSubdirectoryNames {
|
||||
my $directoryname = shift;
|
||||
return unless defined $directoryname;
|
||||
return unless -d $directoryname;
|
||||
|
||||
if ( opendir ( my $dh, $directoryname ) ) {
|
||||
my @directories = grep { -d File::Spec->catfile( $directoryname, $_ ) && ! ( /^\./ ) } readdir( $dh );
|
||||
closedir $dh;
|
||||
return @directories;
|
||||
} else {
|
||||
warn "unable to opendir $directoryname: $!";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my $input = new CGI;
|
||||
my $searchfield = $input->param('description');
|
||||
my $script_name = "/cgi-bin/koha/admin/itemtypes.pl";
|
||||
|
|
@ -131,39 +102,7 @@ if ( $op eq 'add_form' ) {
|
|||
$data = $sth->fetchrow_hashref;
|
||||
}
|
||||
|
||||
# build list of images
|
||||
my $src = "intranet"; # so that the getitemtypeimage functions know where they were called from -fbcit
|
||||
my $imagedir_filesystem = getitemtypeimagedir($src);
|
||||
my $imagedir_web = getitemtypeimagesrc($src);
|
||||
|
||||
my @imagesets = (); # list of hasrefs of image set data to pass to template
|
||||
my @subdirectories = getSubdirectoryNames( $imagedir_filesystem );
|
||||
|
||||
foreach my $imagesubdir ( @subdirectories ) {
|
||||
my @imagelist = (); # hashrefs of image info
|
||||
my $i = 0; # counter
|
||||
my $image_per_line = 12; # max images in a line?
|
||||
my @imagenames = getImagesFromDirectory( File::Spec->catfile( $imagedir_filesystem, $imagesubdir ) );
|
||||
foreach my $thisimage ( @imagenames ) {
|
||||
$i++;
|
||||
if ( $i == $image_per_line ) {
|
||||
$i = 0;
|
||||
push @imagelist, { KohaImage => '', KohaImageSrc => '' };
|
||||
} else {
|
||||
push(
|
||||
@imagelist,
|
||||
{
|
||||
KohaImage => "$imagesubdir/$thisimage",
|
||||
KohaImageSrc => join( '/', $imagedir_web, $imagesubdir, $thisimage ),
|
||||
checked => "$imagesubdir/$thisimage" eq $data->{imageurl} ? 1 : 0,
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
push @imagesets, { imagesetname => $imagesubdir,
|
||||
images => \@imagelist };
|
||||
|
||||
}
|
||||
my $imagesets = C4::Koha::getImageSets( checked => $data->{'imageurl'} );
|
||||
|
||||
my $remote_image = undef;
|
||||
if ( defined $data->{imageurl} and $data->{imageurl} =~ /^http/i ) {
|
||||
|
|
@ -179,7 +118,7 @@ if ( $op eq 'add_form' ) {
|
|||
imageurl => $data->{'imageurl'},
|
||||
template => C4::Context->preference('template'),
|
||||
summary => $data->{summary},
|
||||
imagesets => \@imagesets,
|
||||
imagesets => $imagesets,
|
||||
remote_image => $remote_image,
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -163,8 +163,8 @@ Item Types Administration
|
|||
<li>Icons from collection <b><!-- TMPL_VAR name="imagesetname" --></b>:</li>
|
||||
<!-- TMPL_LOOP NAME="images" -->
|
||||
<li style="float: none; display: inline; clear : none; width: auto;">
|
||||
<label> <!-- TMPL_IF NAME="KohaImageSrc" -->
|
||||
<img src="<!-- TMPL_VAR name="KohaImageSrc" -->" alt="<!-- TMPL_VAR name="KohaImageSrc" -->" title="<!-- TMPL_VAR name="KohaImageSrc" -->" />
|
||||
<label> <!-- TMPL_IF NAME="StaffImageUrl" -->
|
||||
<img src="<!-- TMPL_VAR name="StaffImageUrl" -->" alt="<!-- TMPL_VAR name="StaffImageUrl" -->" title="<!-- TMPL_VAR name="StaffImageUrl" -->" />
|
||||
<!-- TMPL_ELSE -->
|
||||
<!-- /TMPL_IF -->
|
||||
<!-- TMPL_IF name="checked" -->
|
||||
|
|
|
|||
Loading…
Reference in New Issue