source: trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Json/Expire.pm @ 1477

Last change on this file since 1477 was 1477, checked in by nanardon, 9 years ago

Add a summary expiration

File size: 1.6 KB
Line 
1package LATMOS::Accounts::Web::Controller::Json::Expire;
2use Moose;
3use namespace::autoclean;
4
5BEGIN { extends 'Catalyst::Controller'; }
6
7=head1 NAME
8
9LATMOS::Accounts::Web::Controller::Json::Expire - Catalyst Controller
10
11=head1 DESCRIPTION
12
13Catalyst Controller.
14
15=head1 METHODS
16
17=cut
18
19
20=head2 index
21
22=cut
23
24sub index :Path :Args(0) {
25    my ( $self, $c ) = @_;
26
27    my $base = $c->model('Accounts')->db;
28
29    my $graph = {
30        data => [],
31        series => [],
32    };
33
34    my @exists = $base->search_objects('user', 'active=1', 'givenName=*');
35    my %results = $base->attributes_summary_by_object('user', 'expire');
36    my %contrats = $base->attributes_summary_by_object('user', 'contratType');
37   
38    my %dates;
39    foreach my $user (@exists) {
40        if (my $d = $results{$user}) {
41            my $contrat = $contrats{$user}[0] || '(none)';
42            foreach (@{ $results{$user} }) {
43                $_ or next;
44                $_ =~ s/:\d\d\+\d\d$//;
45                $dates{$contrat}{$_} ||= 0;
46                $dates{$contrat}{$_} ++;
47            }
48        }
49    }
50
51    foreach my $contrat (sort keys %dates) {
52        push(@{ $graph->{data} }, [ map { [ $_, $dates{$contrat}{$_} +0 ] } sort { $dates{$contrat}{$b} <=> $dates{$contrat}{$a} } keys %{ $dates{$contrat} } ]);
53        push(@{ $graph->{series} }, { label => $contrat });
54    } 
55   
56    $c->stash->{data} = $graph;
57}
58
59
60
61=encoding utf8
62
63=head1 AUTHOR
64
65Olivier Thauvin,Guyancourt - B1428,+33 1 80285052,
66
67=head1 LICENSE
68
69This library is free software. You can redistribute it and/or modify
70it under the same terms as Perl itself.
71
72=cut
73
74__PACKAGE__->meta->make_immutable;
75
761;
Note: See TracBrowser for help on using the repository browser.