1 #$Header: /home/cvs/cvsroot/freeside/rt/lib/RT/Record.pm,v 1.1 2002-08-12 06:17:07 ivan Exp $
5 RT::Record - Base class for RT record objects
15 ok (require RT::Record);
25 use DBIx::SearchBuilder::Record::Cachable;
29 @ISA= qw(DBIx::SearchBuilder::Record::Cachable);
35 $self->_MyCurrentUser(@_);
45 The primary keys for RT classes is 'id'
56 # {{{ sub _MyCurrentUser
61 $self->CurrentUser(@_);
62 if(!defined($self->CurrentUser)) {
65 $RT::Logger->err("$self was created without a CurrentUser\n");
83 my $now = new RT::Date($self->CurrentUser);
84 $now->Set(Format=> 'unix', Value => time);
85 push @_, 'Created', $now->ISO()
86 if ($self->_Accessible('Created', 'auto'));
89 push @_, 'Creator', $self->{'user'}->id
90 if $self->_Accessible('Creator', 'auto');
92 push @_, 'LastUpdated', $now->ISO()
93 if ($self->_Accessible('LastUpdated', 'auto'));
95 push @_, 'LastUpdatedBy', $self->{'user'}->id
96 if $self->_Accessible('LastUpdatedBy', 'auto');
100 my $id = $self->SUPER::Create(@_);
117 Override DBIx::SearchBuilder::LoadByCols to do case-insensitive loads if the
126 # If this database is case sensitive we need to uncase objects for
128 if ($self->_Handle->CaseSensitive) {
130 foreach my $key (keys %hash) {
131 # If we've been passed an empty value, we can't do the lookup.
132 # We don't need to explicitly downcase integers or an id.
133 if ($key =~ '^id$' || $hash{$key} =~/^\d+$/ || !defined ($hash{$key}) ) {
134 $newhash{$key} = $hash{$key};
137 $newhash{"lower(".$key.")"} = lc($hash{$key});
140 $self->SUPER::LoadByCols(%newhash);
143 $self->SUPER::LoadByCols(%hash);
152 # There is room for optimizations in most of those subs:
158 my $obj = new RT::Date($self->CurrentUser);
160 $obj->Set(Format => 'sql', Value => $self->LastUpdated);
170 my $obj = new RT::Date($self->CurrentUser);
172 $obj->Set(Format => 'sql', Value => $self->Created);
182 # TODO: This should be deprecated
186 return($self->CreatedObj->AgeAsString());
190 # {{{ LastUpdatedAsString
192 # TODO this should be deprecated
194 sub LastUpdatedAsString {
196 if ($self->LastUpdated) {
197 return ($self->LastUpdatedObj->AsString());
206 # {{{ CreatedAsString
208 # TODO This should be deprecated
210 sub CreatedAsString {
212 return ($self->CreatedObj->AsString());
216 # {{{ LongSinceUpdateAsString
218 # TODO This should be deprecated
220 sub LongSinceUpdateAsString {
222 if ($self->LastUpdated) {
224 return ($self->LastUpdatedObj->AgeAsString());
239 my %args = ( Field => undef,
245 #if the user is trying to modify the record
246 if ((!defined ($args{'Field'})) || (!defined ($args{'Value'}))) {
250 $self->_SetLastUpdated();
251 $self->SUPER::_Set(Field => $args{'Field'},
252 Value => $args{'Value'},
253 IsSQL => $args{'IsSQL'});
259 # {{{ sub _SetLastUpdated
261 =head2 _SetLastUpdated
263 This routine updates the LastUpdated and LastUpdatedBy columns of the row in question
264 It takes no options. Arguably, this is a bug
268 sub _SetLastUpdated {
271 my $now = new RT::Date($self->CurrentUser);
274 if ($self->_Accessible('LastUpdated','auto')) {
275 my ($msg, $val) = $self->__Set( Field => 'LastUpdated',
278 if ($self->_Accessible('LastUpdatedBy','auto')) {
279 my ($msg, $val) = $self->__Set( Field => 'LastUpdatedBy',
280 Value => $self->CurrentUser->id);
290 Returns an RT::User object with the RT account of the creator of this row
296 unless (exists $self->{'CreatorObj'}) {
298 $self->{'CreatorObj'} = RT::User->new($self->CurrentUser);
299 $self->{'CreatorObj'}->Load($self->Creator);
301 return($self->{'CreatorObj'});
305 # {{{ sub LastUpdatedByObj
307 =head2 LastUpdatedByObj
309 Returns an RT::User object of the last user to touch this object
313 sub LastUpdatedByObj {
315 unless (exists $self->{LastUpdatedByObj}) {
316 $self->{'LastUpdatedByObj'}=RT::User->new($self->CurrentUser);
317 $self->{'LastUpdatedByObj'}->Load($self->LastUpdatedBy);
319 return $self->{'LastUpdatedByObj'};
324 # {{{ sub CurrentUser
328 If called with an argument, sets the current user to that user object.
329 This will affect ACL decisions, etc.
330 Returns the current user
338 $self->{'user'} = shift;
340 return ($self->{'user'});