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, translation => $translation, id => { '!=' => $localization->id }, } )->count ) { |
41 |
$localization->store; |
42 |
$params{is_changed} = 1; |
|
|
43 |
$localization->store; |
44 |
} else { |
45 |
$params{error} = 1; |
46 |
$params{error_code} = 'already_exists'; |
47 |
} |
42 |
} |
48 |
} |
43 |
$response->param( |
49 |
$response->param( |
44 |
id => $localization->localization_id, |
50 |
%params, |
45 |
entity => $localization->entity, |
51 |
id => Encode::encode('utf-8', $localization->localization_id), |
46 |
code => $localization->code, |
52 |
entity => Encode::encode('utf-8', $localization->entity), |
47 |
lang => $localization->lang, |
53 |
code => Encode::encode('utf-8', $localization->code), |
48 |
translation => $localization->translation, |
54 |
lang => Encode::encode('utf-8', $localization->lang), |
49 |
is_changed => $is_changed, |
55 |
translation => Encode::encode('utf-8', $localization->translation), |
50 |
); |
56 |
); |
51 |
C4::Service->return_success( $response ); |
57 |
C4::Service->return_success( $response ); |
52 |
} |
58 |
} |
Lines 56-79
sub add_translation {
Link Here
|
56 |
my $code = $query->param('code'); |
62 |
my $code = $query->param('code'); |
57 |
my $lang = $query->param('lang'); |
63 |
my $lang = $query->param('lang'); |
58 |
my $translation = $query->param('translation'); |
64 |
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 |
|
65 |
|
|
|
66 |
unless ( Koha::Localizations->search({entity => $entity, code => $code, lang => $lang, translation => $translation, })->count ) { |
67 |
my $localization = Koha::Localization->new( |
68 |
{ |
69 |
entity => $entity, |
70 |
code => $code, |
71 |
lang => $lang, |
72 |
translation => $translation, |
73 |
} |
74 |
); |
75 |
warn $translation; |
76 |
warn $localization->translation; |
77 |
warn Encode::encode('utf-8', $localization->translation); |
78 |
$localization->store; |
79 |
$localization->localization_id; |
80 |
$response->param( |
81 |
id => Encode::encode('utf-8', $localization->localization_id), |
82 |
entity => Encode::encode('utf-8', $localization->entity), |
83 |
code => Encode::encode('utf-8', $localization->code), |
84 |
lang => Encode::encode('utf-8', $localization->lang), |
85 |
translation => Encode::encode('utf-8', $localization->translation), |
86 |
); |
87 |
|
88 |
} else { |
89 |
$response->param( error => 1, error_code => 'already_exists', ); |
90 |
} |
77 |
C4::Service->return_success( $response ); |
91 |
C4::Service->return_success( $response ); |
78 |
} |
92 |
} |
79 |
|
93 |
|
80 |
- |
|
|