[rt-users] UserObj info into a template

Jesse Vincent jesse at bestpractical.com
Wed Nov 28 11:58:06 EST 2001


So, why not just use $Ticket->Requestors within your template and iterate
through them. 

my $requestors = $Ticket->Requestors;
while (my $r = $requestors->Next) {
	$userobj = $r->UserObj();

	#do what you want here.
}


On Tue, Nov 27, 2001 at 06:05:17PM -0800, Ashley Gould wrote:
> I really needed more than the requestor's email.  I created a new scrip
> action and modified RT::Template a bit to to get a real UserObj into my
> new template.  RT now sends our custom RMA form to requestors whenever a
> ticket is moved into our site's rma queue.  It is klugie, but works
> well.  What is really needed is a new "rma" object which can be attached
> to a ticket.  I've included some of the details below.
> 
> RT is sweet.  I'm having so much fun.
> 
> ashley
> 
> 
> 
> 
> --------------------------------------
> The Action:
> 
> I set up the scrip action NotifyRequestorOwnerCcWithRMA.  The action had
> to provide a UserObj to the template RMA form.  The stock RT template
> system only receives a TicketObj and a TransactionObj.  First I created
> a new action which grabs the UserObj of the first requester of the
> ticket and passes it to the template handler.  The ugly part is there
> can be _only_one_ requester per ticket: since RT::Ticket::Requestors
> returns a hash of Watcher objects, there is no way to guarentee the
> which requestor will be grabbed for a UserObj if there are more than
> one.
> 
> 
> These are the relevent parts of rt2/lib/RT/Action/NotifyWithRMA.pm:
> 
> 
> package RT::Action::NotifyWithRMA;
> require RT::Action::SendEmail;
> require RT::Action::Notify;
> @ISA = qw(RT::Action::Notify);
> 
> 
> # {{{ sub Prepare
> 
> # Same as RT::Action::Sendmail::Prepare but adds a $UserObj to the call
> # to RT::Template::Parse.
> 
> sub Prepare  {
> 
> _snip_
> 
>   # Ashley's hack
>   # Get a user object from $self->TicketObj
>   $RT::Logger->debug("RT::Action::NotifyWithRMA.pm\n");
> 
>   my $UserObj = $self->TicketObj->Requestors->Next->OwnerObj();
>   $RT::Logger->debug("$UserObj\n");
> 
> 
> # Ashley added the UserObj
>   $self->TemplateObj->Parse(Argument => $self->Argument,
>                             TicketObj => $self->TicketObj,
>                             TransactionObj => $self->TransactionObj,
>                             UserObj => $UserObj);
> 
> _snip_
> 
> 
> 
> 
> 
> 
> Next I modified RT::Template to accept a UserObj.  This was just a minor
> change in RT::Template::_ParseContent:
> 
> 
> # {{{ sub _ParseContent
> 
> # Perform Template substitutions on the Body
> # Ashley's hack: include a UserObj in $T
> 
> sub _ParseContent  {
>   my $self=shift;
>   my %args = ( Argument => undef,
>                TicketObj => undef,
>                UserObj => undef,        # Ashley's hack
>                TransactionObj => undef,
>                @_);
> 
>   $RT::Logger->debug("RT::Template: $args{'UserObj'}\n");
> 
>   # Might be subject to change
>   require Text::Template;
> 
>   $T::Ticket = $args{'TicketObj'};
>   $T::Transaction = $args{'TransactionObj'};
>   $T::Argument = $args{'Argument'};
>   $T::rtname=$RT::rtname;
>   $T::WebRT=$RT::WebRT;
>   $T::User = $args{'UserObj'};          # Ashley's hack
> 
> 
>   $RT::Logger->debug("RT::Template: $T::User\n");
> 
>   # We need to untaint the content of the template, since we'll be working
>   # with it
>   my $content = $self->Content();
>   $content =~ s/^(.*)$/$1/;
>   $template=Text::Template->new(TYPE=>STRING,
>                                 SOURCE=>$content);
> 
>   return ($template->fill_in(PACKAGE=>T));
> }
> # }}}
> 
> 
> 
> 
> 
> 
> 
> 
> On Sat, Nov 17, 2001 at 01:39:45PM -0500, Jesse Vincent wrote:
> > 
> > 
> > 
> > On Fri, Nov 16, 2001 at 08:49:41PM -0800, Ashley Gould wrote:
> > > HI list,
> > > 
> > > I'm creating a template which sends a filled in RMA form to requestors.
> > > I need to catch the requestor's user information.  But from what I can
> > > see a TemplateObj only knows about Ticket objects and Transaction objects.
> > > And something called Argument:
> > 
> > 
> > So, you can get the Requestors out of the ticket object like this:
> > 
> > { $Ticket->RequestorsAsString }
> > 
> > 
> > -- 
> > http://www.bestpractical.com/products/rt  -- Trouble Ticketing. Free.
> 
> _______________________________________________
> rt-users mailing list
> rt-users at lists.fsck.com
> http://lists.fsck.com/mailman/listinfo/rt-users
> 

-- 
http://www.bestpractical.com/products/rt  -- Trouble Ticketing. Free.




More information about the rt-users mailing list