From e0eee892d02b32a452cc58b0413194e16571f3ae Mon Sep 17 00:00:00 2001 From: Jonathan Miller Date: Sat, 30 May 2026 19:38:29 -0500 Subject: [PATCH] feat(demo): multi-select list for tables, formatted next-reset with timezone - SnapshotTablesField now renders as a multi-select ' + . ''; + } +} diff --git a/src/packages/plg_system_mokowaas/Field/SnapshotTablesField.php b/src/packages/plg_system_mokowaas/Field/SnapshotTablesField.php index 7a4e8912..c61efa6e 100644 --- a/src/packages/plg_system_mokowaas/Field/SnapshotTablesField.php +++ b/src/packages/plg_system_mokowaas/Field/SnapshotTablesField.php @@ -8,9 +8,9 @@ * FILE INFORMATION * DEFGROUP: Joomla.Plugin * INGROUP: MokoWaaS - * VERSION: 02.25.03 + * VERSION: 02.26.00 * PATH: /src/Field/SnapshotTablesField.php - * BRIEF: Multi-select field that loads DB tables with sensible defaults pre-checked + * BRIEF: Multi-select list field that loads DB tables with sensible defaults */ namespace Moko\Plugin\System\MokoWaaS\Field; @@ -18,16 +18,16 @@ namespace Moko\Plugin\System\MokoWaaS\Field; defined('_JEXEC') or die; use Joomla\CMS\Factory; -use Joomla\CMS\Form\Field\CheckboxesField; +use Joomla\CMS\Form\Field\ListField; +use Joomla\CMS\HTML\HTMLHelper; /** - * Renders a checkbox list of all Joomla database tables, with content-related - * tables pre-selected by default. Tables are grouped by category (content, - * users, menus, modules, other). + * Renders a multi-select list box of all Joomla database tables, with + * content-related tables pre-selected by default. * - * @since 02.25.00 + * @since 02.26.00 */ -class SnapshotTablesField extends CheckboxesField +class SnapshotTablesField extends ListField { protected $type = 'SnapshotTables'; @@ -56,17 +56,17 @@ class SnapshotTablesField extends CheckboxesField ]; /** - * Group labels for table categorisation. + * Table suffixes grouped by category for optgroup display. * * @var array * @since 02.25.00 */ private const TABLE_GROUPS = [ - 'content' => ['content', 'categories', 'fields', 'tags', 'contentitem_tag_map', 'ucm_content', 'ucm_history'], - 'users' => ['users', 'user_usergroup_map', 'user_profiles', 'usergroups', 'user_keys', 'user_mfa'], - 'menus' => ['menu', 'menu_types'], - 'modules' => ['modules', 'modules_menu'], - 'assets' => ['assets'], + 'Content' => ['content', 'categories', 'fields', 'fields_values', 'fields_groups', 'tags', 'contentitem_tag_map', 'ucm_content', 'ucm_history'], + 'Users' => ['users', 'user_usergroup_map', 'user_profiles', 'usergroups', 'user_keys', 'user_mfa'], + 'Menus' => ['menu', 'menu_types'], + 'Modules' => ['modules', 'modules_menu'], + 'Assets' => ['assets'], ]; protected function getOptions() @@ -75,68 +75,65 @@ class SnapshotTablesField extends CheckboxesField $prefix = $db->getPrefix(); $tables = $db->getTableList(); - $options = []; + $grouped = []; foreach ($tables as $table) { - // Only show tables with the site's prefix if (strpos($table, $prefix) !== 0) { continue; } - // Convert real table name to #__ notation - $logical = '#__' . substr($table, strlen($prefix)); + $suffix = substr($table, strlen($prefix)); + $logical = '#__' . $suffix; - // Determine group for display ordering $group = 'Other'; foreach (self::TABLE_GROUPS as $groupName => $patterns) { - $suffix = substr($table, strlen($prefix)); - - foreach ($patterns as $pattern) + if (in_array($suffix, $patterns, true)) { - if ($suffix === $pattern) - { - $group = ucfirst($groupName); - break 2; - } + $group = $groupName; + break; } } - $obj = (object) [ - 'value' => $logical, - 'text' => $logical, - 'disable' => false, - 'class' => '', - 'onclick' => '', - ]; - - $options[$group][] = $obj; + $grouped[$group][] = HTMLHelper::_('select.option', $logical, $logical); } - // Flatten with group headers: content tables first, then alphabetical + // Build options with optgroups: priority groups first + $options = []; $priority = ['Content', 'Users', 'Menus', 'Modules', 'Assets']; - $sorted = []; foreach ($priority as $g) { - if (isset($options[$g])) + if (!empty($grouped[$g])) { - $sorted = array_merge($sorted, $options[$g]); - unset($options[$g]); + $options[] = HTMLHelper::_('select.optgroup', '— ' . $g . ' —'); + + foreach ($grouped[$g] as $opt) + { + $options[] = $opt; + } + + $options[] = HTMLHelper::_('select.optgroup', '— ' . $g . ' —'); + unset($grouped[$g]); } } - // Remaining tables (Other) - if (isset($options['Other'])) + if (!empty($grouped['Other'])) { - sort($options['Other']); - $sorted = array_merge($sorted, $options['Other']); + $options[] = HTMLHelper::_('select.optgroup', '— Other —'); + + foreach ($grouped['Other'] as $opt) + { + $options[] = $opt; + } + + $options[] = HTMLHelper::_('select.optgroup', '— Other —'); } - return $sorted; + return $options; } protected function getInput() @@ -148,10 +145,12 @@ class SnapshotTablesField extends CheckboxesField } elseif (is_string($this->value)) { - // Handle legacy textarea format (newline-separated) $this->value = array_filter(array_map('trim', explode("\n", $this->value))); } + // Force multiple attribute + $this->__set('multiple', true); + return parent::getInput(); } } diff --git a/src/packages/plg_system_mokowaas/mokowaas.xml b/src/packages/plg_system_mokowaas/mokowaas.xml index 2dcecb8f..5bf5e75c 100644 --- a/src/packages/plg_system_mokowaas/mokowaas.xml +++ b/src/packages/plg_system_mokowaas/mokowaas.xml @@ -314,13 +314,15 @@ description="PLG_SYSTEM_MOKOWAAS_DEMO_CRON_DESC" default="" hint="min hour day month weekday (e.g. 0 */6 * * *)" showon="demo_reset_schedule:custom" /> - + />