3 use Modern
::Perl
'2009';
13 my ( $query, $response ) = C4
::Service
->init( editcatalogue
=> 'edit_catalogue' );
15 my $frameworkcode = $query->param( 'frameworkcode' ) // '';
17 my $tagslib = GetMarcStructure
( 1, $frameworkcode );
21 foreach my $tag ( sort keys %$tagslib ) {
22 my $taglib = $tagslib->{$tag};
23 my $taginfo = { map { $_, $taglib->{$_} } grep { length $_ > 1 } keys %$taglib };
24 $taginfo->{subfields
} = [ map { [ $_, $taglib->{$_} ] } grep { length $_ == 1 } sort keys %$taglib ];
26 push @tags, [ $tag, $taginfo ];
29 my $schema = Koha
::Database
->new->schema;
30 my $authorised_values = {};
32 my $branches = { map { $_->branchcode => $_->branchname } Koha
::Libraries
->search_filtered };
33 $authorised_values->{branches
} = [];
34 foreach my $thisbranch ( sort keys %$branches ) {
35 push @
{ $authorised_values->{branches
} }, { value
=> $thisbranch, lib
=> $branches->{$thisbranch} };
38 $authorised_values->{itemtypes
} = [ $schema->resultset( "Itemtype" )->search( undef, {
39 columns
=> [ { value
=> 'itemtype' }, { lib
=> "description" } ],
40 order_by
=> "description",
41 result_class
=> 'DBIx::Class::ResultClass::HashRefInflator'
44 my $class_sources = GetClassSources
();
46 my $default_source = C4
::Context
->preference("DefaultClassificationSource");
48 foreach my $class_source (sort keys %$class_sources) {
49 next unless $class_sources->{$class_source}->{'used'} or
50 ($class_source eq $default_source);
51 push @
{ $authorised_values->{cn_source
} }, { value
=> $class_source, lib
=> $class_sources->{$class_source}->{'description'} };
54 my $branch_limit = C4
::Context
->userenv ? C4
::Context
->userenv->{"branch"} : "";
57 $results = $schema->resultset( "AuthorisedValue" )->search(
58 { "authorised_values_branches.branchcode" => { "=", [ $branch_limit, undef ] } },
59 { join => "authorised_values_branches", order_by
=> "lib" } );
61 $results = $schema->resultset( "AuthorisedValue" )->search(
63 { order_by
=> "lib" } );
66 foreach my $result ( $results->all ) {
67 $authorised_values->{$result->category} ||= [];
68 push @
{ $authorised_values->{$result->category} }, { value
=> $result->authorised_value, lib
=> $result->lib };
71 $response->param( framework
=> \
@tags, authorised_values
=> $authorised_values );
73 C4
::Service
->return_success( $response );