[Rt-commit] r14450 - rt/3.8/trunk/lib/RT
ruz at bestpractical.com
ruz at bestpractical.com
Wed Jul 23 22:07:14 EDT 2008
Author: ruz
Date: Wed Jul 23 22:07:13 2008
New Revision: 14450
Modified:
rt/3.8/trunk/lib/RT/Tickets_Overlay.pm
Log:
* implement id = '__Bookmarked__' ticket SQL
Modified: rt/3.8/trunk/lib/RT/Tickets_Overlay.pm
==============================================================================
--- rt/3.8/trunk/lib/RT/Tickets_Overlay.pm (original)
+++ rt/3.8/trunk/lib/RT/Tickets_Overlay.pm Wed Jul 23 22:07:13 2008
@@ -97,7 +97,7 @@
LastUpdatedBy => [ 'ENUM' => 'User', ],
Owner => [ 'WATCHERFIELD' => 'Owner', ],
EffectiveId => [ 'INT', ],
- id => [ 'INT', ],
+ id => [ 'ID', ],
InitialPriority => [ 'INT', ],
FinalPriority => [ 'INT', ],
Priority => [ 'INT', ],
@@ -149,6 +149,7 @@
our %dispatch = (
ENUM => \&_EnumLimit,
INT => \&_IntLimit,
+ ID => \&_IdLimit,
LINK => \&_LinkLimit,
DATE => \&_DateLimit,
STRING => \&_StringLimit,
@@ -259,6 +260,58 @@
version of what ProcessRestrictions used to do. They're also much
more clearly delineated by the TYPE of field being processed.
+=head2 _IdLimit
+
+Handle ID field.
+
+=cut
+
+sub _IdLimit {
+ my ( $sb, $field, $op, $value, @rest ) = @_;
+
+ return $sb->_IntLimit( $field, $op, $value, @rest ) unless $value eq '__Bookmarked__';
+
+ die "Invalid operator $op for __Bookmarked__ search on $field"
+ unless $op =~ /^(=|!=)$/;
+
+ my @bookmarks = do {
+ my $tmp = $sb->CurrentUser->UserObj->FirstAttribute('Bookmarks');
+ $tmp = $tmp->Content if $tmp;
+ $tmp ||= {};
+ grep $_, keys %$tmp;
+ };
+
+ return $sb->_SQLLimit(
+ FIELD => $field,
+ OPERATOR => $op,
+ VALUE => 0,
+ @rest,
+ ) unless @bookmarks;
+
+ # as bookmarked tickets can be merged we have to use a join
+ # but it should be pretty lightweight
+ my $tickets_alias = $sb->Join(
+ TYPE => 'LEFT',
+ ALIAS1 => 'main',
+ FIELD1 => 'id',
+ TABLE2 => 'Tickets',
+ FIELD2 => 'EffectiveId',
+ );
+ $sb->_OpenParen;
+ my $first = 1;
+ my $ea = $op eq '='? 'OR': 'AND';
+ foreach my $id ( sort @bookmarks ) {
+ $sb->_SQLLimit(
+ ALIAS => $tickets_alias,
+ FIELD => 'id',
+ OPERATOR => $op,
+ VALUE => $id,
+ $first? (@rest): ( ENTRYAGGREGATOR => $ea )
+ );
+ }
+ $sb->_CloseParen;
+}
+
=head2 _EnumLimit
Handle Fields which are limited to certain values, and potentially
More information about the Rt-commit
mailing list