Added getList() for WCF.Search.User
authorAlexander Ebert <ebert@woltlab.com>
Wed, 28 Dec 2011 16:05:21 +0000 (17:05 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 28 Dec 2011 16:05:21 +0000 (17:05 +0100)
wcfsetup/install/files/lib/data/user/UserAction.class.php

index 560913a818c5f596fc04ccd82f661259a9b57bf5..9bbfa4b76c4aba701a560b9ec69d7a6caa127c95 100644 (file)
@@ -5,6 +5,7 @@ use wcf\data\user\group\UserGroup;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
 use wcf\system\exception\ValidateActionException;
 use wcf\system\WCF;
+use wcf\util\StringUtil;
 
 /**
  * Executes user-related actions.
@@ -148,4 +149,43 @@ class UserAction extends AbstractDatabaseObjectAction {
                        }
                }
        }
+       
+       public function validateGetList() {
+       }
+       
+       public function getList() {
+               $searchString = $this->parameters['data']['searchString'];
+               $list = array();
+       
+               if ($this->parameters['data']['includeUserGroups']) {
+                       $accessibleGroups = UserGroup::getAccessibleGroups();
+                       foreach ($accessibleGroups as $group) {
+                               $groupName = WCF::getLanguage()->get($group->groupName);
+                               $pos = StringUtil::indexOfIgnoreCase($groupName, $searchString);
+                               if ($pos !== false && $pos == 0) {
+                                       $list[] = array(
+                                               'label' => $groupName,
+                                               'objectID' => $group->groupID,
+                                               'type' => 'group'
+                                       );
+                               }
+                       }
+               }
+       
+               // find users
+               $sql = "SELECT  userID, username
+                       FROM    wcf".WCF_N."_user
+                       WHERE   username LIKE ?";
+               $statement = WCF::getDB()->prepareStatement($sql);
+               $statement->execute(array($searchString.'%'));
+               while ($row = $statement->fetchArray()) {
+                       $list[] = array(
+                               'label' => $row['username'],
+                               'objectID' => $row['userID'],
+                               'type' => 'user'
+                       );
+               }
+       
+               return $list;
+       }
 }