summaryrefslogtreecommitdiff
path: root/rt/lib/RT/SearchBuilder.pm
diff options
context:
space:
mode:
Diffstat (limited to 'rt/lib/RT/SearchBuilder.pm')
-rw-r--r--rt/lib/RT/SearchBuilder.pm96
1 files changed, 77 insertions, 19 deletions
diff --git a/rt/lib/RT/SearchBuilder.pm b/rt/lib/RT/SearchBuilder.pm
index f6b3571b7..fd0842419 100644
--- a/rt/lib/RT/SearchBuilder.pm
+++ b/rt/lib/RT/SearchBuilder.pm
@@ -1,8 +1,8 @@
# BEGIN BPS TAGGED BLOCK {{{
#
# COPYRIGHT:
-#
-# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
+#
+# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
# <jesse@bestpractical.com>
#
# (Except where explicitly superseded by other copyright notices)
@@ -45,7 +45,6 @@
# those contributions and any derivatives thereof.
#
# END BPS TAGGED BLOCK }}}
-
=head1 NAME
RT::SearchBuilder - a baseclass for RT collection objects
@@ -58,6 +57,11 @@
=head1 METHODS
+=begin testing
+
+ok (require RT::SearchBuilder);
+
+=end testing
=cut
@@ -65,13 +69,13 @@
package RT::SearchBuilder;
use RT::Base;
-use DBIx::SearchBuilder "1.40";
+use DBIx::SearchBuilder "1.50";
use strict;
-use warnings;
-
-use base qw(DBIx::SearchBuilder RT::Base);
+use vars qw(@ISA);
+@ISA = qw(DBIx::SearchBuilder RT::Base);
+# {{{ sub _Init
sub _Init {
my $self = shift;
@@ -84,10 +88,13 @@ sub _Init {
}
$self->SUPER::_Init( 'Handle' => $RT::Handle);
}
+# }}}
+
+# {{{ sub LimitToEnabled
=head2 LimitToEnabled
-Only find items that haven't been disabled
+Only find items that haven\'t been disabled
=cut
@@ -98,6 +105,9 @@ sub LimitToEnabled {
VALUE => '0',
OPERATOR => '=' );
}
+# }}}
+
+# {{{ sub LimitToDisabled
=head2 LimitToDeleted
@@ -114,6 +124,9 @@ sub LimitToDeleted {
VALUE => '1'
);
}
+# }}}
+
+# {{{ sub LimitAttribute
=head2 LimitAttribute PARAMHASH
@@ -127,17 +140,17 @@ If NULL is set, also select rows without the named Attribute.
=cut
-my %Negate = (
- '=' => '!=',
- '!=' => '=',
- '>' => '<=',
- '<' => '>=',
- '>=' => '<',
- '<=' => '>',
- 'LIKE' => 'NOT LIKE',
- 'NOT LIKE' => 'LIKE',
- 'IS' => 'IS NOT',
- 'IS NOT' => 'IS',
+my %Negate = qw(
+ = !=
+ != =
+ > <=
+ < >=
+ >= <
+ <= >
+ LIKE NOT LIKE
+ NOT LIKE LIKE
+ IS IS NOT
+ IS NOT IS
);
sub LimitAttribute {
@@ -204,6 +217,9 @@ sub LimitAttribute {
VALUE => 'NULL',
) if $args{NULL};
}
+# }}}
+
+# {{{ sub LimitCustomField
=head2 LimitCustomField
@@ -262,6 +278,8 @@ sub LimitCustomField {
);
}
+# {{{ sub FindAllRows
+
=head2 FindAllRows
Find all matching rows, regardless of whether they are disabled or not
@@ -272,6 +290,8 @@ sub FindAllRows {
shift->{'find_disabled_rows'} = 1;
}
+# {{{ sub Limit
+
=head2 Limit PARAMHASH
This Limit sub calls SUPER::Limit, but defaults "CASESENSITIVE" to 1, thus
@@ -288,6 +308,10 @@ sub Limit {
return $self->SUPER::Limit(%args);
}
+# }}}
+
+# {{{ sub ItemsOrderBy
+
=head2 ItemsOrderBy
If it has a SortOrder attribute, sort the array by SortOrder.
@@ -311,21 +335,55 @@ sub ItemsOrderBy {
return $items;
}
+# }}}
+
+# {{{ sub ItemsArrayRef
+
=head2 ItemsArrayRef
Return this object's ItemsArray, in the order that ItemsOrderBy sorts
it.
+=begin testing
+
+use_ok(RT::Queues);
+ok(my $queues = RT::Queues->new($RT::SystemUser), 'Created a queues object');
+ok( $queues->UnLimit(),'Unlimited the result set of the queues object');
+my $items = $queues->ItemsArrayRef();
+my @items = @{$items};
+
+ok($queues->NewItem->_Accessible('Name','read'));
+my @sorted = sort {lc($a->Name) cmp lc($b->Name)} @items;
+ok (@sorted, "We have an array of queues, sorted". join(',',map {$_->Name} @sorted));
+
+ok (@items, "We have an array of queues, raw". join(',',map {$_->Name} @items));
+my @sorted_ids = map {$_->id } @sorted;
+my @items_ids = map {$_->id } @items;
+
+is ($#sorted, $#items);
+is ($sorted[0]->Name, $items[0]->Name);
+is ($sorted[-1]->Name, $items[-1]->Name);
+is_deeply(\@items_ids, \@sorted_ids, "ItemsArrayRef sorts alphabetically by name");;
+
+
+=end testing
+
=cut
sub ItemsArrayRef {
my $self = shift;
+ my @items;
+
return $self->ItemsOrderBy($self->SUPER::ItemsArrayRef());
}
+# }}}
+
eval "require RT::SearchBuilder_Vendor";
die $@ if ($@ && $@ !~ qr{^Can't locate RT/SearchBuilder_Vendor.pm});
eval "require RT::SearchBuilder_Local";
die $@ if ($@ && $@ !~ qr{^Can't locate RT/SearchBuilder_Local.pm});
1;
+
+