2026-06-28 11:51:04 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @package MokoSuiteCross
|
|
|
|
|
* @subpackage com_mokosuitecross
|
|
|
|
|
* @author Moko Consulting <hello@mokoconsulting.tech>
|
|
|
|
|
* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved.
|
|
|
|
|
* @license GNU General Public License version 3 or later; see LICENSE
|
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace Joomla\Component\MokoSuiteCross\Administrator\Controller;
|
|
|
|
|
|
|
|
|
|
defined('_JEXEC') or die;
|
|
|
|
|
|
|
|
|
|
use Joomla\CMS\MVC\Controller\BaseController;
|
2026-06-28 12:00:10 -05:00
|
|
|
use Joomla\CMS\Session\Session;
|
|
|
|
|
use Joomla\Component\MokoSuiteCross\Administrator\Helper\AnalyticsHelper;
|
2026-06-28 11:51:04 -05:00
|
|
|
|
|
|
|
|
class AnalyticsController extends BaseController
|
|
|
|
|
{
|
2026-06-28 12:00:10 -05:00
|
|
|
/**
|
|
|
|
|
* Return heatmap grid data as JSON.
|
|
|
|
|
*
|
|
|
|
|
* Query params: service_type (string), days (int, default 90)
|
|
|
|
|
*/
|
|
|
|
|
public function heatmap(): void
|
2026-06-28 11:51:04 -05:00
|
|
|
{
|
2026-06-28 12:00:10 -05:00
|
|
|
if (!Session::checkToken('get')) {
|
|
|
|
|
echo json_encode(['success' => false, 'error' => 'Invalid token']);
|
|
|
|
|
$this->app->close();
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$user = $this->app->getIdentity();
|
|
|
|
|
|
|
|
|
|
if (!$user->authorise('core.manage', 'com_mokosuitecross')) {
|
|
|
|
|
echo json_encode(['success' => false, 'error' => 'Permission denied']);
|
|
|
|
|
$this->app->close();
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$serviceType = $this->input->getCmd('service_type', '');
|
|
|
|
|
$days = $this->input->getInt('days', 90);
|
|
|
|
|
|
|
|
|
|
$grid = AnalyticsHelper::getHeatmapData($serviceType, $days);
|
|
|
|
|
$bestTimes = AnalyticsHelper::getBestTimes($serviceType, 3);
|
|
|
|
|
|
|
|
|
|
$this->app->setHeader('Content-Type', 'application/json; charset=utf-8');
|
|
|
|
|
echo json_encode([
|
|
|
|
|
'success' => true,
|
|
|
|
|
'grid' => $grid,
|
|
|
|
|
'best_times' => $bestTimes,
|
|
|
|
|
]);
|
|
|
|
|
$this->app->close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the top posting times as JSON.
|
|
|
|
|
*
|
|
|
|
|
* Query params: service_type (string), limit (int, default 5)
|
|
|
|
|
*/
|
|
|
|
|
public function besttimes(): void
|
|
|
|
|
{
|
|
|
|
|
if (!Session::checkToken('get')) {
|
|
|
|
|
echo json_encode(['success' => false, 'error' => 'Invalid token']);
|
|
|
|
|
$this->app->close();
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$user = $this->app->getIdentity();
|
|
|
|
|
|
|
|
|
|
if (!$user->authorise('core.manage', 'com_mokosuitecross')) {
|
|
|
|
|
echo json_encode(['success' => false, 'error' => 'Permission denied']);
|
|
|
|
|
$this->app->close();
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$serviceType = $this->input->getCmd('service_type', '');
|
|
|
|
|
$limit = $this->input->getInt('limit', 5);
|
|
|
|
|
|
|
|
|
|
$bestTimes = AnalyticsHelper::getBestTimes($serviceType, $limit);
|
|
|
|
|
$serviceBreakdown = AnalyticsHelper::getServiceBreakdown();
|
|
|
|
|
|
|
|
|
|
$this->app->setHeader('Content-Type', 'application/json; charset=utf-8');
|
|
|
|
|
echo json_encode([
|
|
|
|
|
'success' => true,
|
|
|
|
|
'best_times' => $bestTimes,
|
|
|
|
|
'service_breakdown' => $serviceBreakdown,
|
|
|
|
|
]);
|
|
|
|
|
$this->app->close();
|
2026-06-28 11:51:04 -05:00
|
|
|
}
|
|
|
|
|
}
|