diff options
Diffstat (limited to 'perllib/FixMyStreet/DB')
-rw-r--r-- | perllib/FixMyStreet/DB/Result/AdminLog.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 12 |
2 files changed, 14 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/DB/Result/AdminLog.pm b/perllib/FixMyStreet/DB/Result/AdminLog.pm index fcf909692..d60915cfc 100644 --- a/perllib/FixMyStreet/DB/Result/AdminLog.pm +++ b/perllib/FixMyStreet/DB/Result/AdminLog.pm @@ -37,6 +37,8 @@ __PACKAGE__->add_columns( { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, "reason", { data_type => "text", default_value => "", is_nullable => 0 }, + "time_spent", + { data_type => "integer", default_value => "0", is_nullable => 0 }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->belongs_to( diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index d3a30db4e..637f4acbf 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -886,6 +886,18 @@ __PACKAGE__->has_many( } ); +sub get_time_spent { + my $self = shift; + my $admin_logs = $self->admin_log_entries->search({}, + { + group_by => 'object_id', + columns => [ + { sum_time_spent => { sum => 'time_spent' } }, + ] + })->single; + return $admin_logs ? $admin_logs->get_column('sum_time_spent') : 0; +} + # we need the inline_constructor bit as we don't inherit from Moose __PACKAGE__->meta->make_immutable( inline_constructor => 0 ); |