| Current Path : /var/www/consult-e-syn/public_html/plugins/atsinstantreply/tickets/ |
| Current File : /var/www/consult-e-syn/public_html/plugins/atsinstantreply/tickets/tickets.php |
<?php
/**
* @package ats
* @copyright Copyright (c)2011-2022 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU General Public License version 3, or later
*/
defined('_JEXEC') or die;
use Akeeba\TicketSystem\Admin\Model\Categories;
use FOF40\Date\Date;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Router\Route;
/**
* Akeeba Ticket System - InstantReplies from closed, public tickets
*/
class plgAtsinstantreplyTickets extends CMSPlugin
{
/**
* The site's database driver object. The property's presence causes the CMSPlugin to magically populate it.
*
* @var JDatabaseDriver
* @since 3.2.0
*/
protected $db;
/**
* Return InstantReply results to ATS
*
* @param Categories $category The ATS category in which we are performing the search
* @param string $search The search string (partial ticket title)
* @param bool $siteChrome Should I display the full site template when a search result link is clicked?
*
* @return array
*
* @since 3.2.0
*/
public function onATSInstantReply(Categories $category, $search, $siteChrome = true)
{
// Additional query parameters based on whether to show the site's template chrome
$additionalQueryParams = $siteChrome ? '' : '&tmpl=component';
// Make sure we have at least one valid value
$db = $this->db;
// Fetching results from closed tickets
$query = $db->getQuery(true)
->select([
$db->qn('tickets') . '.' . $db->qn('ats_ticket_id'),
$db->qn('tickets') . '.' . $db->qn('title'),
$db->qn('content_html'),
'MATCH(' . $db->qn('content_html') . ') AGAINST (' . $db->q($search) . ') as ' . $db->qn('score'),
])
->from($db->qn('#__ats_posts') . ' AS ' . $db->qn('posts'))
->innerJoin($db->qn('#__ats_tickets') . ' ' . $db->qn('tickets') . ' on ' . $db->qn('posts') . '.' . $db->qn('ats_ticket_id') . ' = ' .
$db->qn('tickets') . '.' . $db->qn('ats_ticket_id'))
->where($db->qn('public') . ' = ' . $db->q(1))
->where($db->qn('catid') . ' = ' . $db->q($category->getId()))
->where($db->qn('tickets') . '.' . $db->qn('enabled') . ' = ' . $db->q(1))
->where('MATCH(' . $db->qn('content_html') . ') AGAINST (' . $db->q($search) . ')');
$status[] = $db->qn('status') . ' = ' . $db->q('C');
$pending = '(' . $db->qn('status') . ' != ' . $db->q('C');
$daysLimit = $this->params->get('instantreplies_daylimit', 30);
if ($daysLimit > 0)
{
$daysAgo = new Date('-' . $daysLimit . ' days');
$pending .= ' AND ' . $db->qn('tickets') . '.' . $db->qn('modified_on') . ' >= ' . $db->q($daysAgo->toSql());
}
$status[] = $pending . ')';
$query->where('(' . implode(' OR ', $status) . ')');
$rawResults = $db->setQuery($query, 0, 10)->loadObjectList();
if (empty($rawResults))
{
return [];
}
$results = [];
$factor = (float) $this->params->get('factor', 1.0);
foreach ($rawResults as $row)
{
$preview = substr(strip_tags($row->content_html), 0, 150) . '…';
$url = Route::link('site', 'index.php?option=com_ats&view=Ticket&id=' . $row->ats_ticket_id . $additionalQueryParams, false, Route::TLS_IGNORE, true);
$results[] = (object) [
'score' => $factor * $row->score,
'title' => '#' . $row->ats_ticket_id . '. ' . $row->title,
'preview' => $preview,
'url' => $url,
'source' => 'ats',
];
}
return $results;
}
}