From: Jan Büren Date: Mon, 29 Jun 2009 15:09:02 +0000 (+0000) Subject: GenericTranslations.pm und debug-code entfernt X-Git-Tag: release-2.6.1beta1~392 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=4dbcf68099d51d441cd7d292dab862fc04cdcc98;p=kivitendo-erp.git GenericTranslations.pm und debug-code entfernt --- diff --git a/SL/Form.pm b/SL/Form.pm index b85d3748f..e7ee2b216 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -1355,9 +1355,6 @@ Content-Length: $numbytes while () { print OUT $_; - open(DUMP_OUT, "> /tmp/lx2.dump" ); - print(DUMP_OUT Dumper($self)); - close(DUMP_OUT); } diff --git a/SL/GenericTranslations.pm b/SL/GenericTranslations.pm new file mode 100644 index 000000000..5592af2b0 --- /dev/null +++ b/SL/GenericTranslations.pm @@ -0,0 +1,146 @@ +package GenericTranslations; + +use SL::DBUtils; + +sub get { + $main::lxdebug->enter_sub(); + + my $self = shift; + my %params = @_; + + Common::check_params(\%params, qw(translation_type)); + + my $myconfig = \%main::myconfig; + my $form = $main::form; + + my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig); + + my $joins = ''; + + my @values = ($params{translation_type}); + my @where = ('gt.translation_type = ?'); + + if ($params{translation_id}) { + push @values, conv_i($params{translation_id}); + push @where, 'gt.translation_id = ?'; + + } else { + push @where, 'gt.translation_id IS NULL'; + } + + if ($params{language_id}) { + push @values, conv_i($params{language_id}); + push @where, $params{allow_fallback} ? '(gt.language_id IS NULL) OR (gt.language_id = ?)' : 'gt.language_id = ?'; + + } else { + push @where, 'gt.language_id IS NULL'; + } + + my $query = qq|SELECT gt.translation + FROM generic_translations gt + $joins + WHERE | . join(' AND ', map { "($_)" } @where) . qq| + ORDER BY gt.language_id ASC|; + + my ($translation) = selectfirst_array_query($form, $dbh, $query, @values); + $translation ||= $params{default}; + + $main::lxdebug->leave_sub(); + + return $translation; +} + +sub list { + $main::lxdebug->enter_sub(); + + my $self = shift; + my %params = @_; + + my $myconfig = \%main::myconfig; + my $form = $main::form; + + my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig); + + my @values = (); + my @where = (); + + if ($params{translation_type}) { + push @values, $params{translation_type}; + push @where, 'translation_type = ?'; + } + + if ($params{translation_id}) { + push @values, conv_i($params{translation_id}); + push @where, 'translation_id = ?'; + } + + my $where_s = scalar(@where) ? 'WHERE ' . join(' AND ', map { "($_)" } @where) : ''; + + my $query = qq|SELECT id, language_id, translation_type, translation_id, translation + FROM generic_translations + $where_s|; + + my $results = selectall_hashref_query($form, $dbh, $query, @values); + + $main::lxdebug->leave_sub(); + + return $results; +} + +sub save { + $main::lxdebug->enter_sub(); + + my $self = shift; + my %params = @_; + + Common::check_params(\%params, qw(translation_type)); + + my $myconfig = \%main::myconfig; + my $form = $main::form; + + my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig); + + $params{translation} =~ s/^\s+//; + $params{translation} =~ s/\s+$//; + + my @v_insert = (conv_i($params{language_id}), $params{translation_type}, conv_i($params{translation_id}), $params{translation}); + my @v_seldel = ($params{translation_type}); + my @w_seldel = ('translation_type = ?'); + + foreach (qw(language_id translation_id)) { + if ($params{$_}) { + push @v_seldel, conv_i($params{$_}); + push @w_seldel, "$_ = ?"; + } else { + push @w_seldel, "$_ IS NULL"; + } + } + + my $q_lookup = qq|SELECT id + FROM generic_translations + WHERE | . join(' AND ', map { "($_)" } @w_seldel); + my $q_delete = qq|DELETE FROM generic_translations + WHERE | . join(' AND ', map { "($_)" } @w_seldel); + my $q_update = qq|UPDATE generic_translations + SET translation = ? + WHERE id = ?|; + my $q_insert = qq|INSERT INTO generic_translations (language_id, translation_type, translation_id, translation) + VALUES (?, ?, ?, ?)|; + + my ($id) = selectfirst_array_query($form, $dbh, $q_lookup, @v_seldel); + + if ($id && !$params{translation}) { + do_query($form, $dbh, $q_delete, @v_seldel); + } elsif ($id) { + do_query($form, $dbh, $q_update, $params{translation}, $id); + } elsif ($params{translation}) { + do_query($form, $dbh, $q_insert, @v_insert); + } + + $dbh->commit() unless ($params{dbh}); + + $main::lxdebug->leave_sub(); +} + + +1;