Search for users by their user id
authorAlexander Ebert <ebert@woltlab.com>
Mon, 9 Jul 2018 12:27:55 +0000 (14:27 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 9 Jul 2018 12:27:55 +0000 (14:27 +0200)
See #2591

com.woltlab.wcf/objectType.xml
wcfsetup/install/files/lib/system/condition/UserUserIDCondition.class.php [new file with mode: 0644]

index 1e9f0f394ccae36253b7382914fd3a5b20b570b3..8775da7390a44b91184dc768162572251b4198d4 100644 (file)
                <!-- /user bulk processing conditions -->
                
                <!-- user search conditions -->
+               <type>
+                       <name>com.woltlab.wcf.userID</name>
+                       <definitionname>com.woltlab.wcf.condition.userSearch</definitionname>
+                       <classname>wcf\system\condition\UserUserIDCondition</classname>
+                       <conditiongroup>general</conditiongroup>
+               </type>
                <type>
                        <name>com.woltlab.wcf.username</name>
                        <definitionname>com.woltlab.wcf.condition.userSearch</definitionname>
diff --git a/wcfsetup/install/files/lib/system/condition/UserUserIDCondition.class.php b/wcfsetup/install/files/lib/system/condition/UserUserIDCondition.class.php
new file mode 100644 (file)
index 0000000..929e94a
--- /dev/null
@@ -0,0 +1,89 @@
+<?php
+declare(strict_types=1);
+namespace wcf\system\condition;
+use wcf\data\condition\Condition;
+use wcf\data\user\User;
+use wcf\data\user\UserList;
+use wcf\data\DatabaseObjectList;
+use wcf\system\WCF;
+
+/**
+ * Condition implementation for the user id of an user.
+ * 
+ * @author      Alexander Ebert
+ * @copyright   2001-2018 WoltLab GmbH
+ * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package     WoltLabSuite\Core\System\Condition
+ */
+class UserUserIDCondition extends AbstractSingleFieldCondition implements IContentCondition, IObjectListCondition, IUserCondition {
+       use TObjectListUserCondition;
+       
+       /**
+        * @inheritDoc
+        */
+       protected $label = 'wcf.user.userID';
+       
+       /**
+        * @var int|null
+        */
+       protected $userID;
+       
+       /**
+        * @inheritDoc
+        */
+       public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) {
+               if (!($objectList instanceof UserList)) {
+                       throw new \InvalidArgumentException("Object list is not an instance of '".UserList::class."', an instance of '".get_class($objectList)."' was given.");
+               }
+               
+               $objectList->getConditionBuilder()->add('user_table.userID = ?', [$conditionData['userID']]);
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       public function checkUser(Condition $condition, User $user) {
+               return $user->userID == $condition->userID;
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       public function showContent(Condition $condition) {
+               if (!WCF::getUser()->userID) return false;
+               
+               return $this->checkUser($condition, WCF::getUser());
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       protected function getFieldElement() {
+               return '<input type="number" name="userID" value="'.$this->userID.'" class="small">';
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       public function readFormParameters() {
+               if (!empty($_POST['userID'])) $this->userID = intval($_POST['userID']);
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       public function getData() {
+               if ($this->userID !== null) {
+                       return ['userID' => $this->userID];
+               }
+               
+               return null;
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       public function setData(Condition $condition) {
+               $this->userID = $condition->conditionData['userID'];
+       }
+}