RT-Extension-TemplateTickets

 view release on metacpan or  search on metacpan

html/Admin/Queues/TemplateTickets.html  view on Meta::CPAN

        $Ticket         = undef;
        $TicketObj      = undef;
        $CreateTemplate = 0;

    } elsif ( $CreateTemplate && not $CanEdit ) {

        # Return to the ticket list if we're trying to create a new template
        # ticket but the user has no permission to modify templates.
        #
        push @Results,
            loc( 'No permission to modify ticket templates in queue [_1]',
            $QueueObj->Name );
        $Ticket         = undef;
        $TicketObj      = undef;
        $CreateTemplate = 0;

    } elsif ($CreateTemplate) {

        # Set the title for creating a new template ticket.
        #
        $Title = loc( 'Create new template ticket for queue [_1]',
            $QueueObj->Name );

    } elsif ( $Delete && $ConfirmDelete && $CanEdit ) {

        # Delete a template ticket, given confirmation and given that the
        # user has the right permissions, and return to the ticket list.
        #
        $TicketObj->DeleteAttribute('TemplateTicketsDefinition');
        push @Results, loc( 'Template ticket #[_1] deleted.', $Ticket );
        $Ticket         = undef;
        $TicketObj      = undef;
        $CreateTemplate = 0;

    } else {

        # Set the title for displaying a template ticket.
        #
        $Title = loc( 'Queue [_1]: Template ticket #[_2]: [_3]',
            $QueueObj->Name, $TicketObj->id, $TicketObj->Subject );

        # If deletion was attempted, display the appropriate notice.
        #
        if ( $Delete && not $ConfirmDelete ) {
            push @Results, loc('Not deleted - deletion not confirmed.');
        } elsif ( $Delete && not $CanEdit ) {
            push @Results, loc('Not deleted - permission denied.');
        }
    }
}

# Find all template tickets for this queue.
#
my $TemplateTickets = RT::Tickets->new( $session{'CurrentUser'} );
$TemplateTickets->FromSQL( 'Queue = '
        . $QueueObj->id
        . ' AND HasAttribute = "TemplateTicketsDefinition"' );
my $TemplateTicketObjects = $TemplateTickets->ItemsArrayRef;

# Read the settings of all the template tickets in this queue, and build a
# hash of the category names so we can provide them as options in a combobox
# when editing.
#
my %TemplateCategories  = ();
my %AllTemplateSettings = ();
$TemplateTickets->GotoFirstItem();
while ( my $TemplateTicketObj = $TemplateTickets->Next ) {
    my $Attribute
        = $TemplateTicketObj->FirstAttribute('TemplateTicketsDefinition');
    next if ( not defined $Attribute );
    my $Settings = $Attribute->Content;
    next if ( not defined $Settings );
    $AllTemplateSettings{ $TemplateTicketObj->id } = $Settings;
    $TemplateCategories{ $Settings->{'Category'} }++;
}

# Sort the template tickets by category and then by subject.
#
$TemplateTicketObjects = [
    sort {
        ( $AllTemplateSettings{ $a->id }->{'Category'} || '' ) eq
            ( $AllTemplateSettings{ $b->id }->{'Category'} || '' )
            ? ( $a->Subject cmp $b->Subject )
            : ( $AllTemplateSettings{ $a->id }->{'Category'}  || '' )
            cmp( $AllTemplateSettings{ $b->id }->{'Category'} || '' )
        } @$TemplateTicketObjects
];

# Settings and ticket content of the currently selected template.
#
my $TemplateSettings = {};
my $TemplateSummary  = '';
my $TemplateContent  = '';

# If a template ticket has been loaded into $TicketObj earlier, get ready to
# display its details, and perform any appropriate operations on it.
#
if ($TicketObj) {

    # Create an object for simulating a read-only version of the ticket
    # (which the current user has no rights over), so that when we run the
    # Mason components to display the ticket, they don't include the editing
    # elements.
    #
    my $ReadonlyTicketObj = {%$TicketObj};
    bless( $ReadonlyTicketObj, ref $TicketObj );

    $ReadonlyTicketObj->{'CurrentUserCanSetOwner'} = sub { return 0; };
    $ReadonlyTicketObj->{'CurrentUserHasRight'}    = sub { return 0; };

    # Limit the ticket history to just the first transaction, since that's
    # what will provide the "content" for the template.
    #
    my $TicketHistory = $ReadonlyTicketObj->SortedTransactions;
    $TicketHistory->RowsPerPage(1);

    # Generate the ticket summary display, and then strip out any form
    # elements and ticket creation links to render it inert.
    #
    $TemplateSummary = $m->scomp( '/Ticket/Elements/ShowSummary',
        'Ticket' => $ReadonlyTicketObj, 'InlineEdit' => 0);



( run in 1.424 second using v1.01-cache-2.11-cpan-39bf76dae61 )