[Rt-commit] [svn] r745 - rt/branches/rt-3.3/lib/RT

autrijus at pallas.eruditorum.org autrijus at pallas.eruditorum.org
Mon Apr 26 15:02:49 EDT 2004


Author: autrijus
Date: Mon Apr 26 15:02:48 2004
New Revision: 745

Modified:
   rt/branches/rt-3.3/lib/RT/SearchBuilder.pm
Log:
 ----------------------------------------------------------------------
 r4171 at not:  autrijus | 2004-04-26T18:59:54.608186Z
 
 * correct EMPTY and NULL support for $Tickets->LimitAttribute().
 ----------------------------------------------------------------------


Modified: rt/branches/rt-3.3/lib/RT/SearchBuilder.pm
==============================================================================
--- rt/branches/rt-3.3/lib/RT/SearchBuilder.pm	(original)
+++ rt/branches/rt-3.3/lib/RT/SearchBuilder.pm	Mon Apr 26 15:02:48 2004
@@ -109,14 +109,42 @@
 Takes NAME, OPERATOR and VALUE to find records that has the
 matching Attribute.
 
+If EMPTY is set, also select rows with an empty string as
+Attribute's Content.
+
+If NULL is set, also select rows without the named Attribute.
+
 =cut
 
+my %Negate = qw(
+    =		!=
+    !=		=
+    >		<=
+    <		>=
+    >=		<
+    <=		>
+    LIKE	NOT LIKE
+    NOT LIKE	LIKE
+    IS		IS NOT
+    IS NOT	IS
+);
+
 sub LimitAttribute {
     my ($self, %args) = @_;
+    my $clause = 'ALIAS';
+    my $operator = ($args{OPERATOR} || '=');
+    
+    if ($args{NULL} and exists $args{VALUE}) {
+	$clause = 'LEFTJOIN';
+	$operator = $Negate{$operator};
+    }
+    elsif ($args{NEGATE}) {
+	$operator = $Negate{$operator};
+    }
     
     my $alias = $self->Join(
 	TYPE   => 'left',
-	ALIAS1 => 'main',
+	ALIAS1 => $args{ALIAS} || 'main',
 	FIELD1 => 'id',
 	TABLE2 => 'Attributes',
 	FIELD2 => 'ObjectId'
@@ -126,13 +154,13 @@
     $type =~ s/(?:s|Collection)$//; # XXX - Hack!
 
     $self->Limit(
-	ALIAS	   => $alias,
+	$clause	   => $alias,
 	FIELD      => 'ObjectType',
 	OPERATOR   => '=',
 	VALUE      => $type,
     );
     $self->Limit(
-	ALIAS	   => $alias,
+	$clause	   => $alias,
 	FIELD      => 'Name',
 	OPERATOR   => '=',
 	VALUE      => $args{NAME},
@@ -141,23 +169,29 @@
     return unless exists $args{VALUE};
 
     $self->Limit(
-	ALIAS	   => $alias,
+	$clause	   => $alias,
 	FIELD      => 'Content',
-	OPERATOR   => ($args{OPERATOR} || '='),
+	OPERATOR   => $operator,
 	VALUE      => $args{VALUE},
-	ENTRYAGGREGATOR => 'OR',
     );
 
-    if ($args{EMPTY}) {
-	# Capture rows without the attribute defined by testing IS NULL.
-	$self->Limit(
-	    ALIAS      => $alias,
-	    FIELD      => $_,
-	    OPERATOR   => 'IS',
-	    VALUE      => 'NULL',
-	    ENTRYAGGREGATOR => 'OR',
-	) for qw( ObjectType Name Content );
-    }
+    # Capture rows with the attribute defined as an empty string.
+    $self->Limit(
+	$clause    => $alias,
+	FIELD      => 'Content',
+	OPERATOR   => '=',
+	VALUE      => '',
+	ENTRYAGGREGATOR => $args{NULL} ? 'AND' : 'OR',
+    ) if $args{EMPTY};
+
+    # Capture rows without the attribute defined
+    $self->Limit(
+	%args,
+	ALIAS      => $alias,
+	FIELD	   => 'id',
+	OPERATOR   => ($args{NEGATE} ? 'IS NOT' : 'IS'),
+	VALUE      => 'NULL',
+    ) if $args{NULL};
 }
 # }}}
 


More information about the Rt-commit mailing list