Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package filter in the Extensions: Manage page #37838

Merged
merged 10 commits into from
Jun 6, 2022
Merged
10 changes: 10 additions & 0 deletions administrator/components/com_installer/forms/filter_manage.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@
<option value="">COM_INSTALLER_VALUE_CLIENT_SELECT</option>
</field>

<field
name="package_id"
type="package"
label="COM_INSTALLER_MANAGE_FILTER_PACKAGE_ID_LABEL"
desc="COM_INSTALLER_MANAGE_FILTER_PACKAGE_ID_DESC"
nikosdion marked this conversation as resolved.
Show resolved Hide resolved
onchange="this.form.submit();"
>
<option value="">COM_INSTALLER_VALUE_PACKAGE_ID_SELECT</option>
</field>

<field
name="type"
type="type"
Expand Down
37 changes: 37 additions & 0 deletions administrator/components/com_installer/src/Field/PackageField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_installer
*
* @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\Component\Installer\Administrator\Field;

use Joomla\CMS\Form\Field\ListField;
use Joomla\Component\Installer\Administrator\Helper\InstallerHelper;

/**
* Package field.
*
* Selects the extension ID of an extension of the "package" type.
*
* @since __DEPLOY_VERSION__
*/
class PackageField extends ListField
{
/**
* Method to get the field options.
*
* @return array The field option objects.
* @since __DEPLOY_VERSION__
*/
protected function getOptions()
{
$options = InstallerHelper::getPackageOptions();

return array_merge($options, parent::getOptions());
nikosdion marked this conversation as resolved.
Show resolved Hide resolved
}

nikosdion marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Object\CMSObject;
use Joomla\Database\DatabaseDriver;
use Joomla\Database\ParameterType;
use SimpleXMLElement;

Expand Down Expand Up @@ -119,6 +120,64 @@ public static function getStateOptions()
return $options;
}

/**
* Get a list of filter options for extensions of the "package" type.
*
* @return array
* @since __DEPLOY_VERSION__
*/
public static function getPackageOptions(): array
{
$options = [];

/** @var DatabaseDriver $db The application's database driver object */
$db = Factory::getContainer()->get('DatabaseDriver');
nikosdion marked this conversation as resolved.
Show resolved Hide resolved
$query = $db->getQuery(true)
->select(
[
$db->quoteName('extension_id'),
$db->quoteName('name'),
$db->quoteName('element')
]
)
nikosdion marked this conversation as resolved.
Show resolved Hide resolved
->from($db->quoteName('#__extensions'))
->where($db->quoteName('type') . ' = ' . $db->quote('package'));
$extensions = $db->setQuery($query)->loadObjectList() ?: [];

if (empty($extensions))
{
return $options;
}

$language = Factory::getApplication()->getLanguage();
$arrayKeys = array_map(
function (object $entry) use ($language): string
{
$language->load($entry->element, JPATH_ADMINISTRATOR);

return Text::_($entry->name);
},
$extensions
);
$arrayValues = array_map(
function (object $entry): int
{
return $entry->extension_id;
},
$extensions
);

$extensions = array_combine($arrayKeys, $arrayValues);
ksort($extensions);

foreach ($extensions as $label => $id)
{
$options[] = HTMLHelper::_('select.option', $id, $label);
}

return $options;
}

/**
* Get a list of filter options for the application statuses.
*
Expand Down
23 changes: 18 additions & 5 deletions administrator/components/com_installer/src/Model/ManageModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ protected function populateState($ordering = 'name', $direction = 'asc')
// Load the filter state.
$this->setState('filter.search', $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', '', 'string'));
$this->setState('filter.client_id', $this->getUserStateFromRequest($this->context . '.filter.client_id', 'filter_client_id', null, 'int'));
$this->setState('filter.package_id', $this->getUserStateFromRequest($this->context . '.filter.package_id', 'filter_package_id', null, 'int'));
$this->setState('filter.status', $this->getUserStateFromRequest($this->context . '.filter.status', 'filter_status', '', 'string'));
$this->setState('filter.type', $this->getUserStateFromRequest($this->context . '.filter.type', 'filter_type', '', 'string'));
$this->setState('filter.folder', $this->getUserStateFromRequest($this->context . '.filter.folder', 'filter_folder', '', 'string'));
Expand Down Expand Up @@ -329,11 +330,12 @@ protected function getListQuery()
->where('state = 0');

// Process select filters.
$status = $this->getState('filter.status', '');
$type = $this->getState('filter.type');
$clientId = $this->getState('filter.client_id', '');
$folder = $this->getState('filter.folder');
$core = $this->getState('filter.core', '');
$status = $this->getState('filter.status', '');
$type = $this->getState('filter.type');
$clientId = $this->getState('filter.client_id', '');
$folder = $this->getState('filter.folder');
$core = $this->getState('filter.core', '');
$packageId = $this->getState('filter.package_id', '');

if ($status !== '')
{
Expand Down Expand Up @@ -367,6 +369,17 @@ protected function getListQuery()
->bind(':clientid', $clientId, ParameterType::INTEGER);
}

if ($packageId !== '')
{
$packageId = (int) $packageId;
$query->where(
'((' . $db->quoteName('package_id') . ' = :package_id) OR '
. '(' . $db->quoteName('extension_id') . ' = :package_id_2))'
)
->bind(':package_id', $packageId, ParameterType::INTEGER)
->bind(':package_id_2', $packageId, ParameterType::INTEGER);
nikosdion marked this conversation as resolved.
Show resolved Hide resolved
}

if ($folder)
{
$folder = $folder === '*' ? '' : $folder;
Expand Down
3 changes: 3 additions & 0 deletions administrator/language/en-GB/com_installer.ini
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ COM_INSTALLER_LANGUAGES_AVAILABLE_LANGUAGES="Available Languages"
COM_INSTALLER_LANGUAGES_FILTER_SEARCH_DESC="Search in language name and language tag."
COM_INSTALLER_LANGUAGES_FILTER_SEARCH_LABEL="Search Languages"
COM_INSTALLER_LANGUAGES_TABLE_CAPTION="Table of Available Languages"
COM_INSTALLER_MANAGE_FILTER_PACKAGE_ID_LABEL="Package"
COM_INSTALLER_MANAGE_FILTER_PACKAGE_ID_DESC="Search for a package extension and extensions included with that package extension."
COM_INSTALLER_MANAGE_FILTER_SEARCH_DESC="Search in extension name. Prefix with ID: to search for an extension ID."
COM_INSTALLER_MANAGE_FILTER_SEARCH_LABEL="Search Extensions"
COM_INSTALLER_MANAGE_TABLE_CAPTION="Table of Extensions"
Expand Down Expand Up @@ -280,6 +282,7 @@ COM_INSTALLER_VALUE_CORE_SELECT="- Select Extensions -"
COM_INSTALLER_VALUE_CORE_YES="Core Extensions"
COM_INSTALLER_VALUE_FOLDER_NONAPPLICABLE="N/A"
COM_INSTALLER_VALUE_FOLDER_SELECT="- Select Folder -"
COM_INSTALLER_VALUE_PACKAGE_ID_SELECT="- Package -"
nikosdion marked this conversation as resolved.
Show resolved Hide resolved
COM_INSTALLER_VALUE_STATE_SELECT="- Select Status -"
COM_INSTALLER_VALUE_SUPPORTED_EXISTS="Download Key valid"
COM_INSTALLER_VALUE_SUPPORTED_MISSING="Download Key invalid"
Expand Down