[Rt-commit] [svn] r1142 - in rt/branches/rt-3.1: html/Search lib/RT
alexmv at pallas.eruditorum.org
alexmv at pallas.eruditorum.org
Thu Jun 24 16:50:12 EDT 2004
Author: alexmv
Date: Thu Jun 24 16:50:11 2004
New Revision: 1142
Modified:
rt/branches/rt-3.1/html/Search/Results.html
rt/branches/rt-3.1/lib/RT/SearchBuilder.pm
rt/branches/rt-3.1/lib/RT/Tickets_Overlay.pm
Log:
* Tickets::ItemsArrayRef needs to exist, and step though the contents to
ensure access control; code dropped back in
* However, it should provide ordered results; factor out sorting from
overridden RT::SearchBuilder's ItemsArrayRef into ItemsOrderBy and
call that in Tickets::ItemsArrayRef
* Invalidate ItemMap if ItemsArray is invalidated
Modified: rt/branches/rt-3.1/html/Search/Results.html
==============================================================================
--- rt/branches/rt-3.1/html/Search/Results.html (original)
+++ rt/branches/rt-3.1/html/Search/Results.html Thu Jun 24 16:50:11 2004
@@ -57,9 +57,10 @@
if ($OrderBy ne $session{'CurrentSearchHash'}->{'OrderBy'}
or $Order ne $session{'CurrentSearchHash'}->{'Order'}) {
- $session{'CurrentSearchHash'}->{'OrderBy'} = $OrderBy;
- $session{'CurrentSearchHash'}->{'Order'} = $Order;
- undef $session{'tickets'}->{'item_map'};
+ $session{'CurrentSearchHash'}->{'OrderBy'} = $OrderBy;
+ $session{'CurrentSearchHash'}->{'Order'} = $Order;
+ # Invalidate the ordering cache
+ undef $session{'tickets'}->{'items_array'};
}
Modified: rt/branches/rt-3.1/lib/RT/SearchBuilder.pm
==============================================================================
--- rt/branches/rt-3.1/lib/RT/SearchBuilder.pm (original)
+++ rt/branches/rt-3.1/lib/RT/SearchBuilder.pm Thu Jun 24 16:50:11 2004
@@ -172,7 +172,7 @@
=cut
sub FindAllRows {
- shift->{'find_disabled_rows'} = 1;
+ shift->{'find_disabled_rows'} = 1;
}
# {{{ sub Limit
@@ -186,24 +186,48 @@
=cut
sub Limit {
- my $self = shift;
- my %args = ( CASESENSITIVE => 1,
- @_ );
+ my $self = shift;
+ my %args = ( CASESENSITIVE => 1,
+ @_ );
- return $self->SUPER::Limit(%args);
+ return $self->SUPER::Limit(%args);
}
# }}}
-# {{{ sub ItemsArrayRef
+# {{{ sub ItemsOrderBy
-=item ItemsArrayRef
+=item ItemsOrderBy
-Return this object's ItemsArray.
If it has a SortOrder attribute, sort the array by SortOrder.
Otherwise, if it has a "Name" attribute, sort alphabetically by Name
-Otherwise, just give up and return it in the order it came from the db.
+Otherwise, just give up and return it in the order it came from the
+db.
+
+=cut
+
+sub ItemsOrderBy {
+ my $self = shift;
+ my $items = shift;
+
+ if ($self->NewItem()->_Accessible('SortOrder','read')) {
+ $items = [ sort { $a->SortOrder <=> $b->SortOrder } @{$items} ];
+ }
+ elsif ($self->NewItem()->_Accessible('Name','read')) {
+ $items = [ sort { lc($a->Name) cmp lc($b->Name) } @{$items} ];
+ }
+
+ return $items;
+}
+# }}}
+
+# {{{ sub ItemsArrayRef
+
+=item ItemsArrayRef
+
+Return this object's ItemsArray, in the order that ItemsOrderBy sorts
+it.
=begin testing
@@ -235,18 +259,7 @@
my $self = shift;
my @items;
- if ($self->NewItem()->_Accessible('SortOrder','read')) {
- @items = sort { $a->SortOrder <=> $b->SortOrder } @{$self->SUPER::ItemsArrayRef()};
- }
- elsif ($self->NewItem()->_Accessible('Name','read')) {
- @items = sort { lc($a->Name) cmp lc($b->Name) } @{$self->SUPER::ItemsArrayRef()};
- }
- else {
- @items = @{$self->SUPER::ItemsArrayRef()};
- }
-
- return(\@items);
-
+ return $self->ItemsOrderBy($self->SUPER::ItemsArrayRef());
}
# }}}
Modified: rt/branches/rt-3.1/lib/RT/Tickets_Overlay.pm
==============================================================================
--- rt/branches/rt-3.1/lib/RT/Tickets_Overlay.pm (original)
+++ rt/branches/rt-3.1/lib/RT/Tickets_Overlay.pm Thu Jun 24 16:50:11 2004
@@ -1781,6 +1781,32 @@
# }}}
+# {{{ sub ItemsArrayRef
+
+=head2 ItemsArrayRef
+
+Returns a reference to the set of all items found in this search
+
+=cut
+
+sub ItemsArrayRef {
+ my $self = shift;
+ my @items;
+
+ unless ( $self->{'items_array'} ) {
+
+ my $placeholder = $self->_ItemsCounter;
+ $self->GotoFirstItem();
+ while ( my $item = $self->Next ) {
+ push ( @{ $self->{'items_array'} }, $item );
+ }
+ $self->GotoItem($placeholder);
+ $self->{'items_array'} = $self->ItemsOrderBy($self->{'items_array'});
+ }
+ return ( $self->{'items_array'} );
+}
+# }}}
+
# {{{ sub Next
sub Next {
my $self = shift;
@@ -2063,15 +2089,15 @@
delete $self->{'item_map'};
if ($items->[0]) {
- $self->{'item_map'}->{'first'} = $items->[0]->EffectiveId;
- while (my $item = shift @$items ) {
- my $id = $item->EffectiveId;
- $self->{'item_map'}->{$id}->{'defined'} = 1;
- $self->{'item_map'}->{$id}->{prev} = $prev;
- $self->{'item_map'}->{$id}->{next} = $items->[0]->EffectiveId if ($items->[0]);
- $prev = $id;
- }
- $self->{'item_map'}->{'last'} = $prev;
+ $self->{'item_map'}->{'first'} = $items->[0]->EffectiveId;
+ while (my $item = shift @$items ) {
+ my $id = $item->EffectiveId;
+ $self->{'item_map'}->{$id}->{'defined'} = 1;
+ $self->{'item_map'}->{$id}->{prev} = $prev;
+ $self->{'item_map'}->{$id}->{next} = $items->[0]->EffectiveId if ($items->[0]);
+ $prev = $id;
+ }
+ $self->{'item_map'}->{'last'} = $prev;
}
}
@@ -2082,14 +2108,14 @@
$ItemMap->{'first'} = first ticketid found
$ItemMap->{'last'} = last ticketid found
-$ItemMap->{$id}->{prev} = the tikcet id found before $id
-$ItemMap->{$id}->{next} = the tikcet id found after $id
+$ItemMap->{$id}->{prev} = the ticket id found before $id
+$ItemMap->{$id}->{next} = the ticket id found after $id
=cut
sub ItemMap {
my $self = shift;
- $self->_BuildItemMap() unless ($self->{'item_map'});
+ $self->_BuildItemMap() unless ($self->{'items_array'} and $self->{'item_map'});
return ($self->{'item_map'});
}
More information about the Rt-commit
mailing list