aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/DB/ResultSet/Comment.pm
blob: 270501efcb745d4968190d64623d8a1e1bb79dd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package FixMyStreet::DB::ResultSet::Comment;
use base 'DBIx::Class::ResultSet';

use strict;
use warnings;

sub to_body {
    my ($rs, $body_restriction) = @_;
    return FixMyStreet::DB::ResultSet::Problem::to_body($rs, $body_restriction);
}


sub timeline {
    my ( $rs, $body_restriction ) = @_;

    my $prefetch = 
        FixMyStreet::App->model('DB')->schema->storage->sql_maker->quote_char ?
        [ qw/user/ ] :
        [];

    return $rs->to_body($body_restriction)->search(
        {
            state => 'confirmed',
            created => { '>=', \"current_timestamp-'7 days'::interval" },
        },
        {
            prefetch => $prefetch,
        }
    );
}

sub summary_count {
    my ( $rs, $body_restriction ) = @_;

    return $rs->to_body($body_restriction)->search(
        undef,
        {
            group_by => ['me.state'],
            select   => [ 'me.state', { count => 'me.id' } ],
            as       => [qw/state state_count/],
            join     => 'problem'
        }
    );
}

1;