30edfbfa58
This allows to group certain item types in a category, to be displayed (and searched) as such in OPAC's advanced search. For example, you can group Reserve 2h and Reserve 12h into a Reserve category. The 2 and 12h types won't appear anymore. This also allows to simply prevent an item type from displaying as a search option. TEST PLAN ------------------ 0) Back up database, so you can reset and retest easily. ;) 1) Apply the patch 2) Run Koha QA tool. 3) prove -v t/db_dependent/Koha.t -- all tests should pass. 4) run ./installer/data/mysql/updatedatabase.pl to add the two columns to itemtypes -- Does a meaningful message get printed? Are the columns added? "DESCRIBE itemtypes;" should list hideinopac and searchcategory. 5) You need to add a category to group your item types: a) In Intranet/Koha Admin/Authorized values, select DOCTYPECAT in the 'Show category:' dropdown i) If you do not have a DOCTYPECAT category, create one. b) Click button "New authorized value for DOCTYPECAT" c) Enter Authorized value: HARDWARE Description : Hardware Description (OPAC): Hardware 6) Group your items under that new category a) In Intranet/Koha Admin/Item types, choose (at least) two item types and for each: - Click action/Edit on the right column - Third row (below Description) is the Search category list box, select Hardware - click Save changes at the bottom 7) Select at least one item to be hidden in the OPAC search a) In Intranet/Koha Admin/Item types (again), choose a different item type: - Click action/Edit - Click the checkbox "Hide in OPAC" below the list of icons. 8) Go test your modifications a) Go to OPAC/Adv search. b) Validate that all items modified above (hidden or grouped) do not appear in Item type list c) Validate that new item type Hardware does appear instead. d) Select item Hardware, start Search. ) Validate returned items are the of the two types that were grouped into the Hardware category in step 4. Sponsored-by: Vanier college Signed-off-by: Nick <nick@quecheelibrary.org> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
218 lines
7 KiB
Perl
Executable file
218 lines
7 KiB
Perl
Executable file
#!/usr/bin/perl
|
|
|
|
# Copyright 2000-2002 Katipo Communications
|
|
#
|
|
# This file is part of Koha.
|
|
#
|
|
# Koha is free software; you can redistribute it and/or modify it
|
|
# under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# Koha is distributed in the hope that it will be useful, but
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with Koha; if not, see <http://www.gnu.org/licenses>.
|
|
|
|
use Modern::Perl;
|
|
|
|
use CGI qw ( -utf8 );
|
|
use C4::Auth;
|
|
use C4::Branch;
|
|
use C4::Context;
|
|
use C4::Koha;
|
|
use C4::Output;
|
|
|
|
use Koha::AuthorisedValues;
|
|
|
|
my $input = new CGI;
|
|
my $id = $input->param('id');
|
|
my $op = $input->param('op') || 'list';
|
|
my $searchfield = $input->param('searchfield');
|
|
$searchfield = '' unless defined $searchfield;
|
|
$searchfield =~ s/\,//g;
|
|
my @messages;
|
|
|
|
our ($template, $borrowernumber, $cookie)= get_template_and_user({
|
|
template_name => "admin/authorised_values.tt",
|
|
authnotrequired => 0,
|
|
flagsrequired => {parameters => 'parameters_remaining_permissions'},
|
|
query => $input,
|
|
type => "intranet",
|
|
debug => 1,
|
|
});
|
|
|
|
################## ADD_FORM ##################################
|
|
# called by default. Used to create form to add or modify a record
|
|
if ($op eq 'add_form') {
|
|
my ( $selected_branches, $category, $av );
|
|
if ($id) {
|
|
$av = Koha::AuthorisedValues->new->find( $id );
|
|
$selected_branches = $av->branch_limitations;
|
|
} else {
|
|
$category = $input->param('category');
|
|
}
|
|
|
|
my $branches = GetBranches;
|
|
my @branches_loop;
|
|
|
|
foreach my $branchcode ( sort { uc($branches->{$a}->{branchname}) cmp uc($branches->{$b}->{branchname}) } keys %$branches ) {
|
|
my $selected = ( grep {$_ eq $branchcode} @$selected_branches ) ? 1 : 0;
|
|
push @branches_loop, {
|
|
branchcode => $branchcode,
|
|
branchname => $branches->{$branchcode}->{branchname},
|
|
selected => $selected,
|
|
};
|
|
}
|
|
|
|
if ($id) {
|
|
$template->param(action_modify => 1);
|
|
} elsif ( ! $category ) {
|
|
$template->param(action_add_category => 1);
|
|
} else {
|
|
$template->param(action_add_value => 1);
|
|
}
|
|
|
|
if ( $av ) {
|
|
$template->param(
|
|
category => $av->category,
|
|
authorised_value => $av->authorised_value,
|
|
lib => $av->lib,
|
|
lib_opac => $av->lib_opac,
|
|
id => $av->id,
|
|
imagesets => C4::Koha::getImageSets( checked => $av->imageurl ),
|
|
);
|
|
} else {
|
|
$template->param(
|
|
category => $category,
|
|
imagesets => C4::Koha::getImageSets(),
|
|
);
|
|
}
|
|
$template->param(
|
|
branches_loop => \@branches_loop,
|
|
);
|
|
|
|
} elsif ($op eq 'add') {
|
|
my $new_authorised_value = $input->param('authorised_value');
|
|
my $new_category = $input->param('category');
|
|
my $imageurl = $input->param( 'imageurl' ) || '';
|
|
$imageurl = '' if $imageurl =~ /removeImage/;
|
|
my $duplicate_entry = 0;
|
|
my @branches = grep { $_ ne q{} } $input->param('branches');
|
|
|
|
my $already_exists = Koha::AuthorisedValues->search(
|
|
{
|
|
category => $new_category,
|
|
authorised_value => $new_authorised_value,
|
|
}
|
|
)->next;
|
|
|
|
if ( $already_exists and ( not $id or $already_exists->id != $id ) ) {
|
|
push @messages, {type => 'error', code => 'already_exists' };
|
|
}
|
|
elsif ( $id ) { # Update
|
|
my $av = Koha::AuthorisedValues->new->find( $id );
|
|
|
|
$av->lib( $input->param('lib') || undef );
|
|
$av->lib_opac( $input->param('lib_opac') || undef );
|
|
$av->category( $new_category );
|
|
$av->authorised_value( $new_authorised_value );
|
|
$av->imageurl( $imageurl );
|
|
eval{
|
|
$av->store;
|
|
$av->replace_branch_limitations( \@branches );
|
|
};
|
|
if ( $@ ) {
|
|
push @messages, {type => 'error', code => 'error_on_update' };
|
|
} else {
|
|
push @messages, { type => 'message', code => 'success_on_update' };
|
|
}
|
|
}
|
|
else { # Insert
|
|
my $av = Koha::AuthorisedValue->new( {
|
|
category => $new_category,
|
|
authorised_value => $new_authorised_value,
|
|
lib => $input->param('lib') || undef,
|
|
lib_opac => $input->param('lib_opac') || undef,
|
|
imageurl => $imageurl,
|
|
} );
|
|
|
|
eval {
|
|
$av->store;
|
|
$av->replace_branch_limitations( \@branches );
|
|
};
|
|
|
|
if ( $@ ) {
|
|
push @messages, {type => 'error', code => 'error_on_insert' };
|
|
} else {
|
|
push @messages, { type => 'message', code => 'success_on_insert' };
|
|
}
|
|
}
|
|
|
|
$op = 'list';
|
|
$searchfield = $new_category;
|
|
} elsif ($op eq 'delete') {
|
|
my $av = Koha::AuthorisedValues->new->find( $input->param('id') );
|
|
my $deleted = eval {$av->delete};
|
|
if ( $@ or not $deleted ) {
|
|
push @messages, {type => 'error', code => 'error_on_delete' };
|
|
} else {
|
|
push @messages, { type => 'message', code => 'success_on_delete' };
|
|
}
|
|
|
|
$op = 'list';
|
|
$template->param( delete_success => 1 );
|
|
}
|
|
|
|
$template->param(
|
|
op => $op,
|
|
searchfield => $searchfield,
|
|
messages => \@messages,
|
|
);
|
|
|
|
if ( $op eq 'list' ) {
|
|
# build categories list
|
|
my @categories = Koha::AuthorisedValues->new->categories;
|
|
my @category_list;
|
|
my %categories; # a hash, to check that some hardcoded categories exist.
|
|
for my $category ( @categories ) {
|
|
push( @category_list, $category );
|
|
$categories{$category} = 1;
|
|
}
|
|
|
|
# push koha system categories
|
|
foreach (qw(Asort1 Asort2 Bsort1 Bsort2 SUGGEST DAMAGED LOST REPORT_GROUP REPORT_SUBGROUP DEPARTMENT TERM SUGGEST_STATUS DOCTYPECAT)) {
|
|
push @category_list, $_ unless $categories{$_};
|
|
}
|
|
|
|
#reorder the list
|
|
@category_list = sort {$a cmp $b} @category_list;
|
|
|
|
$searchfield ||= $category_list[0];
|
|
|
|
my @avs_by_category = Koha::AuthorisedValues->new->search( { category => $searchfield } );
|
|
my @loop_data = ();
|
|
# builds value list
|
|
for my $av ( @avs_by_category ) {
|
|
my %row_data; # get a fresh hash for the row data
|
|
$row_data{category} = $av->category;
|
|
$row_data{authorised_value} = $av->authorised_value;
|
|
$row_data{lib} = $av->lib;
|
|
$row_data{lib_opac} = $av->lib_opac;
|
|
$row_data{imageurl} = getitemtypeimagelocation( 'intranet', $av->imageurl );
|
|
$row_data{branches} = $av->branch_limitations;
|
|
$row_data{id} = $av->id;
|
|
push(@loop_data, \%row_data);
|
|
}
|
|
|
|
$template->param(
|
|
loop => \@loop_data,
|
|
category => $searchfield,
|
|
categories => \@category_list,
|
|
);
|
|
|
|
}
|
|
output_html_with_http_headers $input, $cookie, $template->output;
|