From 71c6d7d09629405dc5b91faec07c807f44104617 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sat, 18 Aug 2012 15:51:26 +0200 Subject: [PATCH] Enhanced ACP search provider API --- .../search/acp/ACPSearchHandler.class.php | 4 ++++ .../search/acp/ACPSearchResultList.class.php | 14 ++++++++++++++ .../acp/IACPSearchResultProvider.class.php | 3 +-- .../MenuItemACPSearchResultProvider.class.php | 14 +++----------- .../OptionACPSearchResultProvider.class.php | 18 +++++++----------- ...roupOptionACPSearchResultProvider.class.php | 18 +++++------------- 6 files changed, 34 insertions(+), 37 deletions(-) diff --git a/wcfsetup/install/files/lib/system/search/acp/ACPSearchHandler.class.php b/wcfsetup/install/files/lib/system/search/acp/ACPSearchHandler.class.php index a13b78df2e..7d77476adb 100644 --- a/wcfsetup/install/files/lib/system/search/acp/ACPSearchHandler.class.php +++ b/wcfsetup/install/files/lib/system/search/acp/ACPSearchHandler.class.php @@ -72,6 +72,10 @@ class ACPSearchHandler extends SingletonFactory { $resultList->addResult($result); } + // sort list and reduce results + $resultList->sort(); + $resultList->reduceResultsTo($maxResultsPerProvider); + $data[] = $resultList; $totalResultCount += count($resultList); } diff --git a/wcfsetup/install/files/lib/system/search/acp/ACPSearchResultList.class.php b/wcfsetup/install/files/lib/system/search/acp/ACPSearchResultList.class.php index 75b92d9904..12ec661ec2 100644 --- a/wcfsetup/install/files/lib/system/search/acp/ACPSearchResultList.class.php +++ b/wcfsetup/install/files/lib/system/search/acp/ACPSearchResultList.class.php @@ -71,6 +71,20 @@ class ACPSearchResultList implements \Countable, \Iterator { $this->rewind(); } + /** + * Reduces the result collection to specified size. + * + * @param integer $size + */ + public function reduceResultsTo($size) { + $count = count($this->results); + + if ($size && ($count > $size)) { + $reduceBy = $count - $size; + $this->reduceResults($reduceBy); + } + } + /** * Sorts results by title. */ diff --git a/wcfsetup/install/files/lib/system/search/acp/IACPSearchResultProvider.class.php b/wcfsetup/install/files/lib/system/search/acp/IACPSearchResultProvider.class.php index 8fc375b8c5..ec17358b7b 100644 --- a/wcfsetup/install/files/lib/system/search/acp/IACPSearchResultProvider.class.php +++ b/wcfsetup/install/files/lib/system/search/acp/IACPSearchResultProvider.class.php @@ -16,8 +16,7 @@ interface IACPSearchResultProvider { * Returns a list of seach results for given query. * * @param string $query - * @param integer $limit * @return array */ - public function search($query, $limit = 5); + public function search($query); } diff --git a/wcfsetup/install/files/lib/system/search/acp/MenuItemACPSearchResultProvider.class.php b/wcfsetup/install/files/lib/system/search/acp/MenuItemACPSearchResultProvider.class.php index c7af47b1ee..571c027a8e 100644 --- a/wcfsetup/install/files/lib/system/search/acp/MenuItemACPSearchResultProvider.class.php +++ b/wcfsetup/install/files/lib/system/search/acp/MenuItemACPSearchResultProvider.class.php @@ -1,6 +1,5 @@ prepareStatement($sql); // don't use a limit here $statement->execute($conditions->getParameters()); - $count = 0; - while ($row = $statement->fetchArray()) { - if ($count == $limit) { - break; - } - - $menuItem = new ACPMenuItem(null, $row); + while ($menuItem = $statement->fetchObject('wcf\data\acp\menu\item\ACPMenuItem')) { if (!$this->validate($menuItem)) { continue; } - $results[] = new ACPSearchResult($languageItems[$row['menuItem']], $row['menuItemLink'] . SID_ARG_1ST); - $count++; + $results[] = new ACPSearchResult($languageItems[$menuItem->menuItem], $menuItem->getLink()); } return $results; diff --git a/wcfsetup/install/files/lib/system/search/acp/OptionACPSearchResultProvider.class.php b/wcfsetup/install/files/lib/system/search/acp/OptionACPSearchResultProvider.class.php index d7ef7ed330..39a5eaf0da 100644 --- a/wcfsetup/install/files/lib/system/search/acp/OptionACPSearchResultProvider.class.php +++ b/wcfsetup/install/files/lib/system/search/acp/OptionACPSearchResultProvider.class.php @@ -1,9 +1,6 @@ prepareStatement($sql, $limit); + $statement = WCF::getDB()->prepareStatement($sql); // don't use a limit here $statement->execute($conditions->getParameters()); $languageItems = array(); $optionNames = array(); @@ -71,23 +68,22 @@ class OptionACPSearchResultProvider extends AbstractCategorizedACPSearchResultPr $sql = "SELECT optionName, categoryName, options, permissions FROM wcf".WCF_N."_option ".$conditions; - $statement = WCF::getDB()->prepareStatement($sql); + $statement = WCF::getDB()->prepareStatement($sql); // don't use a limit here $statement->execute($conditions->getParameters()); - while ($row = $statement->fetchArray()) { + while ($option = $statement->fetchObject('wcf\data\option\Option')) { // category is not accessible - if (!$this->isValid($row['categoryName'])) { + if (!$this->isValid($option->categoryName)) { continue; } // option is not accessible - $option = new Option(null, $row); if (!$this->validate($option)) { continue; } - $link = LinkHandler::getInstance()->getLink('Option', array('id' => $this->getCategoryID($row['categoryName'])), 'optionName='.$row['optionName'].'#'.$this->getCategoryName($row['categoryName'])); - $results[] = new ACPSearchResult($languageItems[$row['optionName']], $link); + $link = LinkHandler::getInstance()->getLink('Option', array('id' => $this->getCategoryID($option->categoryName)), 'optionName='.$option->optionName.'#'.$this->getCategoryName($option->categoryName)); + $results[] = new ACPSearchResult($languageItems[$option->optionName], $link); } return $results; diff --git a/wcfsetup/install/files/lib/system/search/acp/UserGroupOptionACPSearchResultProvider.class.php b/wcfsetup/install/files/lib/system/search/acp/UserGroupOptionACPSearchResultProvider.class.php index 9fa9af9b6e..0b153b29db 100644 --- a/wcfsetup/install/files/lib/system/search/acp/UserGroupOptionACPSearchResultProvider.class.php +++ b/wcfsetup/install/files/lib/system/search/acp/UserGroupOptionACPSearchResultProvider.class.php @@ -1,6 +1,5 @@ prepareStatement($sql); // don't use a limit here $statement->execute($conditions->getParameters()); - $count = 0; - while ($row = $statement->fetchArray()) { - if ($count == $limit) { - break; - } - + while ($userGroupOption = $statement->fetchObject('wcf\data\user\group\option\UserGroupOption')) { // category is not accessible - if (!$this->isValid($row['categoryName'])) { + if (!$this->isValid($userGroupOption->categoryName)) { continue; } // option is not accessible - $userGroupOption = new UserGroupOption(null, $row); if (!$this->validate($userGroupOption)) { continue; } - $link = LinkHandler::getInstance()->getLink('UserGroupOption', array('id' => $row['optionID'])); - $results[] = new ACPSearchResult($languageItems[$row['optionName']], $link); - $count++; + $link = LinkHandler::getInstance()->getLink('UserGroupOption', array('id' => $userGroupOption->optionID)); + $results[] = new ACPSearchResult($languageItems[$userGroupOption->optionName], $link); } return $results; -- 2.20.1