Bug 16251: Fix value of material select for Rancor 008 widget
[koha.git] / svc / split_callnumbers
blob8c85a58546337bbe32dbaa9a5c914ac6de3b4b59
1 #!/usr/bin/perl
3 use Modern::Perl;
4 use JSON qw( from_json );
6 use C4::Service;
7 use C4::ClassSplitRoutine::RegEx;
8 our ( $query, $response ) = C4::Service->init( parameters => 'parameters_remaining_permissions' );
10 sub get_split_callnumbers {
11 my $regexs = from_json( $query->param('regexs') );
12 my $c = $query->param('callnumbers');
13 my @callnumbers = split "\n", $c;
14 my @callnumbers_split;
15 for my $callnumber ( @callnumbers ) {
16 my @lines = C4::ClassSplitRoutine::RegEx::split_callnumber($callnumber, $regexs);
17 push @callnumbers_split, { inline => $callnumber, split => \@lines };
19 $response->param( split_callnumbers => \@callnumbers_split );
20 C4::Service->return_success( $response );
23 sub update_translation {
24 my $id = $query->param('id');
25 my $translation = $query->param('translation');
26 my $lang = $query->param('lang');
28 my $localization = Koha::Localizations->find( $id );
29 if ( defined $lang and $localization->lang ne $lang ) {
30 $localization->lang( $lang )
32 if ( defined $translation and $localization->translation ne $translation ) {
33 $localization->translation( $translation )
35 my %params;
36 my $is_changed;
37 if ( $localization->is_changed ) {
38 $is_changed = 1;
39 unless ( Koha::Localizations->search( { entity => $localization->entity, code => $localization->code, lang => $lang, localization_id => { '!=' => $localization->localization_id }, } )->count ) {
40 $localization->store;
41 } else {
42 $params{error} = 1;
43 $params{error_code} = 'already_exists';
46 $response->param(
47 %params,
48 id => $localization->localization_id,
49 entity => $localization->entity,
50 code => $localization->code,
51 lang => $localization->lang,
52 translation => $localization->translation,
53 is_changed => $is_changed,
55 C4::Service->return_success( $response );
58 sub add_translation {
59 my $entity = $query->param('entity');
60 my $code = $query->param('code');
61 my $lang = $query->param('lang');
62 my $translation = $query->param('translation');
64 unless ( Koha::Localizations->search({entity => $entity, code => $code, lang => $lang, })->count ) {
65 my $localization = Koha::Localization->new(
67 entity => $entity,
68 code => $code,
69 lang => $lang,
70 translation => $translation,
73 $localization->store;
74 $response->param(
75 id => $localization->localization_id,
76 entity => $localization->entity,
77 code => $localization->code,
78 lang => $localization->lang,
79 translation => $localization->translation,
82 } else {
83 $response->param( error => 1, error_code => 'already_exists', );
85 C4::Service->return_success( $response );
88 sub delete_translation {
89 my $id = $query->param('id');
90 Koha::Localizations->find($id)->delete;
91 $response->param( id => $id );
92 C4::Service->return_success( $response );
95 C4::Service->dispatch(
96 [ 'GET /', [ 'callnumbers', 'regexs' ], \&get_split_callnumbers ],