User Support

Ticket system for communicating with users

Tickets Component

The supportTickets component lists the signed-in user's support tickets, newest first, with a search filter and pagination.

Property Description
submitPage The page with the Ticket Submit component, linked from the list.
ticketPage The page with the Ticket component, used for the link of each ticket.
ticketsPerPage The number of tickets on each page. Default: 20
statusFilter Lists only the tickets with these status codes: new, processing or closed. Leave it empty to list every status. See Filtering by Status.

Basic Usage

The component only lists the tickets of the signed-in user, so restrict the page to signed-in users with the RainLab.User session component.

title = "Support Tickets"
url = "/support"
layout = "default"

[session]
security = "user"
redirect = "account/login"

[supportTickets]
submitPage = "support/submit"
ticketPage = "support/ticket"
ticketsPerPage = 20
==
{% component "supportTickets" %}

The default markup shows a Submit a new ticket button, a table of the tickets and a pager. A marker on each row highlights the tickets that have a staff reply for the user to read.

Page Variables

The tickets method of the component returns the tickets for the current page, as a paginated collection.

{% set tickets = supportTickets.tickets %}

Each ticket in the list provides the following values.

Variable Description
ticket.id The ticket ID.
ticket.subject The subject.
ticket.status The status, with its name and code.
ticket.created_at When the ticket was submitted.
ticket.closed_at When the ticket was closed, or null while it is open.
ticket.last_message The newest public message, or null when nobody has replied yet.
ticket.has_new True when the last public message came from staff, so the user has a reply to read.
ticket.url The address of the ticket on the ticketPage page.

Like the Ticket component, the list loads ticket.messages with public messages only, so internal messages never reach the theme.

The component also sets these page variables.

Variable Description
submitPage The submitPage property value.
ticketPage The ticketPage property value.
ticketsPerPage The ticketsPerPage property value.
paginationUrl The address of the current page, ending in page= so that a page number can be appended. It keeps the search query.

The following page lists the tickets with its own markup, including a search form and page links.

title = "Support Tickets"
url = "/support"
layout = "default"

[session]
security = "user"
redirect = "account/login"

[supportTickets]
submitPage = "support/submit"
ticketPage = "support/ticket"
==
{% set tickets = supportTickets.tickets %}

<a href="{{ submitPage|page }}">
    Submit a new ticket
</a>

<form method="get">
    <input name="search" type="search" value="{{ get('search') }}" />
    <button type="submit">
        Search
    </button>
</form>

<table>
    {% for ticket in tickets %}
        <tr>
            <td>
                #{{ ticket.id }}
            </td>
            <td>
                <a href="{{ ticket.url }}">
                    {{ ticket.subject }}
                </a>
                {% if ticket.has_new %}
                    <strong>
                        New reply
                    </strong>
                {% endif %}
            </td>
            <td>
                {{ ticket.status.name }}
            </td>
            <td>
                {{ ticket.created_at|date('M j, Y') }}
            </td>
        </tr>
    {% else %}
        <tr>
            <td colspan="4">
                You have not submitted any support tickets yet.
            </td>
        </tr>
    {% endfor %}
</table>

{% if tickets.lastPage > 1 %}
    <nav>
        {% for page in 1..tickets.lastPage %}
            <a href="{{ paginationUrl ~ page }}">
                {{ page }}
            </a>
        {% endfor %}
    </nav>
{% endif %}

Searching and Pagination

The search query parameter filters the list by the subject, the ticket text and the text of its public messages. Internal messages are not searched.

The page query parameter selects the page. A value that is not a number shows the first page, and a page past the end redirects to the last page. Build page links by appending the page number to paginationUrl, which keeps the search query.

Filtering by Status

Set the statusFilter property to list only some statuses, for example on separate pages for open and closed tickets. The following lists the open tickets.

[supportTickets]
ticketPage = "support/ticket"
statusFilter[] = "new"
statusFilter[] = "processing"

To list the closed tickets, set statusFilter[] = "closed" instead. See Ticket Status for what each status means.

Partials

The component renders the following partials.

Partial Description
default Wraps the list in the responsiv-support element and renders the partials below.
title The heading, and the Submit a new ticket button when submitPage is set.
tickets The table of tickets.
pagination The pager and the ticket count, using the shared pagination-list partial.

To change one of them, copy it into the partials/supportTickets folder of your theme. See Overriding Partials.

Rules

  • Ownership. The list only holds the tickets of the signed-in user. For a guest, the list is empty.
  • Internal messages. The search ignores internal messages, ticket.last_message is always a public message, and ticket.messages holds public messages only.