Adds two new ACP search providers
authorMatthias Schmidt <gravatronics@live.com>
Sun, 16 Sep 2012 08:15:04 +0000 (10:15 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 16 Sep 2012 08:15:04 +0000 (10:15 +0200)
com.woltlab.wcf/acpSearchProvider.xml
wcfsetup/install/files/lib/system/search/acp/PackageACPSearchResultProvider.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/search/acp/UserACPSearchResultProvider.class.php [new file with mode: 0644]

index ee011875068cf7d47a9700178cc63912a8fde47a..887b138c1b44ac27e5bcdbad708b67a0d691d51f 100644 (file)
@@ -9,9 +9,17 @@
                        <classname><![CDATA[wcf\system\search\acp\OptionACPSearchResultProvider]]></classname>
                        <showorder>2</showorder>
                </acpsearchprovider>
-               <acpsearchprovider name="userGroupOption">
-                       <classname><![CDATA[wcf\system\search\acp\UserGroupOptionACPSearchResultProvider]]></classname>
+               <acpsearchprovider name="com.woltlab.wcf.user">
+                       <classname><![CDATA[wcf\system\search\acp\UserACPSearchResultProvider]]></classname>
                        <showorder>3</showorder>
                </acpsearchprovider>
+               <acpsearchprovider name="com.woltlab.wcf.userGroupOption">
+                       <classname><![CDATA[wcf\system\search\acp\UserGroupOptionACPSearchResultProvider]]></classname>
+                       <showorder>4</showorder>
+               </acpsearchprovider>
+               <acpsearchprovider name="com.woltlab.wcf.package">
+                       <classname><![CDATA[wcf\system\search\acp\PackageACPSearchResultProvider]]></classname>
+                       <showorder>5</showorder>
+               </acpsearchprovider>
        </import>
 </data>
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 (file)
index 0000000..2c80fe7
--- /dev/null
@@ -0,0 +1,72 @@
+<?php
+namespace wcf\system\search\acp;
+use wcf\system\database\util\PreparedStatementConditionBuilder;
+use wcf\system\package\PackageDependencyHandler;
+use wcf\system\request\LinkHandler;
+use wcf\system\WCF;
+
+/**
+ * ACP search result provider for packages.
+ * 
+ * @author     Matthias Schmidt
+ * @copyright  2001-2012 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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 (file)
index 0000000..c3c30d6
--- /dev/null
@@ -0,0 +1,44 @@
+<?php
+namespace wcf\system\search\acp;
+use wcf\data\user\group\UserGroup;
+use wcf\system\request\LinkHandler;
+use wcf\system\WCF;
+
+/**
+ * ACP search result provider for users.
+ * 
+ * @author     Matthias Schmidt
+ * @copyright  2001-2012 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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;
+       }
+}