From 65922589f20f9ec85bbfcbd282a3605d857db584 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Joshua=20R=C3=BCsweg?= Date: Wed, 1 Aug 2018 12:02:46 +0200 Subject: [PATCH] Add conditions for reactions See #2508 --- com.woltlab.wcf/objectType.xml | 150 +++++++++++++++++- .../UserReputationCondition.class.php | 73 +++++++++ 2 files changed, 217 insertions(+), 6 deletions(-) create mode 100644 wcfsetup/install/files/lib/system/condition/UserReputationCondition.class.php diff --git a/com.woltlab.wcf/objectType.xml b/com.woltlab.wcf/objectType.xml index fbce34f7cd..03c2686fe6 100644 --- a/com.woltlab.wcf/objectType.xml +++ b/com.woltlab.wcf/objectType.xml @@ -615,9 +615,31 @@ com.woltlab.wcf.condition.userGroupAssignment wcf\system\condition\UserIntegerPropertyCondition contents - likesReceived + positiveReactionsReceived 0 + + com.woltlab.wcf.negativeReactionsReceived + com.woltlab.wcf.condition.userGroupAssignment + wcf\system\condition\UserIntegerPropertyCondition + contents + negativeReactionsReceived + 0 + + + com.woltlab.wcf.neutralReactionsReceived + com.woltlab.wcf.condition.userGroupAssignment + wcf\system\condition\UserIntegerPropertyCondition + contents + neutralReactionsReceived + 0 + + + com.woltlab.wcf.userReputation + com.woltlab.wcf.condition.userGroupAssignment + wcf\system\condition\UserReputationCondition + contents + com.woltlab.wcf.userOptions com.woltlab.wcf.condition.userGroupAssignment @@ -702,9 +724,31 @@ com.woltlab.wcf.condition.trophy wcf\system\condition\UserIntegerPropertyCondition contents - likesReceived + positiveReactionsReceived 0 + + com.woltlab.wcf.negativeReactionsReceived + com.woltlab.wcf.condition.trophy + wcf\system\condition\UserIntegerPropertyCondition + contents + negativeReactionsReceived + 0 + + + com.woltlab.wcf.neutralReactionsReceived + com.woltlab.wcf.condition.trophy + wcf\system\condition\UserIntegerPropertyCondition + contents + neutralReactionsReceived + 0 + + + com.woltlab.wcf.userReputation + com.woltlab.wcf.condition.trophy + wcf\system\condition\UserReputationCondition + contents + com.woltlab.wcf.userOptions com.woltlab.wcf.condition.trophy @@ -835,9 +879,34 @@ wcf\system\condition\UserIntegerPropertyCondition com.woltlab.wcf.user contents - likesReceived + positiveReactionsReceived + 0 + + + com.woltlab.wcf.negativeReactionsReceived + com.woltlab.wcf.condition.notice + wcf\system\condition\UserIntegerPropertyCondition + com.woltlab.wcf.user + contents + negativeReactionsReceived 0 + + com.woltlab.wcf.neutralReactionsReceived + com.woltlab.wcf.condition.notice + wcf\system\condition\UserIntegerPropertyCondition + com.woltlab.wcf.user + contents + neutralReactionsReceived + 0 + + + com.woltlab.wcf.userReputation + com.woltlab.wcf.condition.notice + wcf\system\condition\UserReputationCondition + com.woltlab.wcf.user + contents + com.woltlab.wcf.user.userOptions com.woltlab.wcf.condition.notice @@ -1003,9 +1072,34 @@ wcf\system\condition\UserIntegerPropertyCondition com.woltlab.wcf.user contents - likesReceived + positiveReactionsReceived 0 + + com.woltlab.wcf.negativeReactionsReceived + com.woltlab.wcf.condition.ad + wcf\system\condition\UserIntegerPropertyCondition + com.woltlab.wcf.user + contents + negativeReactionsReceived + 0 + + + com.woltlab.wcf.neutralReactionsReceived + com.woltlab.wcf.condition.ad + wcf\system\condition\UserIntegerPropertyCondition + com.woltlab.wcf.user + contents + neutralReactionsReceived + 0 + + + com.woltlab.wcf.userReputation + com.woltlab.wcf.condition.ad + wcf\system\condition\UserReputationCondition + com.woltlab.wcf.user + contents + com.woltlab.wcf.user.userOptions com.woltlab.wcf.condition.ad @@ -1207,9 +1301,31 @@ com.woltlab.wcf.bulkProcessing.user.condition wcf\system\condition\UserIntegerPropertyCondition contents - likesReceived + positiveReactionsReceived 0 + + com.woltlab.wcf.negativeReactionsReceived + com.woltlab.wcf.bulkProcessing.user.condition + wcf\system\condition\UserIntegerPropertyCondition + contents + negativeReactionsReceived + 0 + + + com.woltlab.wcf.neutralReactionsReceived + com.woltlab.wcf.bulkProcessing.user.condition + wcf\system\condition\UserIntegerPropertyCondition + contents + neutralReactionsReceived + 0 + + + com.woltlab.wcf.userReputation + com.woltlab.wcf.bulkProcessing.user.condition + wcf\system\condition\UserReputationCondition + contents + com.woltlab.wcf.userOptions com.woltlab.wcf.bulkProcessing.user.condition @@ -1300,9 +1416,31 @@ com.woltlab.wcf.condition.userSearch wcf\system\condition\UserIntegerPropertyCondition contents - likesReceived + positiveReactionsReceived 0 + + com.woltlab.wcf.negativeReactionsReceived + com.woltlab.wcf.condition.userSearch + wcf\system\condition\UserIntegerPropertyCondition + contents + negativeReactionsReceived + 0 + + + com.woltlab.wcf.neutralReactionsReceived + com.woltlab.wcf.condition.userSearch + wcf\system\condition\UserIntegerPropertyCondition + contents + neutralReactionsReceived + 0 + + + com.woltlab.wcf.userReputation + com.woltlab.wcf.condition.userSearch + wcf\system\condition\UserReputationCondition + contents + com.woltlab.wcf.userOptions com.woltlab.wcf.condition.userSearch diff --git a/wcfsetup/install/files/lib/system/condition/UserReputationCondition.class.php b/wcfsetup/install/files/lib/system/condition/UserReputationCondition.class.php new file mode 100644 index 0000000000..c90171ca52 --- /dev/null +++ b/wcfsetup/install/files/lib/system/condition/UserReputationCondition.class.php @@ -0,0 +1,73 @@ + + * @package WoltLabSuite\Core\System\Condition + */ +class UserReputationCondition extends AbstractIntegerCondition implements IContentCondition, IObjectListCondition, IUserCondition { + use TObjectListUserCondition; + + /** + * @inheritDoc + */ + public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) { + if (!($objectList instanceof UserList)) { + throw new \InvalidArgumentException("Object list is no instance of '".UserList::class."', instance of '".get_class($objectList)."' given."); + } + + if (isset($conditionData['greaterThan'])) { + /** @noinspection PhpUndefinedFieldInspection */ + $objectList->getConditionBuilder()->add('(user_table.positiveReactionsReceived - user_table.negativeReactionsReceived) > ?', [$conditionData['greaterThan']]); + } + if (isset($conditionData['lessThan'])) { + $objectList->getConditionBuilder()->add('(user_table.positiveReactionsReceived - user_table.negativeReactionsReceived) < ?', [$conditionData['lessThan']]); + } + } + + /** + * @inheritDoc + */ + public function checkUser(Condition $condition, User $user) { + if ($condition->greaterThan !== null && ($user->positiveReactionsReceived - $user->negativeReactionsReceived) <= $condition->greaterThan) { + return false; + } + if ($condition->lessThan !== null && ($user->positiveReactionsReceived - $user->negativeReactionsReceived) >= $condition->lessThan) { + return false; + } + + return true; + } + + /** + * @inheritDoc + */ + protected function getIdentifier() { + return 'user_userReputation'; + } + + /** + * @inheritDoc + */ + protected function getLabel() { + return WCF::getLanguage()->get('wcf.user.condition.userReputation'); + } + + /** + * @inheritDoc + */ + public function showContent(Condition $condition) { + if (!WCF::getUser()->userID) return false; + + return $this->checkUser($condition, WCF::getUser()); + } +} -- 2.20.1