View | Details | Raw Unified | Return to bug 26251
Collapse All | Expand All

(-)a/svc/split_callnumbers (-75 / +1 lines)
Lines 1-10 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
use JSON qw( from_json );
5
6
use C4::Service;
4
use C4::Service;
7
use C4::ClassSplitRoutine::RegEx;
5
use C4::ClassSplitRoutine::RegEx;
6
8
our ( $query, $response ) = C4::Service->init( parameters => 'parameters_remaining_permissions' );
7
our ( $query, $response ) = C4::Service->init( parameters => 'parameters_remaining_permissions' );
9
8
10
sub get_split_callnumbers {
9
sub get_split_callnumbers {
Lines 20-97 sub get_split_callnumbers { Link Here
20
    C4::Service->return_success( $response );
19
    C4::Service->return_success( $response );
21
}
20
}
22
21
23
sub update_translation {
24
    my $id = $query->param('id');
25
    my $translation = $query->param('translation');
26
    my $lang = $query->param('lang');
27
28
    my $localization = Koha::Localizations->find( $id );
29
    if ( defined $lang and $localization->lang ne $lang ) {
30
        $localization->lang( $lang )
31
    }
32
    if ( defined $translation and $localization->translation ne $translation ) {
33
        $localization->translation( $translation )
34
    }
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';
44
        }
45
    }
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,
54
    );
55
    C4::Service->return_success( $response );
56
}
57
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');
63
64
    unless ( Koha::Localizations->search({entity => $entity, code => $code, lang => $lang, })->count ) {
65
        my $localization = Koha::Localization->new(
66
            {
67
                entity => $entity,
68
                code => $code,
69
                lang => $lang,
70
                translation => $translation,
71
            }
72
        );
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,
80
        );
81
82
    } else {
83
        $response->param( error => 1, error_code => 'already_exists', );
84
    }
85
    C4::Service->return_success( $response );
86
}
87
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 );
93
}
94
95
C4::Service->dispatch(
22
C4::Service->dispatch(
96
    [ 'GET /', [ 'callnumbers', 'regexs' ], \&get_split_callnumbers ],
23
    [ 'GET /', [ 'callnumbers', 'regexs' ], \&get_split_callnumbers ],
97
);
24
);
98
- 

Return to bug 26251