3 # Copyright (c) 1996-2003 Jesse Vincent <jesse@bestpractical.com>
5 # (Except where explictly superceded by other copyright notices)
7 # This work is made available to you under the terms of Version 2 of
8 # the GNU General Public License. A copy of that license should have
9 # been provided with this software, but in any event can be snarfed
12 # This work is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
17 # Unless otherwise specified, all modifications, corrections or
18 # extensions to this work which alter its source code become the
19 # property of Best Practical Solutions, LLC when submitted for
20 # inclusion in the work.
26 RT::SearchBuilder - a baseclass for RT collection objects
38 ok (require RT::SearchBuilder);
45 package RT::SearchBuilder;
48 use DBIx::SearchBuilder;
52 @ISA = qw(DBIx::SearchBuilder RT::Base);
58 $self->{'user'} = shift;
59 unless(defined($self->CurrentUser)) {
61 Carp::confess("$self was created without a CurrentUser");
62 $RT::Logger->err("$self was created without a CurrentUser");
65 $self->SUPER::_Init( 'Handle' => $RT::Handle);
69 # {{{ sub LimitToEnabled
73 Only find items that haven\'t been disabled
80 $self->Limit( FIELD => 'Disabled',
86 # {{{ sub LimitToDisabled
90 Only find items that have been deleted.
97 $self->{'find_disabled_rows'} = 1;
98 $self->Limit( FIELD => 'Disabled',
105 # {{{ sub FindAllRows
109 Find all matching rows, regardless of whether they are disabled or not
114 shift->{'find_disabled_rows'} = 1;
119 =head2 Limit PARAMHASH
121 This Limit sub calls SUPER::Limit, but defaults "CASESENSITIVE" to 1, thus
122 making sure that by default lots of things don't do extra work trying to
123 match lower(colname) agaist lc($val);
129 my %args = ( CASESENSITIVE => 1,
132 return $self->SUPER::Limit(%args);
137 # {{{ sub ItemsArrayRef
141 Return this object's ItemsArray.
142 If it has a SortOrder attribute, sort the array by SortOrder.
143 Otherwise, if it has a "Name" attribute, sort alphabetically by Name
144 Otherwise, just give up and return it in the order it came from the db.
150 ok(my $queues = RT::Queues->new($RT::SystemUser), 'Created a queues object');
151 ok( $queues->UnLimit(),'Unlimited the result set of the queues object');
152 my $items = $queues->ItemsArrayRef();
153 my @items = @{$items};
155 ok($queues->NewItem->_Accessible('Name','read'));
156 my @sorted = sort {lc($a->Name) cmp lc($b->Name)} @items;
157 ok (@sorted, "We have an array of queues, sorted". join(',',map {$_->Name} @sorted));
159 ok (@items, "We have an array of queues, raw". join(',',map {$_->Name} @items));
160 my @sorted_ids = map {$_->id } @sorted;
161 my @items_ids = map {$_->id } @items;
163 is ($#sorted, $#items);
164 is ($sorted[0]->Name, $items[0]->Name);
165 is ($sorted[-1]->Name, $items[-1]->Name);
166 is_deeply(\@items_ids, \@sorted_ids, "ItemsArrayRef sorts alphabetically by name");;
177 if ($self->NewItem()->_Accessible('SortOrder','read')) {
178 @items = sort { $a->SortOrder <=> $b->SortOrder } @{$self->SUPER::ItemsArrayRef()};
180 elsif ($self->NewItem()->_Accessible('Name','read')) {
181 @items = sort { lc($a->Name) cmp lc($b->Name) } @{$self->SUPER::ItemsArrayRef()};
184 @items = @{$self->SUPER::ItemsArrayRef()};
193 eval "require RT::SearchBuilder_Vendor";
194 die $@ if ($@ && $@ !~ qr{^Can't locate RT/SearchBuilder_Vendor.pm});
195 eval "require RT::SearchBuilder_Local";
196 die $@ if ($@ && $@ !~ qr{^Can't locate RT/SearchBuilder_Local.pm});