feat: build out core helpers — 1 files added
Universal: Auto Version Bump / Version Bump (push) Successful in 9s
Universal: Pre-Release / Build Pre-Release (${{ inputs.stability || github.ref_name }}) (push) Successful in 10s

This commit is contained in:
Jonathan Miller
2026-06-21 17:37:56 -05:00
parent 018b2a623d
commit 74a169200b
@@ -0,0 +1,77 @@
<?php
namespace Moko\Plugin\System\MokoSuiteSupport\Helper;
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\Database\DatabaseInterface;
/**
* Canned responses — quick reply templates for agents, categorized, searchable.
*/
class CannedResponseHelper
{
/**
* Get all canned responses, optionally filtered by category.
*/
public static function getAll(?string $category = null): array
{
$db = Factory::getContainer()->get(DatabaseInterface::class);
$query = $db->getQuery(true)
->select('cr.id, cr.title, cr.body, cr.category, cr.shortcut')
->from($db->quoteName('#__mokosuitesupport_canned_responses', 'cr'))
->where($db->quoteName('cr.status') . ' = ' . $db->quote('active'))
->order('cr.category ASC, cr.title ASC');
if ($category) {
$query->where($db->quoteName('cr.category') . ' = ' . $db->quote($category));
}
$db->setQuery($query);
return $db->loadObjectList() ?: [];
}
/**
* Search canned responses by keyword.
*/
public static function search(string $keyword): array
{
$db = Factory::getContainer()->get(DatabaseInterface::class);
$filter = \Joomla\Filter\InputFilter::getInstance();
$keyword = $filter->clean($keyword, 'STRING');
if (strlen($keyword) < 2) {
return [];
}
$search = $db->quote('%' . $db->escape($keyword, true) . '%');
$db->setQuery($db->getQuery(true)
->select('cr.id, cr.title, cr.body, cr.category, cr.shortcut')
->from($db->quoteName('#__mokosuitesupport_canned_responses', 'cr'))
->where($db->quoteName('cr.status') . ' = ' . $db->quote('active'))
->where('(cr.title LIKE ' . $search . ' OR cr.body LIKE ' . $search . ' OR cr.shortcut LIKE ' . $search . ')')
->order('cr.title ASC'), 0, 20);
return $db->loadObjectList() ?: [];
}
/**
* Get categories with response counts.
*/
public static function getCategories(): array
{
$db = Factory::getContainer()->get(DatabaseInterface::class);
$db->setQuery($db->getQuery(true)
->select('category, COUNT(*) AS count')
->from('#__mokosuitesupport_canned_responses')
->where($db->quoteName('status') . ' = ' . $db->quote('active'))
->group('category')
->order('category ASC'));
return $db->loadObjectList() ?: [];
}
}