Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision af853490

Von Moritz Bunkus vor etwa 18 Jahren hinzugefügt

  • ID af85349024c0d1fc6db899cd84708c7fb6dfb7f4
  • Vorgänger bdff2b07
  • Nachfolger 32d33e11

Verwalten von Einheitennamen für jede angelegte Sprache. Beim Druck werden die Einheitennamen durch diejenigen ersetzt, die für die ausgewählte Ausgabesprache gespeichert sind.

Unterschiede anzeigen:

SL/AM.pm
851 851
sub language {
852 852
  $main::lxdebug->enter_sub();
853 853

  
854
  my ($self, $myconfig, $form) = @_;
854
  my ($self, $myconfig, $form, $return_list) = @_;
855 855

  
856 856
  # connect to database
857 857
  my $dbh = $form->dbconnect($myconfig);
......
864 864
  $sth = $dbh->prepare($query);
865 865
  $sth->execute || $form->dberror($query);
866 866

  
867
  my $ary = [];
868

  
867 869
  while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
868
    push @{ $form->{ALL} }, $ref;
870
    push(@{ $ary }, $ref);
869 871
  }
870 872

  
871 873
  $sth->finish;
872 874
  $dbh->disconnect;
873 875

  
874 876
  $main::lxdebug->leave_sub();
877

  
878
  if ($return_list) {
879
    return @{$ary};
880
  } else {
881
    $form->{ALL} = $ary;
882
  }
875 883
}
876 884

  
877 885
sub get_language {
......
2040 2048
  }
2041 2049
  $sth->finish();
2042 2050

  
2043
  foreach my $unit (keys(%{$units})) {
2044
    ($units->{$unit}->{"${prefix}base_unit"}, $units->{$unit}->{"${prefix}factor"}) = AM->get_base_unit($units, $unit);
2051
  my $query_lang = "SELECT id, template_code FROM language ORDER BY description";
2052
  $sth = $dbh->prepare($query_lang);
2053
  $sth->execute() || $form->dberror($query_lang);
2054
  my @languages;
2055
  while ($ref = $sth->fetchrow_hashref()) {
2056
    push(@languages, $ref);
2057
  }
2058
  $sth->finish();
2059

  
2060
  $query_lang = "SELECT ul.localized, ul.localized_plural, l.id, l.template_code " .
2061
    "FROM units_language ul " .
2062
    "LEFT JOIN language l ON ul.language_id = l.id " .
2063
    "WHERE ul.unit = ?";
2064
  $sth = $dbh->prepare($query_lang);
2065

  
2066
  foreach my $unit (values(%{$units})) {
2067
    ($unit->{"${prefix}base_unit"}, $unit->{"${prefix}factor"}) = AM->get_base_unit($units, $unit->{"name"});
2068

  
2069
    $unit->{"LANGUAGES"} = {};
2070
    foreach my $lang (@languages) {
2071
      $unit->{"LANGUAGES"}->{$lang->{"template_code"}} = { "template_code" => $lang->{"template_code"} };
2072
    }
2073

  
2074
    $sth->execute($unit->{"name"}) || $form->dberror($query_lang . " (" . $unit->{"name"} . ")");
2075
    while ($ref = $sth->fetchrow_hashref()) {
2076
      map({ $unit->{"LANGUAGES"}->{$ref->{"template_code"}}->{$_} = $ref->{$_} } keys(%{$ref}));
2077
    }
2045 2078
  }
2079
  $sth->finish();
2046 2080

  
2047 2081
  $dbh->disconnect();
2048 2082

  
......
2051 2085
  return $units;
2052 2086
}
2053 2087

  
2088
sub translate_units {
2089
  $main::lxdebug->enter_sub();
2090

  
2091
  my ($self, $form, $template_code, $unit, $amount) = @_;
2092

  
2093
  my $units = $self->retrieve_units(\%main::myconfig, $form);
2094

  
2095
  my $h = $units->{$unit}->{"LANGUAGES"}->{$template_code};
2096
  $main::lxdebug->dump(0, "klaus", $h);
2097
  my $new_unit = $unit;
2098
  if ($h) {
2099
    if (($amount != 1) && $h->{"localized_plural"}) {
2100
      $new_unit = $h->{"localized_plural"};
2101
    } elsif ($h->{"localized"}) {
2102
      $new_unit = $h->{"localized"};
2103
    }
2104
  }
2105

  
2106
  $main::lxdebug->leave_sub();
2107

  
2108
  return $new_unit;
2109
}
2110

  
2054 2111
sub units_in_use {
2055 2112
  $main::lxdebug->enter_sub();
2056 2113

  
......
2142 2199
sub add_unit {
2143 2200
  $main::lxdebug->enter_sub();
2144 2201

  
2145
  my ($self, $myconfig, $form, $name, $base_unit, $factor, $type) = @_;
2202
  my ($self, $myconfig, $form, $name, $base_unit, $factor, $type, $languages) = @_;
2146 2203

  
2147
  my $dbh = $form->dbconnect($myconfig);
2204
  my $dbh = $form->dbconnect_noauto($myconfig);
2148 2205

  
2149 2206
  my $query = "INSERT INTO units (name, base_unit, factor, type) VALUES (?, ?, ?, ?)";
2150 2207
  $dbh->do($query, undef, $name, $base_unit, $factor, $type) || $form->dberror($query . " ($name, $base_unit, $factor, $type)");
2208

  
2209
  if ($languages) {
2210
    $query = "INSERT INTO units_language (unit, language_id, localized, localized_plural) VALUES (?, ?, ?, ?)";
2211
    my $sth = $dbh->prepare($query);
2212
    foreach my $lang (@{$languages}) {
2213
      my @values = ($name, $lang->{"id"}, $lang->{"localized"}, $lang->{"localized_plural"});
2214
      $sth->execute(@values) || $form->dberror($query . " (" . join(", ", @values) . ")");
2215
    }
2216
    $sth->finish();
2217
  }
2218

  
2219
  $dbh->commit();
2151 2220
  $dbh->disconnect();
2152 2221

  
2153 2222
  $main::lxdebug->leave_sub();
......
2162 2231

  
2163 2232
  my ($base_unit, $unit, $sth, $query);
2164 2233

  
2234
  $query = "DELETE FROM units_language";
2235
  $dbh->do($query) || $form->dberror($query);
2236

  
2165 2237
  if ($delete_units && (0 != scalar(@{$delete_units}))) {
2166
    $query = "DELETE FROM units WHERE name = ?";
2167
    $sth = $dbh->prepare($query);
2168
    map({ $sth->execute($_) || $form->dberror($query . " ($_)"); } @{$delete_units});
2169
    $sth->finish();
2238
    $query = "DELETE FROM units WHERE name = (";
2239
    map({ $query .= "?," } @{$delete_units});
2240
    substr($query, -1, 1) = ")";
2241
    $dbh->do($query, undef, @{$delete_units}) || $form->dberror($query . " ($_)");
2170 2242
  }
2171 2243

  
2172 2244
  $query = "UPDATE units SET name = ?, base_unit = ?, factor = ? WHERE name = ?";
2173 2245
  $sth = $dbh->prepare($query);
2174 2246

  
2247
  my $query_lang = "INSERT INTO units_language (unit, language_id, localized, localized_plural) VALUES (?, ?, ?, ?)";
2248
  my $sth_lang = $dbh->prepare($query_lang);
2249

  
2175 2250
  foreach $unit (values(%{$units})) {
2176 2251
    $unit->{"depth"} = 0;
2177 2252
    my $base_unit = $unit;
......
2182 2257
  }
2183 2258

  
2184 2259
  foreach $unit (sort({ $a->{"depth"} <=> $b->{"depth"} } values(%{$units}))) {
2260
    if ($unit->{"LANGUAGES"}) {
2261
      foreach my $lang (@{$unit->{"LANGUAGES"}}) {
2262
        next unless ($lang->{"id"} && $lang->{"localized"});
2263
        my @values = ($unit->{"name"}, $lang->{"id"}, $lang->{"localized"}, $lang->{"localized_plural"});
2264
        $sth_lang->execute(@values) || $form->dberror($query_lang . " (" . join(", ", @values) . ")");
2265
      }
2266
    }
2267

  
2185 2268
    next if ($unit->{"unchanged_unit"});
2186 2269

  
2187 2270
    my @values = ($unit->{"name"}, $unit->{"base_unit"}, $unit->{"factor"}, $unit->{"old_name"});
......
2189 2272
  }
2190 2273

  
2191 2274
  $sth->finish();
2275
  $sth_lang->finish();
2192 2276
  $dbh->commit();
2193 2277
  $dbh->disconnect();
2194 2278

  

Auch abrufbar als: Unified diff