summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2019-04-27 09:11:42 +0200
committerDaniel Friesel <derf@finalrewind.org>2019-04-27 09:11:42 +0200
commitd6e6c9992e85151ee12b9104bca647ce0e11782b (patch)
tree4bddfc005f4694aff7724f3479cac2e0bd4f5032 /lib
parent8c1888263ba1b79c86c677b8f7f665b7342b04c2 (diff)
History: Only show months and years with logged journeys
Diffstat (limited to 'lib')
-rwxr-xr-xlib/Travelynx.pm41
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm
index f5fdb47..6434e00 100755
--- a/lib/Travelynx.pm
+++ b/lib/Travelynx.pm
@@ -1069,6 +1069,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) = @_;