Subticket Manager: Extending and Integration
Use the Subticket Manager from your own PHP code: public methods of the plugin class, the osTicket signals it uses, the queue decoration and how it works with the API Endpoints plugin.
Subticket Manager: Extending and Integration
Public methods of the plugin class
The class SubticketPlugin provides five methods that other PHP code (for example another osTicket plugin) can use. The class is available as soon as osTicket has loaded the active plugin.
| Method | Returns | Description |
|---|---|---|
getChildren($parentId) |
List of arrays with id, number, subject, status, created |
Children of a ticket, oldest first |
getParent($childId) |
Array with ticket_id, number, subject, status, or null |
Parent of a ticket |
linkTicket($childId, $parentId) |
bool |
Links by internal ticket ID |
linkTicketByNumber($childId, $parentNumber) |
bool |
Links by the parent's ticket number |
unlinkTicket($childId) |
bool |
Sets the child's ticket_pid to NULL |
if (class_exists('SubticketPlugin')) {
$plugin = new SubticketPlugin();
$children = $plugin->getChildren($ticket->getId());
}
When linking, the plugin checks for positive IDs, self-linking, existence of both tickets and loops (up to ten levels). The methods do not check department permissions or ticket states; that is up to the calling code. On errors they return false and write a line with the prefix [SUBTICKET-PLUGIN] to the PHP error log.
Working with the API Endpoints plugin
The API Endpoints plugin ships subticket endpoints for the REST API (tickets-subtickets-parent.php, tickets-subtickets-list.php, tickets-subtickets-create.php, tickets-subtickets-unlink.php), which are enabled per API key through the can_manage_subtickets permission.
- Dependency: API Endpoints checks with
class_exists('SubticketPlugin')whether the Subticket Manager is loaded and creates an instance. If the class is missing, the subticket endpoints answer with 501 (Subticket plugin not available). - Methods used:
getParent,getChildren,linkTicketandunlinkTicket. - Permissions: API Endpoints controls the permissions of the API key. The department check of the Subticket Manager's AJAX interface does not apply on this route.
- Activation: Both plugins must be active. The Subticket Manager needs no setting for this.
A link made through the REST API shows up in the panel and the queue indicator immediately because both read the same ticket_pid column.
osTicket signals used
| Signal | Handler | Effect |
|---|---|---|
object.view |
onTicketView() |
Renders the panel when a ticket is shown in the staff area. Registered in the staff area only |
model.created |
onTicketCreated() |
For a new ticket, sets ticket_pid to the parent ID remembered in the session |
model.updated |
onTicketStatusChanged() |
Registered but without function: the method is empty |
Queue decoration
The file queue-decoration.php defines the class ParentTicketDecoration as a subclass of QueueColumnAnnotation. It is loaded early so osTicket finds it through the declared classes. It extends the query with a subquery that counts the children per ticket (field _child_count) and renders the icon icon-code-fork with a counter and the tooltip "%d sub-ticket(s)".
Limits
- There are no signals, hooks or configuration points of its own to change the plugin's rules.
- The panel texts are hard-coded and cannot be changed through the osTicket translation system.