Lines 1-6
Link Here
|
1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
2 |
|
2 |
|
3 |
use Modern::Perl; |
3 |
use Modern::Perl; |
|
|
4 |
use Encode qw( encode ); |
4 |
|
5 |
|
5 |
use C4::Service; |
6 |
use C4::Service; |
6 |
use Koha::Localizations; |
7 |
use Koha::Localizations; |
Lines 8-22
use Koha::Localizations;
Link Here
|
8 |
our ( $query, $response ) = C4::Service->init( parameters => 'parameters_remaining_permissions' ); |
9 |
our ( $query, $response ) = C4::Service->init( parameters => 'parameters_remaining_permissions' ); |
9 |
|
10 |
|
10 |
sub get_translations { |
11 |
sub get_translations { |
11 |
my $rs = Koha::Localizations->search({ type => $query->param('type'), code => $query->param('code') }); |
12 |
my $rs = Koha::Localizations->search({ entity => $query->param('entity'), code => $query->param('code') }); |
12 |
my @translations; |
13 |
my @translations; |
13 |
while ( my $s = $rs->next ) { |
14 |
while ( my $s = $rs->next ) { |
14 |
push @translations, { |
15 |
push @translations, { |
15 |
id => $s->localization_id, |
16 |
id => Encode::encode( 'utf-8', $s->localization_id ), |
16 |
type => $s->type, |
17 |
entity => Encode::encode( 'utf-8', $s->entity ), |
17 |
code => $s->code, |
18 |
code => Encode::encode( 'utf-8', $s->code ), |
18 |
lang => $s->lang, |
19 |
lang => Encode::encode( 'utf-8', $s->lang ), |
19 |
translation => $s->translation, |
20 |
translation => Encode::encode( 'utf-8', $s->translation ), |
20 |
} |
21 |
} |
21 |
} |
22 |
} |
22 |
$response->param( translations => \@translations ); |
23 |
$response->param( translations => \@translations ); |
Lines 27-52
sub update_translation {
Link Here
|
27 |
my $id = $query->param('id'); |
28 |
my $id = $query->param('id'); |
28 |
my $translation = $query->param('translation'); |
29 |
my $translation = $query->param('translation'); |
29 |
my $lang = $query->param('lang'); |
30 |
my $lang = $query->param('lang'); |
30 |
my $localization = Koha::Localizations->find( $id ); |
|
|
31 |
|
31 |
|
|
|
32 |
my $localization = Koha::Localizations->find( $id ); |
32 |
if ( defined $lang and $localization->lang ne $lang ) { |
33 |
if ( defined $lang and $localization->lang ne $lang ) { |
33 |
$localization->lang( $lang ) |
34 |
$localization->lang( $lang ) |
34 |
} |
35 |
} |
35 |
if ( defined $translation and $localization->translation ne $translation ) { |
36 |
if ( defined $translation and $localization->translation ne $translation ) { |
36 |
$localization->translation( $translation ) |
37 |
$localization->translation( $translation ) |
37 |
} |
38 |
} |
38 |
my $is_changed; |
39 |
my %params; |
39 |
if ( $localization->is_changed ) { |
40 |
if ( $localization->is_changed ) { |
40 |
$is_changed = 1; |
41 |
unless ( Koha::Localizations->search( { entity => $localization->entity, code => $localization->code, lang => $lang, localization_id => { '!=' => $localization->localization_id }, } )->count ) { |
41 |
$localization->store; |
42 |
$localization->store; |
|
|
43 |
} else { |
44 |
$params{error} = 1; |
45 |
$params{error_code} = 'already_exists'; |
46 |
} |
42 |
} |
47 |
} |
43 |
$response->param( |
48 |
$response->param( |
44 |
id => $localization->localization_id, |
49 |
%params, |
45 |
entity => $localization->entity, |
50 |
id => Encode::encode('utf-8', $localization->localization_id), |
46 |
code => $localization->code, |
51 |
entity => Encode::encode('utf-8', $localization->entity), |
47 |
lang => $localization->lang, |
52 |
code => Encode::encode('utf-8', $localization->code), |
48 |
translation => $localization->translation, |
53 |
lang => Encode::encode('utf-8', $localization->lang), |
49 |
is_changed => $is_changed, |
54 |
translation => Encode::encode('utf-8', $localization->translation), |
50 |
); |
55 |
); |
51 |
C4::Service->return_success( $response ); |
56 |
C4::Service->return_success( $response ); |
52 |
} |
57 |
} |
Lines 56-79
sub add_translation {
Link Here
|
56 |
my $code = $query->param('code'); |
61 |
my $code = $query->param('code'); |
57 |
my $lang = $query->param('lang'); |
62 |
my $lang = $query->param('lang'); |
58 |
my $translation = $query->param('translation'); |
63 |
my $translation = $query->param('translation'); |
59 |
my $localization = Koha::Localization->new( |
|
|
60 |
{ |
61 |
entity => $entity, |
62 |
code => $code, |
63 |
lang => $lang, |
64 |
translation => $translation, |
65 |
} |
66 |
); |
67 |
$localization->store; |
68 |
$localization->localization_id; |
69 |
$response->param( |
70 |
id => $localization->localization_id, |
71 |
entity => $localization->entity, |
72 |
code => $localization->code, |
73 |
lang => $localization->lang, |
74 |
translation => $localization->translation, |
75 |
); |
76 |
|
64 |
|
|
|
65 |
unless ( Koha::Localizations->search({entity => $entity, code => $code, lang => $lang, })->count ) { |
66 |
my $localization = Koha::Localization->new( |
67 |
{ |
68 |
entity => $entity, |
69 |
code => $code, |
70 |
lang => $lang, |
71 |
translation => $translation, |
72 |
} |
73 |
); |
74 |
$localization->store; |
75 |
$response->param( |
76 |
id => Encode::encode('utf-8', $localization->localization_id), |
77 |
entity => Encode::encode('utf-8', $localization->entity), |
78 |
code => Encode::encode('utf-8', $localization->code), |
79 |
lang => Encode::encode('utf-8', $localization->lang), |
80 |
translation => Encode::encode('utf-8', $localization->translation), |
81 |
); |
82 |
|
83 |
} else { |
84 |
$response->param( error => 1, error_code => 'already_exists', ); |
85 |
} |
77 |
C4::Service->return_success( $response ); |
86 |
C4::Service->return_success( $response ); |
78 |
} |
87 |
} |
79 |
|
88 |
|
80 |
- |
|
|