e702eb8d9e
Universal: PR Check / Branch Policy (pull_request) Successful in 2s
Branch Cleanup / Delete merged branch (pull_request) Failing after 1s
RC Revert / Rename rc/ back to dev/ (pull_request) Has been skipped
Universal: PR Check / Validate PR (pull_request) Failing after 6s
Universal: PR Check / Secret Scan (pull_request) Successful in 6s
Generic: Project CI / Lint & Validate (pull_request) Successful in 20s
Universal: Auto Version Bump / Version Bump (push) Successful in 11s
Joomla: Metadata Validation / Validate Joomla Metadata (pull_request) Successful in 40s
Generic: Project CI / Tests (pull_request) Has been cancelled
Universal: PR Check / Build RC Package (pull_request) Has been cancelled
Universal: PR Check / Report Issues (pull_request) Has been cancelled
Authored-by: Moko Consulting
98 lines
2.9 KiB
PHP
98 lines
2.9 KiB
PHP
<?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;
|
|
use Joomla\CMS\Session\Session;
|
|
use Joomla\Component\MokoSuiteCross\Administrator\Helper\AnalyticsHelper;
|
|
|
|
class AnalyticsController extends BaseController
|
|
{
|
|
/**
|
|
* Return heatmap grid data as JSON.
|
|
*
|
|
* Query params: service_type (string), days (int, default 90)
|
|
*/
|
|
public function heatmap(): 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', '');
|
|
$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();
|
|
}
|
|
}
|