diff --git a/admin/libraries/phocadownload/category/category.php b/admin/libraries/phocadownload/category/category.php index f89f953..e441a68 100755 --- a/admin/libraries/phocadownload/category/category.php +++ b/admin/libraries/phocadownload/category/category.php @@ -16,6 +16,7 @@ class PhocaDownloadCategory { + private static $categoriesCache = null; private static $categoryA = array(); private static $categoryF = array(); private static $categoryP = array(); @@ -245,5 +246,30 @@ public static function getPathTree($path = array(), $id = 0, $parent_id = 0, $ti } return $path; } + + + private static function loadCategoriesCache(): void { + if (self::$categoriesCache === null) { + $db = Factory::getDBO(); + $db->setQuery('SELECT a.*, null AS children FROM #__phocadownload_categories AS a ORDER BY a.ordering, a.id'); + $categories = $db->loadObjectList('id') ?? []; + + array_walk($categories, function ($category) use ($categories) { + if ($category->parent_id) { + if ($categories[$category->parent_id]->children === null) + $categories[$category->parent_id]->children = []; + $categories[$category->parent_id]->children[] = $category; + } + }); + + self::$categoriesCache = $categories; + } + } + + public static function getCategories(): array { + self::loadCategoriesCache(); + + return self::$categoriesCache; + } } ?> diff --git a/admin/libraries/phocadownload/html/batch.php b/admin/libraries/phocadownload/html/batch.php index f4de7f2..d02a544 100755 --- a/admin/libraries/phocadownload/html/batch.php +++ b/admin/libraries/phocadownload/html/batch.php @@ -11,11 +11,12 @@ use Joomla\CMS\Language\Text; use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Factory; +use Joomla\CMS\Layout\LayoutHelper; abstract class PhocaDownloadBatch { - public static function item($published, $category = 0) + /*public static function item($published, $category = 0) { // Create the copy/move options. $options = array( @@ -50,13 +51,88 @@ public static function item($published, $category = 0) '
', '', HTMLHelper::_( 'select.radiolist', $options, 'batch[move_copy]', '', 'value', 'text', 'm'), '
' ); + return implode("\n", $lines); + } +*/ + + private static function buildCategoryTree(array &$options, array $categories, string $treeTitle): void { + foreach ($categories as $category) { + $title = ($treeTitle ? $treeTitle . ' - ' : '') . $category->title; + $options[] = (object)[ + 'text' => $title . ($category->language === '*' ? '' : ' (' . $category->language . ')'), + 'value' => $category->id, + ]; + if ($category->children) + self::buildCategoryTree($options, $category->children, $title); + } + } + + public static function item($published, $category = 0) + { + // Create the copy/move options. + $options = array( + HTMLHelper::_('select.option', 'c', Text::_('JLIB_HTML_BATCH_COPY')), + HTMLHelper::_('select.option', 'm', Text::_('JLIB_HTML_BATCH_MOVE')) + ); + + $rootCategories = array_filter(PhocadownloadCategory::getCategories(), function($category) { + return !$category->parent_id; + }); + + $tree = []; + $tree[] = HTMLHelper::_('select.option', '', Text::_('JSELECT'), 'value', 'text'); + if ($category) { + $tree[] = HTMLHelper::_('select.option', 0, Text::_('JLIB_HTML_ADD_TO_ROOT'), 'value', 'text'); + } + self::buildCategoryTree($tree, $rootCategories, ''); + + $fancySelectData = [ + 'autocomplete' => 'off', + 'autofocus' => false, + 'class' => '', + 'description' => '', + 'disabled' => false, + 'group' => false, + 'id' => 'batch-category-id', + 'hidden' => false, + 'hint' => '', + 'label' => '', + 'labelclass' => '', + 'onchange' => '', + 'onclick' => '', + 'multiple' => false, + 'pattern' => '', + 'readonly' => false, + 'repeat' => false, + 'required' => false, + 'size' => 4, + 'spellcheck' => false, + 'validate' => '', + 'value' => '', + 'options' => $tree, + 'dataAttributes' => [], + 'dataAttribute' => '', + 'name' => 'batch[category_id]', + ]; + + // Create the batch selector to change select the category by which to move or copy. + $lines = array( + '', + '
', + LayoutHelper::render('joomla.form.field.list-fancy-select', $fancySelectData), + HTMLHelper::_( 'select.radiolist', $options, 'batch[move_copy]', '', 'value', 'text', 'm'), + '
' + ); + return implode("\n", $lines); } } diff --git a/checksum.json b/checksum.json index cecd093..11b1e80 100644 --- a/checksum.json +++ b/checksum.json @@ -1 +1 @@ -{"com_phocadownload_v5.0.0Beta.zip":{"key":"com_phocadownload_v5.0.0Beta.zip","extname":"com_phocadownload","version":"5.0.0Beta","checksum":"20941490400c5c7a3de22dcd565c5a71674d746bda0947409e17176ebbf5a91693893cd6fbd5b45c2e61d2658d4312fcaf5bf1269fd804ff36d3670cf536e3e8"},"com_phocadownload_v4.0.7.zip":{"key":"com_phocadownload_v4.0.7.zip","extname":"com_phocadownload","version":"4.0.7","checksum":"a0e91e9087d8fae4a0215c429391e6531f95bd6e62c84d667e7767bea44dbc3e020ee4800bdfbe7d36640c0b9b565984ad8af5b1f326608b788e5618679b8796"}} \ No newline at end of file +{"com_phocadownload_v5.0.0Beta.zip":{"key":"com_phocadownload_v5.0.0Beta.zip","extname":"com_phocadownload","version":"5.0.0Beta","checksum":"60224eaec714795c831ccf2145be6272561bf62cb831a5f28ce2b738d894e3d9d24c2e3805e2d769e36d50cdb21ead28572a76f80de58271a2ad31cd9915c43d"},"com_phocadownload_v4.0.7.zip":{"key":"com_phocadownload_v4.0.7.zip","extname":"com_phocadownload","version":"4.0.7","checksum":"85092b0c0de78f23abb348f1083bd6de10e46f0cecfa50aa984fd84a67a9a2255cd6fcc30467b75a3ea545d81959520a9d11d86299c5f0a306ace8821d8c8e50"}} \ No newline at end of file diff --git a/manifest.xml b/manifest.xml index 6e31b28..35cda59 100755 --- a/manifest.xml +++ b/manifest.xml @@ -29,7 +29,7 @@ https://github.com/PhocaCz/PhocaDownload/releases/download/4.0.7/com_phocadownload_v4.0.7.zip - a0e91e9087d8fae4a0215c429391e6531f95bd6e62c84d667e7767bea44dbc3e020ee4800bdfbe7d36640c0b9b565984ad8af5b1f326608b788e5618679b8796 + 85092b0c0de78f23abb348f1083bd6de10e46f0cecfa50aa984fd84a67a9a2255cd6fcc30467b75a3ea545d81959520a9d11d86299c5f0a306ace8821d8c8e50 stable @@ -39,4 +39,6 @@ administrator + +