diff options
author | Daniel Friesel <derf@finalrewind.org> | 2020-02-01 16:15:20 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2020-02-01 16:15:20 +0100 |
commit | eb3f4aed05d31509e0544ff29b382759ba31b9c2 (patch) | |
tree | fc863f10184cadba9504092881bfae420e93efd7 /lib/Travelynx.pm | |
parent | 5439dbad343d9db39119cc0168b18bc9c58b195c (diff) |
allow checkin and checkout station to be edited
Diffstat (limited to 'lib/Travelynx.pm')
-rwxr-xr-x | lib/Travelynx.pm | 49 |
1 files changed, 46 insertions, 3 deletions
diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm index 46911d8..aeb09d1 100755 --- a/lib/Travelynx.pm +++ b/lib/Travelynx.pm @@ -43,13 +43,22 @@ sub epoch_to_dt { } sub get_station { - my ($station_name) = @_; + my ( $station_name, $exact_match ) = @_; my @candidates = Travel::Status::DE::IRIS::Stations::get_station($station_name); if ( @candidates == 1 ) { - return $candidates[0]; + if ( not $exact_match ) { + return $candidates[0]; + } + if ( $candidates[0][0] eq $station_name + or $candidates[0][1] eq $station_name + or $candidates[0][2] eq $station_name ) + { + return $candidates[0]; + } + return undef; } return undef; } @@ -187,10 +196,12 @@ sub startup { return { sched_departure => 0x0001, real_departure => 0x0002, + from_station => 0x0004, route => 0x0010, is_cancelled => 0x0020, sched_arrival => 0x0100, real_arrival => 0x0200, + to_station => 0x0400, }; } ); @@ -912,7 +923,39 @@ sub startup { ); eval { - if ( $key eq 'sched_departure' ) { + if ( $key eq 'from_name' ) { + my $from_station = get_station( $value, 1 ); + if ( not $from_station ) { + die("Unbekannter Startbahnhof\n"); + } + $rows = $db->update( + 'journeys', + { + checkin_station_id => $from_station->[2], + edited => $journey->{edited} | 0x0004, + }, + { + id => $journey_id, + } + )->rows; + } + elsif ( $key eq 'to_name' ) { + my $to_station = get_station( $value, 1 ); + if ( not $to_station ) { + die("Unbekannter Zielbahnhof\n"); + } + $rows = $db->update( + 'journeys', + { + checkout_station_id => $to_station->[2], + edited => $journey->{edited} | 0x0400, + }, + { + id => $journey_id, + } + )->rows; + } + elsif ( $key eq 'sched_departure' ) { $rows = $db->update( 'journeys', { |