1 package GenericTranslations;
9 $main::lxdebug->enter_sub();
14 Common::check_params(\%params, qw(translation_type));
16 my $myconfig = \%main::myconfig;
17 my $form = $main::form;
19 my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig);
23 my @values = ($params{translation_type});
24 my @where = ('gt.translation_type = ?');
26 if ($params{translation_id}) {
27 push @values, conv_i($params{translation_id});
28 push @where, 'gt.translation_id = ?';
31 push @where, 'gt.translation_id IS NULL';
34 if ($params{language_id}) {
35 push @values, conv_i($params{language_id});
36 push @where, $params{allow_fallback} ? '(gt.language_id IS NULL) OR (gt.language_id = ?)' : 'gt.language_id = ?';
39 push @where, 'gt.language_id IS NULL';
42 my $query = qq|SELECT gt.translation
43 FROM generic_translations gt
45 WHERE | . join(' AND ', map { "($_)" } @where) . qq|
46 ORDER BY gt.language_id ASC|;
48 my ($translation) = selectfirst_array_query($form, $dbh, $query, @values);
49 $translation ||= $params{default};
51 $main::lxdebug->leave_sub();
57 $main::lxdebug->enter_sub();
62 my $myconfig = \%main::myconfig;
63 my $form = $main::form;
65 my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig);
70 if ($params{translation_type}) {
71 push @values, $params{translation_type};
72 push @where, 'translation_type = ?';
75 if ($params{translation_id}) {
76 push @values, conv_i($params{translation_id});
77 push @where, 'translation_id = ?';
80 my $where_s = scalar(@where) ? 'WHERE ' . join(' AND ', map { "($_)" } @where) : '';
82 my $query = qq|SELECT id, language_id, translation_type, translation_id, translation
83 FROM generic_translations
86 my $results = selectall_hashref_query($form, $dbh, $query, @values);
88 $main::lxdebug->leave_sub();
94 my ($self, %params) = @_;
95 $main::lxdebug->enter_sub();
97 my $rc = SL::DB->client->with_transaction(\&_save, $self, %params);
99 $::lxdebug->leave_sub;
107 Common::check_params(\%params, qw(translation_type));
109 my $myconfig = \%main::myconfig;
110 my $form = $main::form;
112 my $dbh = $params{dbh} || SL::DB->client->dbh;
114 $params{translation} =~ s/^\s+//;
115 $params{translation} =~ s/\s+$//;
117 my @v_insert = (conv_i($params{language_id}), $params{translation_type}, conv_i($params{translation_id}), $params{translation});
118 my @v_seldel = ($params{translation_type});
119 my @w_seldel = ('translation_type = ?');
121 foreach (qw(language_id translation_id)) {
123 push @v_seldel, conv_i($params{$_});
124 push @w_seldel, "$_ = ?";
126 push @w_seldel, "$_ IS NULL";
130 my $q_lookup = qq|SELECT id
131 FROM generic_translations
132 WHERE | . join(' AND ', map { "($_)" } @w_seldel);
133 my $q_delete = qq|DELETE FROM generic_translations
134 WHERE | . join(' AND ', map { "($_)" } @w_seldel);
135 my $q_update = qq|UPDATE generic_translations
138 my $q_insert = qq|INSERT INTO generic_translations (language_id, translation_type, translation_id, translation)
139 VALUES (?, ?, ?, ?)|;
141 my ($id) = selectfirst_array_query($form, $dbh, $q_lookup, @v_seldel);
143 if ($id && !$params{translation}) {
144 do_query($form, $dbh, $q_delete, @v_seldel);
146 do_query($form, $dbh, $q_update, $params{translation}, $id);
147 } elsif ($params{translation}) {
148 do_query($form, $dbh, $q_insert, @v_insert);