aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/DB/ResultSet
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/DB/ResultSet')
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Alert.pm38
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Comment.pm27
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Problem.pm30
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm18
4 files changed, 113 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/DB/ResultSet/Alert.pm b/perllib/FixMyStreet/DB/ResultSet/Alert.pm
new file mode 100644
index 000000000..62e6120e4
--- /dev/null
+++ b/perllib/FixMyStreet/DB/ResultSet/Alert.pm
@@ -0,0 +1,38 @@
+package FixMyStreet::DB::ResultSet::Alert;
+use base 'DBIx::Class::ResultSet';
+
+use strict;
+use warnings;
+
+sub timeline_created {
+ my ( $rs, $restriction ) = @_;
+
+ my $prefetch =
+ FixMyStreet::App->model('DB')->schema->storage->sql_maker->quote_char ?
+ [ qw/alert_type user/ ] :
+ [ qw/alert_type/ ];
+
+ return $rs->search(
+ {
+ whensubscribed => { '>=', \"ms_current_timestamp()-'7 days'::interval" },
+ confirmed => 1,
+ %{ $restriction },
+ },
+ {
+ prefetch => $prefetch,
+ }
+ );
+}
+
+sub timeline_disabled {
+ my ( $rs, $restriction ) = @_;
+
+ return $rs->search(
+ {
+ whendisabled => { '>=', \"ms_current_timestamp()-'7 days'::interval" },
+ %{ $restriction },
+ },
+ );
+}
+
+1;
diff --git a/perllib/FixMyStreet/DB/ResultSet/Comment.pm b/perllib/FixMyStreet/DB/ResultSet/Comment.pm
new file mode 100644
index 000000000..4719c7a24
--- /dev/null
+++ b/perllib/FixMyStreet/DB/ResultSet/Comment.pm
@@ -0,0 +1,27 @@
+package FixMyStreet::DB::ResultSet::Comment;
+use base 'DBIx::Class::ResultSet';
+
+use strict;
+use warnings;
+
+sub timeline {
+ my ( $rs, $restriction ) = @_;
+
+ my $prefetch =
+ FixMyStreet::App->model('DB')->schema->storage->sql_maker->quote_char ?
+ [ qw/user/ ] :
+ [];
+
+ return $rs->search(
+ {
+ state => 'confirmed',
+ created => { '>=', \"ms_current_timestamp()-'7 days'::interval" },
+ %{ $restriction },
+ },
+ {
+ prefetch => $prefetch,
+ }
+ );
+}
+
+1;
diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
new file mode 100644
index 000000000..8d798a7c1
--- /dev/null
+++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
@@ -0,0 +1,30 @@
+package FixMyStreet::DB::ResultSet::Problem;
+use base 'DBIx::Class::ResultSet';
+
+use strict;
+use warnings;
+
+sub timeline {
+ my ( $rs, $restriction ) = @_;
+
+ my $prefetch =
+ FixMyStreet::App->model('DB')->schema->storage->sql_maker->quote_char ?
+ [ qw/user/ ] :
+ [];
+
+ return $rs->search(
+ {
+ -or => {
+ created => { '>=', \"ms_current_timestamp()-'7 days'::interval" },
+ confirmed => { '>=', \"ms_current_timestamp()-'7 days'::interval" },
+ whensent => { '>=', \"ms_current_timestamp()-'7 days'::interval" },
+ %{ $restriction },
+ }
+ },
+ {
+ prefetch => $prefetch,
+ }
+ );
+}
+
+1;
diff --git a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm
index 80f62f495..1f5e26197 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm
@@ -112,4 +112,22 @@ sub send_questionnaires_period {
}
}
+sub timeline {
+ my ( $rs, $restriction ) = @_;
+
+ return $rs->search(
+ {
+ -or => {
+ whenanswered => { '>=', \"ms_current_timestamp()-'7 days'::interval" },
+ 'me.whensent' => { '>=', \"ms_current_timestamp()-'7 days'::interval" },
+ },
+ %{ $restriction },
+ },
+ {
+ -select => [qw/me.*/],
+ prefetch => [qw/problem/],
+ }
+ );
+}
+
1;