Subject: | patch: add TaskTransaction accessor |
Date: | Mon, 4 Aug 2008 15:01:14 -0800 |
To: | <bugs-Net-Hiveminder [...] rt.cpan.org> |
From: | "Vonnahme, Nathan" <nathan.vonnahme [...] bannerhealth.com> |
I've added an accessor for the TaskTransaction model so I can get at a
task's "last modified" datestamp.
I made a stupid demo script to make sure it works-- it's not a real test
script though; I suppose a real one would use data fixtures/stubs
instead of actually connecting to Hiveminder.
Pardon the use of Date::Manip-- if you have a more favorite module, go
for it!
-n
=head2 get_task_history LOCATOR
Load the transaction history for task LOCATOR.
Returns an array of transactions looking like:
$VAR1 = {
'modified_at' => '2008-07-24 15:38:06',
'type' => 'update',
'id' => '1745040',
'task_id' => '433397',
'created_by' => '463'
};
=cut
sub get_task_history {
my $self = shift;
my $task_id = $self->loc2id(shift);
# see http://hiveminder.com/=/model/BTDT.Model.TaskTransaction
return $self->search( 'TaskTransaction', task_id => $task_id, );
}
=head2 get_task_last_modified LOCATOR
Look up the date/time of the last modification to task LOCATOR.
$lastmod = $hm->get_task_history('GACK'); # '2008-07-24 15:38:06'
This method requires L<Date::Manip>, which is an optional dependency
of Net::Hiveminder. If Date::Manip is unavailable, then this will throw
an error.
B<WARNING:> This is kind of slow.
=cut
sub get_task_last_modified {
my $self = shift;
my $locator = shift;
require Date::Manip;
# get all the transactions
my $transactions = $self->get_task_history($locator);
# explicitly sort chronologically
@$transactions = sort {Date::Manip::Date_Cmp($a->{modified_at},
$b->{modified_at})} @$transactions;
return $transactions->[$#$transactions]{modified_at};
}
--
Nathan Vonnahme, IT Software Engineer at Fairbanks Memorial Hospital
nathan.vonnahme@bannerhealth.com 907-458-5464
1650 Cowles St, Fairbanks, Alaska 99701
Message body is not shown because sender requested not to inline it.
Message body is not shown because sender requested not to inline it.