From: Matthias Schmidt Date: Sun, 16 Sep 2012 08:15:04 +0000 (+0200) Subject: Adds two new ACP search providers X-Git-Tag: 2.0.0_Beta_1~870^2~22^2~3^2~2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=6d600dc3a44ccb6b19338d857a19ab1ed0e6efbd;p=GitHub%2FWoltLab%2FWCF.git Adds two new ACP search providers --- diff --git a/com.woltlab.wcf/acpSearchProvider.xml b/com.woltlab.wcf/acpSearchProvider.xml index ee01187506..887b138c1b 100644 --- a/com.woltlab.wcf/acpSearchProvider.xml +++ b/com.woltlab.wcf/acpSearchProvider.xml @@ -9,9 +9,17 @@ 2 - - + + 3 + + + 4 + + + + 5 + diff --git a/wcfsetup/install/files/lib/system/search/acp/PackageACPSearchResultProvider.class.php b/wcfsetup/install/files/lib/system/search/acp/PackageACPSearchResultProvider.class.php new file mode 100644 index 0000000000..2c80fe7492 --- /dev/null +++ b/wcfsetup/install/files/lib/system/search/acp/PackageACPSearchResultProvider.class.php @@ -0,0 +1,72 @@ + + * @package com.woltlab.wcf + * @subpackage system.search.acp + * @category Community Framework + */ +class PackageACPSearchResultProvider implements IACPSearchResultProvider { + /** + * @see wcf\system\search\acp\IACPSearchResultProvider::search() + */ + public function search($query) { + if (!WCF::getSession()->getPermission('admin.system.package.canUpdatePackage') && !WCF::getSession()->getPermission('admin.system.package.canUninstallPackage')) { + return array(); + } + + $results = array(); + + // search by language item + $conditions = new PreparedStatementConditionBuilder(); + $conditions->add("languageID = ?", array(WCF::getLanguage()->languageID)); + $conditions->add("languageItem LIKE ?", array('wcf.acp.package.title.package%')); + $conditions->add("languageItemValue LIKE ?", array($query.'%')); + $conditions->add("packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies())); + + $sql = "SELECT languageItem + FROM wcf".WCF_N."_language_item + ".$conditions; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute($conditions->getParameters()); + + $packageIDs = array(); + while ($row = $statement->fetchArray()) { + $packageIDs[] = str_replace('wcf.acp.package.title.package', '', $row['languageItem']); + } + + $conditions = new PreparedStatementConditionBuilder(false); + if (!empty($packageIDs)) { + $conditions->add("packageID IN (?)", array($packageIDs)); + } + + $sql = "SELECT * + FROM wcf".WCF_N."_package + WHERE packageName LIKE ? + OR package LIKE ? + ".(count($conditions->getParameters()) ? "OR ".$conditions : ""); + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(array_merge($conditions->getParameters(), array( + $query.'%', + $query.'%' + ))); + + while ($package = $statement->fetchObject('wcf\data\package\Package')) { + $results[] = new ACPSearchResult($package->getName(), LinkHandler::getInstance()->getLink('PackageView', array( + 'id' => $package->packageID, + 'title' => $package->getName() + ))); + } + + return $results; + } +} diff --git a/wcfsetup/install/files/lib/system/search/acp/UserACPSearchResultProvider.class.php b/wcfsetup/install/files/lib/system/search/acp/UserACPSearchResultProvider.class.php new file mode 100644 index 0000000000..c3c30d660e --- /dev/null +++ b/wcfsetup/install/files/lib/system/search/acp/UserACPSearchResultProvider.class.php @@ -0,0 +1,44 @@ + + * @package com.woltlab.wcf + * @subpackage system.search.acp + * @category Community Framework + */ +class UserACPSearchResultProvider implements IACPSearchResultProvider { + /** + * @see wcf\system\search\acp\IACPSearchResultProvider::search() + */ + public function search($query) { + if (!WCF::getSession()->getPermission('admin.user.canEditUser')) { + return array(); + } + + $results = array(); + + $sql = "SELECT * + FROM wcf".WCF_N."_user + WHERE username LIKE ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(array($query.'%')); + + while ($user = $statement->fetchObject('wcf\data\user\User')) { + if (UserGroup::isAccessibleGroup($user->getGroupIDs())) { + $results[] = new ACPSearchResult($user->username, LinkHandler::getInstance()->getLink('UserEdit', array( + 'object' => $user + ))); + } + } + + return $results; + } +}