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 use Data::Printer colored => 1; warn p $c;
15 my @callnumbers_split;
16 for my $callnumber ( @callnumbers ) {
17 my @lines = C4::ClassSplitRoutine::RegEx::split_callnumber($callnumber, $regexs);
18 push @callnumbers_split, { inline => $callnumber, split => \@lines };
20 $response->param( split_callnumbers => \@callnumbers_split );
21 C4::Service->return_success( $response );
24 sub update_translation {
25 my $id = $query->param('id');
26 my $translation = $query->param('translation');
27 my $lang = $query->param('lang');
29 my $localization = Koha::Localizations->find( $id );
30 if ( defined $lang and $localization->lang ne $lang ) {
31 $localization->lang( $lang )
33 if ( defined $translation and $localization->translation ne $translation ) {
34 $localization->translation( $translation )
38 if ( $localization->is_changed ) {
40 unless ( Koha::Localizations->search( { entity => $localization->entity, code => $localization->code, lang => $lang, localization_id => { '!=' => $localization->localization_id }, } )->count ) {
44 $params{error_code} = 'already_exists';
49 id => $localization->localization_id,
50 entity => $localization->entity,
51 code => $localization->code,
52 lang => $localization->lang,
53 translation => $localization->translation,
54 is_changed => $is_changed,
56 C4::Service->return_success( $response );
60 my $entity = $query->param('entity');
61 my $code = $query->param('code');
62 my $lang = $query->param('lang');
63 my $translation = $query->param('translation');
65 unless ( Koha::Localizations->search({entity => $entity, code => $code, lang => $lang, })->count ) {
66 my $localization = Koha::Localization->new(
71 translation => $translation,
76 id => $localization->localization_id,
77 entity => $localization->entity,
78 code => $localization->code,
79 lang => $localization->lang,
80 translation => $localization->translation,
84 $response->param( error => 1, error_code => 'already_exists', );
86 C4::Service->return_success( $response );
89 sub delete_translation {
90 my $id = $query->param('id');
91 Koha::Localizations->find($id)->delete;
92 $response->param( id => $id );
93 C4::Service->return_success( $response );
96 C4::Service->dispatch(
97 [ 'GET /', [ 'callnumbers', 'regexs' ], \&get_split_callnumbers ],