feat: initial scaffold — package manifest with dlid/updateservers + first helper
Universal: Auto Version Bump / Version Bump (push) Successful in 8s
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:27:09 -05:00
parent 9ee38037e5
commit 9ff31d4de1
2 changed files with 146 additions and 0 deletions
@@ -0,0 +1,120 @@
<?php
namespace Moko\Plugin\System\MokoSuiteSight\Helper;
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\Database\DatabaseInterface;
/**
* Dashboard management — CRUD, widget layout, user assignments, sharing.
*/
class DashboardHelper
{
/**
* Get dashboards for the current user.
*/
public static function getForUser(?int $userId = null): array
{
$userId = $userId ?: (int) Factory::getApplication()->getIdentity()->id;
$db = Factory::getContainer()->get(DatabaseInterface::class);
$db->setQuery($db->getQuery(true)
->select('d.id, d.title, d.description, d.is_default, d.shared, d.created_at')
->select('(SELECT COUNT(*) FROM #__mokosuitesight_widgets w WHERE w.dashboard_id = d.id) AS widget_count')
->from($db->quoteName('#__mokosuitesight_dashboards', 'd'))
->where('(d.user_id = ' . (int) $userId . ' OR d.shared = 1)')
->order('d.is_default DESC, d.title ASC'));
return $db->loadObjectList() ?: [];
}
/**
* Get a dashboard with all its widgets.
*/
public static function getWithWidgets(int $dashboardId): ?object
{
$db = Factory::getContainer()->get(DatabaseInterface::class);
$db->setQuery($db->getQuery(true)
->select('d.*')
->from($db->quoteName('#__mokosuitesight_dashboards', 'd'))
->where('d.id = ' . (int) $dashboardId));
$dashboard = $db->loadObject();
if (!$dashboard) {
return null;
}
$db->setQuery($db->getQuery(true)
->select('w.*')
->from($db->quoteName('#__mokosuitesight_widgets', 'w'))
->where('w.dashboard_id = ' . (int) $dashboardId)
->order('w.position ASC'));
$dashboard->widgets = $db->loadObjectList() ?: [];
foreach ($dashboard->widgets as &$w) {
$w->config = json_decode($w->config ?? '{}');
}
return $dashboard;
}
/**
* Create a new dashboard.
*/
public static function create(string $title, ?string $description = null): object
{
$db = Factory::getContainer()->get(DatabaseInterface::class);
$filter = \Joomla\Filter\InputFilter::getInstance();
$dashboard = (object) [
'title' => $filter->clean($title, 'STRING'),
'description' => $description ? $filter->clean($description, 'STRING') : null,
'user_id' => (int) Factory::getApplication()->getIdentity()->id,
'layout' => '{}',
'shared' => 0,
'is_default' => 0,
'created_at' => Factory::getDate()->toSql(),
];
$db->insertObject('#__mokosuitesight_dashboards', $dashboard, 'id');
return (object) ['success' => true, 'dashboard_id' => (int) $dashboard->id];
}
/**
* Add a widget to a dashboard.
*/
public static function addWidget(int $dashboardId, string $type, string $dataSource, array $config = []): object
{
$allowedTypes = ['counter', 'line_chart', 'bar_chart', 'pie_chart', 'gauge', 'table', 'sparkline', 'heatmap', 'funnel'];
if (!in_array($type, $allowedTypes, true)) {
throw new \InvalidArgumentException('Invalid widget type.');
}
$db = Factory::getContainer()->get(DatabaseInterface::class);
// Get next position
$db->setQuery($db->getQuery(true)
->select('COALESCE(MAX(position), 0) + 1')
->from('#__mokosuitesight_widgets')
->where('dashboard_id = ' . (int) $dashboardId));
$position = (int) $db->loadResult();
$widget = (object) [
'dashboard_id' => $dashboardId,
'type' => $type,
'data_source' => $dataSource,
'config' => json_encode($config),
'position' => $position,
'width' => $config['width'] ?? 6,
'height' => $config['height'] ?? 4,
'created_at' => Factory::getDate()->toSql(),
];
$db->insertObject('#__mokosuitesight_widgets', $widget, 'id');
return (object) ['success' => true, 'widget_id' => (int) $widget->id];
}
}
+26
View File
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<extension type="package" method="upgrade">
<name>Package - MokoSuite Insight</name>
<packagename>mokosuitesight</packagename>
<version>01.00.00</version>
<creationDate>2026-06-21</creationDate>
<author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail>
<authorUrl>https://mokoconsulting.tech</authorUrl>
<copyright>Copyright (C) 2026 Moko Consulting. All rights reserved.</copyright>
<license>GNU General Public License version 3 or later; see LICENSE</license>
<description>MokoSuite Insight - real-time dashboards, data visualization, KPI monitoring, alerting. Connects to all MokoSuite modules.</description>
<php_minimum>8.3</php_minimum>
<dlid prefix="dlid=" suffix=""/>
<blockChildUninstall>true</blockChildUninstall>
<scriptfile>script.php</scriptfile>
<files folder="packages">
<file type="plugin" id="plg_system_mokosuitesight" group="system">plg_system_mokosuitesight.zip</file>
<file type="component" id="com_mokosuitesight">com_mokosuitesight.zip</file>
</files>
<updateservers>
<server type="extension" priority="1" name="Package - MokoSuite Insight">https://git.mokoconsulting.tech/MokoConsulting/MokoSuiteInsight/updates.xml</server>
</updateservers>
</extension>