Add TUserLookupPageHandler
authorMatthias Schmidt <gravatronics@live.com>
Sun, 31 Jul 2016 10:52:00 +0000 (12:52 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 31 Jul 2016 10:52:26 +0000 (12:52 +0200)
wcfsetup/install/files/lib/system/page/handler/TUserLookupPageHandler.class.php [new file with mode: 0644]

diff --git a/wcfsetup/install/files/lib/system/page/handler/TUserLookupPageHandler.class.php b/wcfsetup/install/files/lib/system/page/handler/TUserLookupPageHandler.class.php
new file mode 100644 (file)
index 0000000..c82ea8e
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+namespace wcf\system\page\handler;
+use wcf\data\user\UserProfileList;
+
+/**
+ * Provides the `lookup` method for looking up users. 
+ * 
+ * @author     Matthias Schmidt
+ * @copyright  2001-2016 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    WoltLabSuite\Core\System\Page\Handler
+ * @since      3.0
+ */
+trait TUserLookupPageHandler {
+       /**
+        * @see ILookupPageHandler::lookup()
+        */
+       public function lookup($searchString) {
+               $userList = new UserProfileList();
+               $userList->getConditionBuilder()->add('user_table.username LIKE ?', ['%' . $searchString . '%']);
+               $userList->readObjects();
+               
+               $results = [];
+               foreach ($userList as $user) {
+                       $results[] = [
+                               'image' => $user->getAvatar()->getImageTag(48),
+                               'link' => $user->getLink(),
+                               'objectID' => $user->userID,
+                               'title' => $user->username
+                       ];
+               }
+               
+               return $results;
+       }
+}