From d6e6c9992e85151ee12b9104bca647ce0e11782b Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sat, 27 Apr 2019 09:11:42 +0200 Subject: History: Only show months and years with logged journeys --- lib/Travelynx.pm | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'lib/Travelynx.pm') diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm index f5fdb47..6434e00 100755 --- a/lib/Travelynx.pm +++ b/lib/Travelynx.pm @@ -1068,6 +1068,47 @@ sub startup { } ); + $self->helper( + 'history_years' => sub { + my ( $self, $uid ) = @_; + $uid //= $self->current_user->{id}, + + my $res = $self->pg->db->select( + 'journeys', + 'distinct extract(year from real_departure) as year', + { user_id => $uid }, + { order_by => { -asc => 'year' } } + ); + + my @ret; + for my $row ( $res->hashes->each ) { + push( @ret, [ $row->{year}, $row->{year} ] ); + } + return @ret; + } + ); + + $self->helper( + 'history_months' => sub { + my ( $self, $uid ) = @_; + $uid //= $self->current_user->{id}, + + my $res = $self->pg->db->select( + 'journeys', + "distinct to_char(real_departure, 'YYYY.MM') as yearmonth", + { user_id => $uid }, + { order_by => { -asc => 'yearmonth' } } + ); + + my @ret; + for my $row ( $res->hashes->each ) { + my ( $year, $month ) = split( qr{[.]}, $row->{yearmonth} ); + push( @ret, [ "${year}/${month}", "${month}.${year}" ] ); + } + return @ret; + } + ); + $self->helper( 'get_oldest_journey_ts' => sub { my ($self) = @_; -- cgit v1.2.3