Add ISortableAction interface to ReactionTypeAction
authorJoshua Rüsweg <josh@bastelstu.be>
Tue, 10 Apr 2018 12:22:10 +0000 (14:22 +0200)
committerJoshua Rüsweg <josh@bastelstu.be>
Tue, 10 Apr 2018 12:22:10 +0000 (14:22 +0200)
See #2508

wcfsetup/install/files/lib/data/reaction/type/ReactionTypeAction.class.php

index 5a2f3eece4fee321d41e00ce889dd388f787fea4..726fc80396d4c758bd3a4632bced5866a3622a84 100644 (file)
@@ -2,6 +2,10 @@
 declare(strict_types=1);
 namespace wcf\data\reaction\type;
 use wcf\data\AbstractDatabaseObjectAction;
+use wcf\data\ISortableAction;
+use wcf\system\exception\PermissionDeniedException;
+use wcf\system\exception\UserInputException;
+use wcf\system\WCF;
 
 /**
  * ReactionType related actions.
@@ -15,4 +19,57 @@ use wcf\data\AbstractDatabaseObjectAction;
  * @method     ReactionTypeEditor[]            getObjects()
  * @method     ReactionTypeEditor              getSingleObject()
  */
-class ReactionTypeAction extends AbstractDatabaseObjectAction {}
+class ReactionTypeAction extends AbstractDatabaseObjectAction implements ISortableAction {
+       /**
+        * @inheritDoc
+        */
+       protected $permissionsDelete = ['admin.content.reaction.canManageReactionType'];
+       
+       /**
+        * @inheritDoc
+        */
+       protected $permissionsUpdate = ['admin.content.reaction.canManageReactionType'];
+       
+       /**
+        * @inheritDoc
+        */
+       protected $requireACP = ['delete', 'update', 'updatePosition'];
+       
+       /**
+        * @inheritDoc
+        */
+       public function validateUpdatePosition() {
+               // validate permissions
+               if (is_array($this->permissionsUpdate) && count($this->permissionsUpdate)) {
+                       WCF::getSession()->checkPermissions($this->permissionsUpdate);
+               }
+               else {
+                       throw new PermissionDeniedException();
+               }
+               
+               if (!isset($this->parameters['data']['structure'])) {
+                       throw new UserInputException('structure');
+               }
+               
+               $this->readInteger('offset', true, 'data');
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       public function updatePosition() {
+               $reactionTypeList = new ReactionTypeList();
+               $reactionTypeList->readObjects();
+               
+               $i = $this->parameters['data']['offset'];
+               WCF::getDB()->beginTransaction();
+               foreach ($this->parameters['data']['structure'][0] as $reactionTypeID) {
+                       $reactionType = $reactionTypeList->search($reactionTypeID);
+                       if ($reactionType === null) continue;
+                       
+                       $editor = new ReactionTypeEditor($reactionType);
+                       $editor->update(['showOrder' => $i++]);
+               }
+               WCF::getDB()->commitTransaction();
+       }
+}