Bug 20100: (QA follow-up) Pref description and improve code in member-flags
[koha.git] / svc / cataloguing / framework
blob4880b8abdb3b79b95c3a0b7c3355e9d923ddb26f
1 #!/usr/bin/perl
3 use Modern::Perl '2009';
5 use CGI;
6 use C4::ClassSource;
7 use C4::Context;
8 use C4::Biblio;
9 use C4::Service;
10 use Koha::Database;
11 use Koha::Libraries;
13 my ( $query, $response ) = C4::Service->init( editcatalogue => 'edit_catalogue' );
15 my $frameworkcode = $query->param( 'frameworkcode' ) // '';
17 my $tagslib = GetMarcStructure( 1, $frameworkcode );
19 my @tags;
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'
42 } ) ];
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"} : "";
55 my $results;
56 if( $branch_limit ) {
57 $results = $schema->resultset( "AuthorisedValue" )->search(
58 { "authorised_values_branches.branchcode" => { "=", [ $branch_limit, undef ] } },
59 { join => "authorised_values_branches", order_by => "lib" } );
60 } else {
61 $results = $schema->resultset( "AuthorisedValue" )->search(
62 undef,
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 );