#
# COPYRIGHT:
#
-# This software is Copyright (c) 1996-2013 Best Practical Solutions, LLC
+# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC
# <sales@bestpractical.com>
#
# (Except where explicitly superseded by other copyright notices)
use strict;
use warnings;
-
+use Scalar::Util 'blessed';
use base 'RT::Record';
$self->FriendlyType));
}
- # XXX: Remove this restriction once we support lists and cascaded selects
- if ( $self->BasedOnObj->id and $type =~ /List/ ) {
- return (0, $self->loc("We can't currently render as a List when basing categories on another custom field. Please use another render type."));
- }
-
return $self->_Set( Field => 'RenderType', Value => $type, @_ );
}
sub LookupTypes {
my $self = shift;
- return keys %FRIENDLY_OBJECT_TYPES;
+ return sort keys %FRIENDLY_OBJECT_TYPES;
}
my @FriendlyObjectTypes = (
return ( $self->loc( $FriendlyObjectTypes[$#types], @types ) );
}
+=head1 RecordClassFromLookupType
+
+Returns the type of Object referred to by ObjectCustomFields' ObjectId column
+
+Optionally takes a LookupType to use instead of using the value on the loaded
+record. In this case, the method may be called on the class instead of an
+object.
+
+=cut
+
sub RecordClassFromLookupType {
my $self = shift;
- my ($class) = ($self->LookupType =~ /^([^-]+)/);
+ my $type = shift || $self->LookupType;
+ my ($class) = ($type =~ /^([^-]+)/);
unless ( $class ) {
- $RT::Logger->error(
- "Custom Field #". $self->id
- ." has incorrect LookupType '". $self->LookupType ."'"
- );
+ if (blessed($self) and $self->LookupType eq $type) {
+ $RT::Logger->error(
+ "Custom Field #". $self->id
+ ." has incorrect LookupType '$type'"
+ );
+ } else {
+ RT->Logger->error("Invalid LookupType passed as argument: $type");
+ }
+ return undef;
+ }
+ return $class;
+}
+
+=head1 ObjectTypeFromLookupType
+
+Returns the ObjectType used in ObjectCustomFieldValues rows for this CF
+
+Optionally takes a LookupType to use instead of using the value on the loaded
+record. In this case, the method may be called on the class instead of an
+object.
+
+=cut
+
+sub ObjectTypeFromLookupType {
+ my $self = shift;
+ my $type = shift || $self->LookupType;
+ my ($class) = ($type =~ /([^-]+)$/);
+ unless ( $class ) {
+ if (blessed($self) and $self->LookupType eq $type) {
+ $RT::Logger->error(
+ "Custom Field #". $self->id
+ ." has incorrect LookupType '$type'"
+ );
+ } else {
+ RT->Logger->error("Invalid LookupType passed as argument: $type");
+ }
return undef;
}
return $class;
}
}
- if (my $canonicalizer = $self->can('_CanonicalizeValue'.$self->Type)) {
- $canonicalizer->($self, \%args);
- }
-
-
-
my $newval = RT::ObjectCustomFieldValue->new( $self->CurrentUser );
my ($val, $msg) = $newval->Create(
ObjectType => ref($obj),
}
+sub _CanonicalizeValue {
+ my $self = shift;
+ my $args = shift;
+
+ my $type = $self->_Value('Type');
+ return 1 unless $type;
+
+ my $method = '_CanonicalizeValue'. $type;
+ return 1 unless $self->can($method);
+ $self->$method($args);
+}
sub _CanonicalizeValueDateTime {
my $self = shift;
$DateObj->Set( Format => 'unknown',
Value => $args->{'Content'} );
$args->{'Content'} = $DateObj->ISO;
+ return 1;
}
# For date, we need to store Content as ISO date
Value => $args->{'Content'},
);
$args->{'Content'} = $DateObj->Date( Timezone => 'user' );
+ return 1;
+}
+
+sub _CanonicalizeValueIPAddress {
+ my $self = shift;
+ my $args = shift;
+
+ $args->{Content} = RT::ObjectCustomFieldValue->ParseIP( $args->{Content} );
+ return (0, $self->loc("Content is not a valid IP address"))
+ unless $args->{Content};
+ return 1;
+}
+
+sub _CanonicalizeValueIPAddressRange {
+ my $self = shift;
+ my $args = shift;
+
+ my $content = $args->{Content};
+ $content .= "-".$args->{LargeContent} if $args->{LargeContent};
+
+ ($args->{Content}, $args->{LargeContent})
+ = RT::ObjectCustomFieldValue->ParseIPRange( $content );
+
+ $args->{ContentType} = 'text/plain';
+ return (0, $self->loc("Content is not a valid IP address range"))
+ unless $args->{Content};
+ return 1;
}
=head2 MatchPattern STRING