X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FTicketSystem%2FRT_External.pm;h=66f8747022f8b3bf1917d0b9fc7d2515c4a67975;hb=57323a695e58b58cc8892784d356995f6e41bfcd;hp=a105c2752ff40f94ebb99859f7ee2c249df5a0c4;hpb=dda497584a2e12907bba7cf07051fe34ede63b32;p=freeside.git diff --git a/FS/FS/TicketSystem/RT_External.pm b/FS/FS/TicketSystem/RT_External.pm index a105c2752..66f874702 100644 --- a/FS/FS/TicketSystem/RT_External.pm +++ b/FS/FS/TicketSystem/RT_External.pm @@ -1,11 +1,14 @@ package FS::TicketSystem::RT_External; use strict; -use vars qw( $conf $priority_field $priority_field_queue $field ); +use vars qw( $conf $default_queueid + $priority_field $priority_field_queue $field ); +use URI::Escape; use FS::UID; install_callback FS::UID sub { my $conf = new FS::Conf; + $default_queueid = $conf->config('ticket_system-default_queueid'); $priority_field = $conf->config('ticket_system-custom_priority_field'); if ( $priority_field ) { @@ -25,46 +28,103 @@ sub num_customer_tickets { #$dbh ||= create one from some config options + my( $from_sql, @param) = $self->_from_customer( $custnum, $priority ); + + my $sql = "select count(*) $from_sql"; + my $sth = $dbh->prepare($sql) or die $dbh->errstr. " preparing $sql"; + $sth->execute(@param) or die $sth->errstr. " executing $sql"; + + $sth->fetchrow_arrayref->[0]; + +} + +sub customer_tickets { + my( $self, $custnum, $limit, $priority, $dbh ) = @_; + $limit ||= 0; + + #$dbh ||= create one from some config options + + my( $from_sql, @param) = $self->_from_customer( $custnum, $priority ); + my $sql = "select tickets.*, queues.name". + ( length($priority) ? ", ticketcustomfieldvalues.content" : '' ). + " $from_sql order by priority desc limit $limit"; + my $sth = $dbh->prepare($sql) or die $dbh->errstr. "preparing $sql"; + $sth->execute(@param) or die $sth->errstr. "executing $sql"; + + #munge column names??? #httemplate/view/cust_main/tickets.html has column + #names that might not make sense now... + $sth->fetchall_arrayref({}); + +} + +sub _from_customer { + my( $self, $custnum, $priority ) = @_; + my @param = (); - my $priority_sql = ''; + my $join = ''; + my $where = ''; if ( defined($priority) ) { + + my $queue_sql = " customfields.queue = ( select id from queues + where queues.name = ? ) + or ( ? = '' and customfields.queue = 0 )"; + if ( length($priority) ) { - my $queue_sql = " queue = ( select id from queues where queues.name = ? ) - or ( ? = '' and queue = 0 )"; - $priority_sql = " - and ? = ( select content from TicketCustomFieldValues - where ticket = tickets.id - and customfield = ( select id from customfields - where name = ? - and ( $queue_sql ) - ) - ) - "; - push @param, $priority, - $priority_field, - $priority_field_queue, - $priority_field_queue; + #$where = " + # and ? = ( select content from TicketCustomFieldValues + # where ticket = tickets.id + # and customfield = ( select id from customfields + # where name = ? + # and ( $queue_sql ) + # ) + # ) + #"; + push @param, $priority; + + $join = "join TicketCustomFieldValues + on ( tickets.id = TicketCustomFieldValues.ticket )"; + + $where = "and content = ? + and customfield = ( select id from customfields + where name = ? + and ( $queue_sql ) + ) + "; } else { - return '0nothandledyet0'; + $where = + "and 0 = ( select count(*) from TicketCustomFieldValues + where ticket = tickets.id + and customfield = ( select id from customfields + where name = ? + and ( $queue_sql ) + ) + ) + "; } + push @param, $priority_field, + $priority_field_queue, + $priority_field_queue; } my $sql = " - select count(*) from tickets + from tickets + join queues on ( tickets.queue = queues.id ) + join links on ( tickets.id = links.localbase ) + $join where ( status = 'new' or status = 'open' or status = 'stalled' ) and target = 'freeside://freeside/cust_main/$custnum' + $where "; - my $sth = $dbh->prepare($sql) or die $dbh->errstr; - $sth->execute(@param) or die $sth->errstr; - - $sth->fetchrow_arrayref->[0]; + ( $sql, @param ); } sub href_customer_tickets { my( $self, $custnum, $priority ) = @_; + #i snarfed this from an RT bookmarked search, it could be unescaped in the + #source for readability and run through uri_escape my $href = 'Search/Results.html?Order=ASC&Query=%20MemberOf%20%3D%20%27freeside%3A%2F%2Ffreeside%2Fcust_main%2F'. $custnum. @@ -97,5 +157,20 @@ sub href_customer_tickets { $href; } + +sub href_new_ticket { + my( $self, $custnum, $requestors ) = @_; + 'Ticket/Create.html?'. + "Queue=$default_queueid". + "&new-MemberOf=freeside://freeside/cust_main/$custnum". + ( $requestors ? '&Requestors='. uri_escape($requestors) : '' ) + ; +} + +sub href_ticket { + my($self, $ticketnum) = @_; + 'Ticket/Display.html?id='.$ticketnum; +} + 1;