fix(tickets): wire contact, assignees through controller + fix status type bug

- Pass contact_id, assign_users, assign_groups, custom_fields from
  controller to model on ticket creation
- Fix updateTicketStatus: getString→getInt (was passing string to int param)
- Add getBackendUsers() and getUserGroups() to TicketsModel
- Add assign users/groups multi-select fields to creation modal
This commit is contained in:
Jonathan Miller
2026-06-11 21:45:55 -05:00
parent 5d5972eb7a
commit 945fe0de93
4 changed files with 66 additions and 5 deletions
@@ -365,10 +365,14 @@ class DisplayController extends BaseController
$input = Factory::getApplication()->getInput();
$this->jsonResponse($this->getModel('Tickets')->createTicket([
'subject' => $input->getString('subject', ''),
'body' => $input->getRaw('body', ''),
'priority' => $input->getString('priority', 'normal'),
'category_id' => $input->getInt('category_id', 0),
'subject' => $input->getString('subject', ''),
'body' => $input->getRaw('body', ''),
'priority' => $input->getString('priority', 'normal'),
'category_id' => $input->getInt('category_id', 0),
'contact_id' => $input->getInt('contact_id', 0),
'assign_users' => $input->get('assign_users', [], 'ARRAY'),
'assign_groups' => $input->get('assign_groups', [], 'ARRAY'),
'custom_fields' => $input->get('custom_fields', [], 'ARRAY'),
]));
}
@@ -405,7 +409,7 @@ class DisplayController extends BaseController
$this->jsonResponse($this->getModel('Tickets')->updateStatus(
$input->getInt('ticket_id', 0),
$input->getString('status', '')
$input->getInt('status', 0)
));
}
@@ -575,6 +575,39 @@ class TicketsModel extends BaseDatabaseModel
return $db->loadObjectList() ?: [];
}
/**
* Get backend users for assignee selection.
*/
public function getBackendUsers(): array
{
$db = $this->getDatabase();
$db->setQuery(
$db->getQuery(true)
->select(['u.id', 'u.name', 'u.username'])
->from($db->quoteName('#__users', 'u'))
->where($db->quoteName('u.block') . ' = 0')
->order($db->quoteName('u.name') . ' ASC')
);
return $db->loadObjectList() ?: [];
}
/**
* Get Joomla user groups for assignee selection.
*/
public function getUserGroups(): array
{
$db = $this->getDatabase();
$db->setQuery(
$db->getQuery(true)
->select(['id', 'title'])
->from($db->quoteName('#__usergroups'))
->order($db->quoteName('title') . ' ASC')
);
return $db->loadObjectList() ?: [];
}
/**
* Get Joomla custom field groups assigned to a ticket category.
*/
@@ -25,6 +25,8 @@ class HtmlView extends BaseHtmlView
protected $contacts = [];
protected $statuses = [];
protected $priorities = [];
protected $backendUsers = [];
protected $userGroups = [];
public function display($tpl = null)
{
@@ -46,6 +48,8 @@ class HtmlView extends BaseHtmlView
$this->overdue = $model->getOverdueTickets();
$this->atsAvailable = $model->checkAtsAvailable();
$this->contacts = $model->getContacts();
$this->backendUsers = $model->getBackendUsers();
$this->userGroups = $model->getUserGroups();
$this->addToolbar();
@@ -182,6 +182,26 @@ $token = Session::getFormToken();
</select>
</div>
</div>
<div class="row mb-3">
<div class="col-md-6">
<label class="form-label">Assign Users</label>
<select name="assign_users[]" class="form-select" multiple size="4">
<?php foreach ($this->backendUsers as $u): ?>
<option value="<?php echo $u->id; ?>"><?php echo $this->escape($u->name); ?></option>
<?php endforeach; ?>
</select>
<small class="text-muted">Hold Ctrl/Cmd to select multiple</small>
</div>
<div class="col-md-6">
<label class="form-label">Assign Groups</label>
<select name="assign_groups[]" class="form-select" multiple size="4">
<?php foreach ($this->userGroups as $g): ?>
<option value="<?php echo $g->id; ?>"><?php echo $this->escape($g->title); ?></option>
<?php endforeach; ?>
</select>
<small class="text-muted">Hold Ctrl/Cmd to select multiple</small>
</div>
</div>
<div class="mb-3">
<label class="form-label">Description</label>
<textarea name="body" class="form-control" rows="6" required></textarea>