4 use JSON qw( from_json );
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 )
37 if ( $localization->is_changed ) {
39 unless ( Koha::Localizations->search( { entity => $localization->entity, code => $localization->code, lang => $lang, localization_id => { '!=' => $localization->localization_id }, } )->count ) {
43 $params{error_code} = 'already_exists';
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 );
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(
70 translation => $translation,
75 id => $localization->localization_id,
76 entity => $localization->entity,
77 code => $localization->code,
78 lang => $localization->lang,
79 translation => $localization->translation,
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 ],