[freeside-commits] freeside/rt/lib/RT Tickets_Overlay.pm, 1.5, 1.5.2.1
Mark Wells
mark at wavetail.420.am
Fri Nov 19 18:35:49 PST 2010
Update of /home/cvs/cvsroot/freeside/rt/lib/RT
In directory wavetail.420.am:/tmp/cvs-serv12184/lib/RT
Modified Files:
Tag: FREESIDE_2_1_BRANCH
Tickets_Overlay.pm
Log Message:
search tickets on some customer fields, RT#9328
Index: Tickets_Overlay.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/rt/lib/RT/Tickets_Overlay.pm,v
retrieving revision 1.5
retrieving revision 1.5.2.1
diff -u -w -d -r1.5 -r1.5.2.1
--- Tickets_Overlay.pm 4 Nov 2010 05:57:00 -0000 1.5
+++ Tickets_Overlay.pm 20 Nov 2010 02:35:47 -0000 1.5.2.1
@@ -146,6 +146,9 @@
WatcherGroup => [ 'MEMBERSHIPFIELD', ], #loc_left_pair
HasAttribute => [ 'HASATTRIBUTE', 1 ],
HasNoAttribute => [ 'HASATTRIBUTE', 0 ],
+ Agentnum => [ 'FREESIDEFIELD', ],
+ Classnum => [ 'FREESIDEFIELD', ],
+ Tagnum => [ 'FREESIDEFIELD', 'cust_tag' ],
);
# Mapping of Field Type to Function
@@ -163,6 +166,7 @@
CUSTOMFIELD => \&_CustomFieldLimit,
DATECUSTOMFIELD => \&_DateCustomFieldLimit,
HASATTRIBUTE => \&_HasAttributeLimit,
+ FREESIDEFIELD => \&_FreesideFieldLimit,
);
our %can_bundle = ();# WATCHERFIELD => "yes", );
@@ -1697,7 +1701,6 @@
);
}
-
# End Helper Functions
# End of SQL Stuff -------------------------------------------------
@@ -1832,13 +1835,52 @@
push @res, { %$row, FIELD => "Priority", ORDER => $order } ;
} elsif ( $field eq 'Customer' ) { #Freeside
+ if ( $subkey eq 'Number' ) {
+ my ($linkalias, $custnum_sql) = $self->JoinToCustLinks;
+ push @res, { %$row,
+ ALIAS => '',
+ FIELD => $custnum_sql,
+ };
+ }
+ else {
+ my $custalias = $self->JoinToCustomer;
+ my $field;
+ if ( $subkey eq 'Name' ) {
+ $field = "COALESCE( $custalias.company,
+ $custalias.last || ', ' || $custalias.first
+ )";
+ }
+ else {
+ # no other cases exist yet, but for obviousness:
+ $field = $subkey;
+ }
+ push @res, { %$row, ALIAS => '', FIELD => $field };
+ }
+ } #Freeside
+
+ else {
+ push @res, $row;
+ }
+ }
+ return $self->SUPER::OrderByCols(@res);
+}
+
+#Freeside
+
+sub JoinToCustLinks {
+ # Set up join to links (id = localbase),
+ # limit link type to 'MemberOf',
+ # and target value to any Freeside custnum URI.
+ # Return the linkalias for further join/limit action,
+ # and an sql expression to retrieve the custnum.
+ my $self = shift;
my $linkalias = $self->Join(
TYPE => 'LEFT',
ALIAS1 => 'main',
FIELD1 => 'id',
TABLE2 => 'Links',
- FIELD2 => 'LocalBase'
+ FIELD2 => 'LocalBase',
);
$self->SUPER::Limit(
@@ -1853,8 +1895,6 @@
OPERATOR => 'STARTSWITH',
VALUE => 'freeside://freeside/cust_main/',
);
-
- #if there was a Links.RemoteTarget int, this bs wouldn't be necessary
my $custnum_sql = "CAST(SUBSTR($linkalias.Target,31) AS ";
if ( RT->Config->Get('DatabaseType') eq 'mysql' ) {
$custnum_sql .= 'SIGNED INTEGER)';
@@ -1862,41 +1902,64 @@
else {
$custnum_sql .= 'INTEGER)';
}
+ return ($linkalias, $custnum_sql);
+}
- if ( $subkey eq 'Number' ) {
-
- push @res, { %$row,
- ALIAS => '',
- FIELD => $custnum_sql,
- };
-
- } elsif ( $subkey eq 'Name' ) {
+sub JoinToCustomer {
+ my $self = shift;
+ my ($linkalias, $custnum_sql) = $self->JoinToCustLinks;
my $custalias = $self->Join(
TYPE => 'LEFT',
EXPRESSION => $custnum_sql,
TABLE2 => 'cust_main',
FIELD2 => 'custnum',
-
);
-
- my $field = "COALESCE( $custalias.company,
- $custalias.last || ', ' || $custalias.first
- )";
-
- push @res, { %$row, ALIAS => '', FIELD => $field };
-
+ return $custalias;
}
- } #Freeside
-
- else {
- push @res, $row;
+sub _FreesideFieldLimit {
+ my ( $self, $field, $op, $value, %rest ) = @_;
+ my $alias = $self->JoinToCustomer;
+ my $is_negative = 0;
+ if ( $op eq '!=' || $op =~ /\bNOT\b/i ) {
+ # if the op is negative, do the join as though
+ # the op were positive, then accept only records
+ # where the right-side join key is null.
+ $is_negative = 1;
+ $op = '=' if $op eq '!=';
+ $op =~ s/\bNOT\b//;
}
+ my $meta = $FIELD_METADATA{$field};
+ if ( $meta->[1] ) {
+ $alias = $self->Join(
+ TYPE => 'LEFT',
+ ALIAS1 => $alias,
+ FIELD1 => 'custnum',
+ TABLE2 => $meta->[1],
+ FIELD2 => 'custnum',
+ );
}
- return $self->SUPER::OrderByCols(@res);
+
+ $self->SUPER::Limit(
+ LEFTJOIN => $alias,
+ FIELD => lc($field),
+ OPERATOR => $op,
+ VALUE => $value,
+ ENTRYAGGREGATOR => 'AND',
+ );
+ $self->_SQLLimit(
+ %rest,
+ ALIAS => $alias,
+ FIELD => lc($field),
+ OPERATOR => $is_negative ? 'IS' : 'IS NOT',
+ VALUE => 'NULL',
+ QUOTEVALUE => 0,
+ );
}
+#Freeside
+
# }}}
# {{{ Limit the result set based on content
More information about the freeside-commits
mailing list