diff --git a/administrator/components/com_installer/models/extension.php b/administrator/components/com_installer/models/extension.php index e997967c4d3ba..80960e56f3505 100644 --- a/administrator/components/com_installer/models/extension.php +++ b/administrator/components/com_installer/models/extension.php @@ -63,31 +63,56 @@ protected function _getList($query, $limitstart = 0, $limit = 0) $search = str_replace('/', ' ', $search); $db = $this->getDbo(); - // Process ordering and pagination. - if (in_array($listOrder, array('name', 'client_translated', 'type_translated', 'folder_translated')) - || (!empty($search) && stripos($search, 'id:') !== 0)) + // Define which fields have to be processed in a custom way because of translation. + $customOrderFields = array('name', 'client_translated', 'type_translated', 'folder_translated'); + + // Process searching, ordering and pagination for fields that need to be translated. + if (in_array($listOrder, $customOrderFields) || (!empty($search) && stripos($search, 'id:') !== 0)) { + // Get results from database and translate them. $db->setQuery($query); $result = $db->loadObjectList(); $this->translate($result); - // Search in the name. + // Process searching. if (!empty($search)) { $escapedSearchString = $this->refineSearchStringToRegex($search, '/'); + // By default search only the extension name field. + $searchFields = array('name'); + + // If in update sites view search also in the update site name field. + if ($this instanceof InstallerModelUpdatesites) + { + $searchFields[] = 'update_site_name'; + } + foreach ($result as $i => $item) { - if (!preg_match("/$escapedSearchString/i", $item->name)) + // Check if search string exists in any of the fields to be searched. + $found = 0; + foreach ($searchFields as $key => $field) + { + if (!$found && preg_match('/' . $escapedSearchString . '/i', $item->{$field})) + { + $found = 1; + } + } + + // If search string was not found in any of the fields searched remove it from results array. + if (!$found) { unset($result[$i]); } } } + // Process ordering. // Sort array object by selected ordering and selected direction. Sort is case insensative and using locale sorting. $result = ArrayHelper::sortObjects($result, $listOrder, strtolower($listDirn) == 'desc' ? -1 : 1, false, true); + // Process pagination. $total = count($result); $this->cache[$this->getStoreId('getTotal')] = $total; @@ -100,6 +125,7 @@ protected function _getList($query, $limitstart = 0, $limit = 0) return array_slice($result, $limitstart, $limit ? $limit : null); } + // Process searching, ordering and pagination for regular database fields. $query->order($db->quoteName($listOrder) . ' ' . $db->escape($listDirn)); $result = parent::_getList($query, $limitstart, $limit); $this->translate($result); diff --git a/administrator/components/com_installer/models/forms/filter_manage.xml b/administrator/components/com_installer/models/forms/filter_manage.xml index 697b04050f84e..7ed0277312f52 100644 --- a/administrator/components/com_installer/models/forms/filter_manage.xml +++ b/administrator/components/com_installer/models/forms/filter_manage.xml @@ -55,12 +55,12 @@ - - - - - - + + + + + + diff --git a/administrator/components/com_installer/models/forms/filter_updatesites.xml b/administrator/components/com_installer/models/forms/filter_updatesites.xml index c7e4b43cc2a32..60bf6fa60c683 100644 --- a/administrator/components/com_installer/models/forms/filter_updatesites.xml +++ b/administrator/components/com_installer/models/forms/filter_updatesites.xml @@ -59,12 +59,12 @@ - - - - - - + + + + + + diff --git a/administrator/components/com_installer/models/manage.php b/administrator/components/com_installer/models/manage.php index 63217b815cc85..cdd9b0486bf5f 100644 --- a/administrator/components/com_installer/models/manage.php +++ b/administrator/components/com_installer/models/manage.php @@ -34,8 +34,9 @@ public function __construct($config = array()) 'status', 'name', 'client_id', - 'type', - 'folder', + 'client', 'client_translated', + 'type', 'type_translated', + 'folder', 'folder_translated', 'extension_id', ); } @@ -333,6 +334,8 @@ protected function getListQuery() $query->where('extension_id = ' . (int) substr($search, 3)); } + // Note: The search for name, ordering and pagination are processed by the parent InstallerModel class (in extension.php). + return $query; } } diff --git a/administrator/components/com_installer/models/updatesites.php b/administrator/components/com_installer/models/updatesites.php index 3c08b2051860d..859a387692e1a 100644 --- a/administrator/components/com_installer/models/updatesites.php +++ b/administrator/components/com_installer/models/updatesites.php @@ -11,8 +11,6 @@ require_once __DIR__ . '/extension.php'; -use Joomla\Utilities\ArrayHelper; - /** * Installer Update Sites Model * @@ -38,9 +36,10 @@ public function __construct($config = array()) 'update_site_name', 'name', 'client_id', + 'client', 'client_translated', 'status', - 'type', - 'folder', + 'type', 'type_translated', + 'folder', 'folder_translated', 'update_site_id', 'enabled', ); @@ -171,12 +170,12 @@ protected function getListQuery() if ($clientId != '') { - $query->where('client_id = ' . (int) $clientId); + $query->where('e.client_id = ' . (int) $clientId); } if ($folder != '' && in_array($type, array('plugin', 'library', ''))) { - $query->where('folder = ' . $this->_db->quote($folder == '*' ? '' : $folder)); + $query->where('e.folder = ' . $this->_db->quote($folder == '*' ? '' : $folder)); } // Process search filter (update site id). @@ -187,65 +186,8 @@ protected function getListQuery() $query->where('s.update_site_id = ' . (int) substr($search, 3)); } - return $query; - } - - /** - * Returns an object list - * - * @param string $query The query - * @param int $limitstart Offset - * @param int $limit The number of records - * - * @return array - * - * @since 3.4 - */ - protected function _getList($query, $limitstart = 0, $limit = 0) - { - $ordering = $this->getState('list.ordering', 'name'); - $direction = $this->getState('list.direction', 'asc'); - $search = $this->getState('filter.search'); - - // Replace slashes so preg_match will work - $search = str_replace('/', ' ', $search); - $db = $this->getDbo(); - - if ($ordering == 'name' || (!empty($search) && stripos($search, 'id:') !== 0)) - { - $db->setQuery($query); - $result = $db->loadObjectList(); - $this->translate($result); + // Note: The search for name, ordering and pagination are processed by the parent InstallerModel class (in extension.php). - if (!empty($search) && (stripos($search, 'id:') !== 0)) - { - foreach ($result as $i => $item) - { - if (!preg_match("/$search/i", $item->name) && !preg_match("/$search/i", $item->update_site_name)) - { - unset($result[$i]); - } - } - } - - $result = ArrayHelper::sortObjects($result, $ordering, strtolower($direction) === 'desc' ? -1 : 1, true, true); - - $total = count($result); - $this->cache[$this->getStoreId('getTotal')] = $total; - - if ($total < $limitstart) - { - $limitstart = 0; - $this->setState('list.start', 0); - } - - return array_slice($result, $limitstart, $limit ? $limit : null); - } - - $query->order($db->quoteName($ordering) . ' ' . $direction); - $result = parent::_getList($query, $limitstart, $limit); - $this->translate($result); - - return $result; + return $query; } } diff --git a/administrator/components/com_installer/views/manage/tmpl/default.php b/administrator/components/com_installer/views/manage/tmpl/default.php index 5d37fea6d8392..042d9dad45de4 100644 --- a/administrator/components/com_installer/views/manage/tmpl/default.php +++ b/administrator/components/com_installer/views/manage/tmpl/default.php @@ -52,10 +52,10 @@ - + - + @@ -67,7 +67,7 @@ - + @@ -102,10 +102,10 @@ - client; ?> + client_translated; ?> - type); ?> + type_translated; ?> version != '' ? $item->version : ' '; ?> @@ -119,7 +119,7 @@ - folder != '' ? $item->folder : JText::_('COM_INSTALLER_TYPE_NONAPPLICABLE'); ?> + folder_translated; ?> extension_id; ?> diff --git a/administrator/components/com_installer/views/updatesites/tmpl/default.php b/administrator/components/com_installer/views/updatesites/tmpl/default.php index c50afbc1eca53..012792721aca9 100644 --- a/administrator/components/com_installer/views/updatesites/tmpl/default.php +++ b/administrator/components/com_installer/views/updatesites/tmpl/default.php @@ -49,13 +49,13 @@ - + - + - + @@ -97,13 +97,13 @@ - client; ?> + client_translated; ?> - type); ?> + type_translated; ?> - folder != '' ? $item->folder : JText::_('COM_INSTALLER_TYPE_NONAPPLICABLE'); ?> + folder_translated; ?> update_site_id; ?>