1 | package LATMOS::Accounts::Web::Controller::About; |
---|
2 | use strict; |
---|
3 | use warnings; |
---|
4 | use base 'Catalyst::Controller'; |
---|
5 | |
---|
6 | use POSIX; |
---|
7 | use DateTime; |
---|
8 | use Date::Calc; |
---|
9 | use Date::Parse; |
---|
10 | |
---|
11 | =head1 NAME |
---|
12 | |
---|
13 | LATMOS::Accounts::Web::Controller::About - Catalyst Controller |
---|
14 | |
---|
15 | =head1 DESCRIPTION |
---|
16 | |
---|
17 | Catalyst Controller. |
---|
18 | |
---|
19 | =head1 METHODS |
---|
20 | |
---|
21 | =cut |
---|
22 | |
---|
23 | |
---|
24 | =head2 index |
---|
25 | |
---|
26 | =cut |
---|
27 | |
---|
28 | sub index :Path :Args(0) { |
---|
29 | my ( $self, $c ) = @_; |
---|
30 | |
---|
31 | $c->stash->{page}{title} = "A propos..."; |
---|
32 | |
---|
33 | if ($c->user) { |
---|
34 | my $ouser = $c->model('Accounts')->db->get_object( |
---|
35 | 'user', |
---|
36 | $c->user->{username}, |
---|
37 | ); |
---|
38 | |
---|
39 | my @cd = split('-', DateTime->from_epoch( |
---|
40 | epoch => str2time( |
---|
41 | $ouser->get_attributes('create'), |
---|
42 | ) |
---|
43 | )->ymd('-')); |
---|
44 | my @now = split('-', DateTime->now()->ymd('-')); |
---|
45 | |
---|
46 | my ($Dy,$Dm,$Dd) = Date::Calc::N_Delta_YMD(@cd, @now); |
---|
47 | $c->stash->{accountExists} = join(', ', |
---|
48 | ($Dy ? $c->loc('[_1] years', $Dy) : ()), |
---|
49 | ($Dm ? $c->loc('[_1] months', $Dm) : ()), |
---|
50 | ($Dd ? $c->loc('[_1] days', $Dd) : ()), |
---|
51 | ); |
---|
52 | |
---|
53 | if (my $expire = $ouser->get_attributes('expire')) { |
---|
54 | my @ed = split('-', DateTime->from_epoch( |
---|
55 | epoch => str2time( |
---|
56 | $expire |
---|
57 | ) |
---|
58 | )->ymd('-')); |
---|
59 | |
---|
60 | my ($Dy,$Dm,$Dd) = Date::Calc::N_Delta_YMD(@now, @ed); |
---|
61 | $c->stash->{accountExpire} = join(', ', |
---|
62 | ($Dy ? $c->loc('[_1] years', $Dy) : ()), |
---|
63 | ($Dm ? $c->loc('[_1] months', $Dm) : ()), |
---|
64 | ($Dd ? $c->loc('[_1] days', $Dd) : ()), |
---|
65 | ); |
---|
66 | } |
---|
67 | } |
---|
68 | } |
---|
69 | |
---|
70 | sub echo : XMLRPC { |
---|
71 | my ( $self, $c, @args ) = @_; |
---|
72 | return RPC::XML::fault->new( 400, "No input!" |
---|
73 | ) unless @args; |
---|
74 | return join ' ', @args; |
---|
75 | } |
---|
76 | |
---|
77 | =head1 AUTHOR |
---|
78 | |
---|
79 | Olivier Thauvin |
---|
80 | |
---|
81 | =head1 LICENSE |
---|
82 | |
---|
83 | This library is free software. You can redistribute it and/or modify |
---|
84 | it under the same terms as Perl itself. |
---|
85 | |
---|
86 | =cut |
---|
87 | |
---|
88 | 1; |
---|