Fix showOrder value for reactionTypes
authorJoshua Rüsweg <ruesweg@woltlab.com>
Fri, 10 May 2019 11:04:20 +0000 (13:04 +0200)
committerJoshua Rüsweg <ruesweg@woltlab.com>
Fri, 10 May 2019 11:04:20 +0000 (13:04 +0200)
See #2508

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

index dce9282938fc90a0d231d3dce841aa1e1e5bf75f..bff6c926db0b51e858d8d9147b622bb3a77b7aaf 100644 (file)
@@ -72,7 +72,20 @@ class ReactionTypeAddForm extends AbstractFormBuilderForm {
                                ShowOrderFormField::create()
                                        ->description('wcf.acp.reactionType.showOrder.description')
                                        ->required()
-                                       ->options(new ReactionTypeList()),
+                                       ->options(function () {
+                                               $list = new ReactionTypeList();
+                                               $list->sqlOrderBy = 'showOrder ASC';
+                                               $list->readObjects();
+                                               
+                                               $returnValues = [];
+                                               
+                                               foreach ($list as $reactionType) {
+                                                       $returnValues[$reactionType->showOrder + 1] = $reactionType->getTitle();
+                                               }
+                                               
+                                               return $returnValues;
+                                               
+                                       }),
                                IsDisabledFormField::create()
                                        ->label('wcf.acp.reactionType.isDisabled')
                        ]);
index af26b2e01de605a2322dcd271c0bff5463fabf92..09488edd87bdd0b515ae4c156c634308324eaafc 100644 (file)
@@ -40,6 +40,16 @@ class ReactionTypeAction extends AbstractDatabaseObjectAction implements ISortab
         * @inheritDoc
         */
        public function create() {
+               if (isset($this->parameters['data']['showOrder']) && $this->parameters['data']['showOrder'] !== null) {
+                       $sql = "UPDATE  wcf" . WCF_N . "_reaction_type
+                                       SET     showOrder = showOrder + 1
+                                       WHERE   showOrder >= ?";
+                       $statement = WCF::getDB()->prepareStatement($sql);
+                       $statement->execute([
+                               $this->parameters['data']['showOrder']
+                       ]);
+               }
+               
                /** @var ReactionType $reactionType */
                $reactionType = parent::create();
                $reactionTypeEditor = new ReactionTypeEditor($reactionType);
@@ -129,6 +139,27 @@ class ReactionTypeAction extends AbstractDatabaseObjectAction implements ISortab
                                }
                        }
                        
+                       // update show order
+                       if (isset($this->parameters['data']['showOrder']) && $this->parameters['data']['showOrder'] !== null) {
+                               $sql = "UPDATE  wcf" . WCF_N . "_reaction_type
+                                       SET     showOrder = showOrder + 1
+                                       WHERE   showOrder >= ?
+                                       AND     reactionTypeID <> ?";
+                               $statement = WCF::getDB()->prepareStatement($sql);
+                               $statement->execute([
+                                       $this->parameters['data']['showOrder'],
+                                       $object->reactionTypeID
+                               ]);
+                               
+                               $sql = "UPDATE  wcf" . WCF_N . "_reaction_type
+                                       SET     showOrder = showOrder - 1
+                                       WHERE   showOrder >= ?";
+                               $statement = WCF::getDB()->prepareStatement($sql);
+                               $statement->execute([
+                                       $object->showOrder
+                               ]);
+                       }
+                       
                        if (!empty($updateData)) {
                                $object->update($updateData);
                        }