Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision eaf4d483

Von Moritz Bunkus vor fast 18 Jahren hinzugefügt

  • ID eaf4d4830c5b449170dbef0d0ad5f88863f1e8bd
  • Vorgänger 94fe7579
  • Nachfolger 4b1c7617

Einheiten sortierbar gemacht.

Unterschiede anzeigen:

SL/AM.pm
2284 2284
    push(@{$select}, { "name" => "", "base_unit" => "", "factor" => "", "selected" => "" });
2285 2285
  }
2286 2286

  
2287
  foreach my $unit (sort({ lc($a) cmp lc($b) } keys(%{$units}))) {
2287
  foreach my $unit (sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } keys(%{$units}))) {
2288 2288
    push(@{$select}, { "name" => $unit,
2289 2289
                       "base_unit" => $units->{$unit}->{"base_unit"},
2290 2290
                       "factor" => $units->{$unit}->{"factor"},
......
2303 2303

  
2304 2304
  my $select = "<select name=${name}>";
2305 2305

  
2306
  foreach my $unit (sort({ lc($a) cmp lc($b) } keys(%{$units}))) {
2306
  foreach my $unit (sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } keys(%{$units}))) {
2307 2307
    if (!$convertible_into ||
2308 2308
        ($units->{$convertible_into} &&
2309 2309
         ($units->{$convertible_into}->{"base_unit"} eq $units->{$unit}->{"base_unit"}))) {
......
2324 2324

  
2325 2325
  my $dbh = $form->dbconnect_noauto($myconfig);
2326 2326

  
2327
  my $query = "INSERT INTO units (name, base_unit, factor, type) VALUES (?, ?, ?, ?)";
2328
  $dbh->do($query, undef, $name, $base_unit, $factor, $type) || $form->dberror($query . " ($name, $base_unit, $factor, $type)");
2327
  my $query = qq|SELECT COALESCE(MAX(sortkey), 0) + 1 FROM units|;
2328
  my ($sortkey) = selectrow_query($form, $dbh, $query);
2329

  
2330
  $query = "INSERT INTO units (name, base_unit, factor, type, sortkey) " .
2331
    "VALUES (?, ?, ?, ?, ?)";
2332
  do_query($form, $dbh, $query, $name, $base_unit, $factor, $type, $sortkey);
2329 2333

  
2330 2334
  if ($languages) {
2331 2335
    $query = "INSERT INTO units_language (unit, language_id, localized, localized_plural) VALUES (?, ?, ?, ?)";
......
2401 2405
  $main::lxdebug->leave_sub();
2402 2406
}
2403 2407

  
2408
sub swap_units {
2409
  $main::lxdebug->enter_sub();
2410

  
2411
  my ($self, $myconfig, $form, $dir, $name_1, $unit_type) = @_;
2412

  
2413
  my $dbh = $form->dbconnect_noauto($myconfig);
2414

  
2415
  my $query;
2416

  
2417
  $query = qq|SELECT sortkey FROM units WHERE name = ?|;
2418
  my ($sortkey_1) = selectrow_query($form, $dbh, $query, $name_1);
2419

  
2420
  $query =
2421
    qq|SELECT sortkey FROM units | .
2422
    qq|WHERE sortkey | . ($dir eq "down" ? ">" : "<") . qq| ? AND type = ? | .
2423
    qq|ORDER BY sortkey | . ($dir eq "down" ? "ASC" : "DESC") . qq| LIMIT 1|;
2424
  my ($sortkey_2) = selectrow_query($form, $dbh, $query, $sortkey_1, $unit_type);
2425

  
2426
  $main::lxdebug->message(0, "name1 $name_1 dir $dir sk1 $sortkey_1 sk2 $sortkey_2");
2427

  
2428
  if (defined($sortkey_1)) {
2429
    $query = qq|SELECT name FROM units WHERE sortkey = ${sortkey_2}|;
2430
    my ($name_2) = selectrow_query($form, $dbh, $query);
2431

  
2432
    if (defined($name_2)) {
2433
      $query = qq|UPDATE units SET sortkey = ? WHERE name = ?|;
2434
      my $sth = $dbh->prepare($query);
2435

  
2436
      do_statement($form, $sth, $query, $sortkey_1, $name_2);
2437
      do_statement($form, $sth, $query, $sortkey_2, $name_1);
2438
    }
2439
  }
2440

  
2441
  $dbh->commit();
2442
  $dbh->disconnect();
2443

  
2444
  $main::lxdebug->leave_sub();
2445
}
2446

  
2404 2447
1;

Auch abrufbar als: Unified diff