From: Alexander Ebert Date: Mon, 9 Jul 2018 12:27:55 +0000 (+0200) Subject: Search for users by their user id X-Git-Tag: 5.2.0_Alpha_1~364^2~134 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=ea1d1e7613cf0a937370ae19b3f3ad2cecd6537b;p=GitHub%2FWoltLab%2FWCF.git Search for users by their user id See #2591 --- diff --git a/com.woltlab.wcf/objectType.xml b/com.woltlab.wcf/objectType.xml index 1e9f0f394c..8775da7390 100644 --- a/com.woltlab.wcf/objectType.xml +++ b/com.woltlab.wcf/objectType.xml @@ -1230,6 +1230,12 @@ + + com.woltlab.wcf.userID + com.woltlab.wcf.condition.userSearch + wcf\system\condition\UserUserIDCondition + general + com.woltlab.wcf.username com.woltlab.wcf.condition.userSearch 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 index 0000000000..929e94a2de --- /dev/null +++ b/wcfsetup/install/files/lib/system/condition/UserUserIDCondition.class.php @@ -0,0 +1,89 @@ + + * @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 ''; + } + + /** + * @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']; + } +}