generated from MokoConsulting/Template-Joomla
feat: build out core helpers — 1 files added
This commit is contained in:
@@ -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() ?: [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user