From aaeb81a5d230ca556fa950d0f9be0b98e85effcf Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Sun, 1 Oct 2023 07:11:58 +0200 Subject: store related stations; respect them when looking up connections --- lib/Travelynx/Model/Stations.pm | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'lib/Travelynx/Model/Stations.pm') diff --git a/lib/Travelynx/Model/Stations.pm b/lib/Travelynx/Model/Stations.pm index ecd8adb..147219f 100644 --- a/lib/Travelynx/Model/Stations.pm +++ b/lib/Travelynx/Model/Stations.pm @@ -50,6 +50,41 @@ sub add_or_update { ); } +sub add_meta { + my ( $self, %opt ) = @_; + my $db = $opt{db} // $self->{pg}->db; + my $eva = $opt{eva}; + my @meta = @{ $opt{meta} }; + + for my $meta (@meta) { + if ( $meta != $eva ) { + $db->insert( + 'related_stations', + { + eva => $eva, + meta => $meta + }, + { on_conflict => undef } + ); + } + } +} + +sub get_meta { + my ( $self, %opt ) = @_; + my $db = $opt{db} // $self->{pg}->db; + my $eva = $opt{eva}; + + my $res = $db->select( 'related_stations', ['meta'], { eva => $eva } ); + my @ret; + + while ( my $row = $res->hash ) { + push( @ret, $row->{meta} ); + } + + return @ret; +} + sub get_for_autocomplete { my ($self) = @_; -- cgit v1.2.3