Sorting an RT collection

Hello,

I have a need to sort a collection (of tickets) based on some
criterion that is not a simple table attribute/column. I’m thinking I
can populate a Tickets object in the normal way and then call a new
method to sort the internal array that holds the retrieved database rows.

Where I’m getting confused is: SearchBuilder maintains rows in an
array $self->{‘items’}, but Tickets_Overlay seems to maintain a
second array $self->{‘items_array’} (in the ItemsArrayRef method).

My questions are:

  • Why two arrays?
  • Can my goal be achieved as simply as I think (by sorting the
    appropriate arrays) or is there more to it?
  • Is this (sorting by not-a-table-column) done anywhere currently within RT?

Thanks,
Steve

Stephen Turner
Senior Programmer/Analyst - Client Support Services
MIT Information Services and Technology (IS&T)

Stephen Turner wrote:

Hello,

I have a need to sort a collection (of tickets) based on some criterion
that is not a simple table attribute/column. I’m thinking I can populate
a Tickets object in the normal way and then call a new method to sort
the internal array that holds the retrieved database rows.

Where I’m getting confused is: SearchBuilder maintains rows in an array
$self->{‘items’}, but Tickets_Overlay seems to maintain a second array
$self->{‘items_array’} (in the ItemsArrayRef method).

My questions are:

  • Why two arrays?

So, there’s an awful lot of cough legacy code in there. I think that
it has to do with only wanting the ItemsArrayRef to contain items that
had passed an ACL check. And my guess is that the code in
Tickets_Overlay predated a refactoring of SearchBuilder that made this
code more accessible.

  • Can my goal be achieved as simply as I think (by sorting the
    appropriate arrays) or is there more to it?

The one caveat is that if you have a search that’s more than one “page”
long, you’re going to be sorting within a page.

  • Is this (sorting by not-a-table-column) done anywhere currently within
    RT?

To my knowledge, it’s not yet. It feels like a feature that would be a
natural addition to SearchBuilder, if the Tickets_Overlay code doesn’t
block the way.

signature.asc (191 Bytes)