Fixed show order calculation
authorMarcel Werk <burntime@woltlab.com>
Fri, 25 Jan 2013 01:29:56 +0000 (02:29 +0100)
committerMarcel Werk <burntime@woltlab.com>
Fri, 25 Jan 2013 01:29:56 +0000 (02:29 +0100)
wcfsetup/install/files/lib/data/page/menu/item/PageMenuItemEditor.class.php
wcfsetup/install/files/lib/system/package/plugin/PageMenuPackageInstallationPlugin.class.php

index 1603d374258323185fe950e1ef70f888a26077c0..089a1df49eb89ca37b7862ddc2853f28507742d4 100644 (file)
@@ -28,7 +28,7 @@ class PageMenuItemEditor extends DatabaseObjectEditor implements IEditableCached
         */
        public static function create(array $parameters = array()) {
                // calculate show order
-               $parameters['showOrder'] = self::getShowOrder($parameters['showOrder'], $parameters['menuPosition']);
+               $parameters['showOrder'] = self::getShowOrder($parameters['showOrder'], $parameters['menuPosition'], $parameters['parentMenuItem']);
                
                return parent::create($parameters);
        }
@@ -39,9 +39,6 @@ class PageMenuItemEditor extends DatabaseObjectEditor implements IEditableCached
         * @todo Handle language id and update related language item
         */
        public function update(array $parameters = array()) {
-               if (isset($parameters['menuPosition']) && isset($parameters['showOrder'])) {
-                       $this->updateShowOrder($parameters['showOrder'], $parameters['menuPosition']);
-               }
                
                parent::update($parameters);
        }
@@ -111,66 +108,6 @@ class PageMenuItemEditor extends DatabaseObjectEditor implements IEditableCached
                ));
        }
        
-       /**
-        * Updates show order for current menu item.
-        * 
-        * @param       integer         $showOrder
-        * @param       string          $menuPosition
-        */
-       protected function updateShowOrder($showOrder, $menuPosition) {
-               if ($menuPosition == $this->menuPosition) {
-                       if ($this->showOrder != $showOrder) {
-                               if ($showOrder < $this->showOrder) {
-                                       $sql = "UPDATE  wcf".WCF_N."_page_menu_item
-                                               SET     showOrder = showOrder + 1
-                                               WHERE   showOrder >= ?
-                                                       AND showOrder < ?
-                                                       AND menuPosition = ?";
-                                       $statement = WCF::getDB()->prepareStatement($sql);
-                                       $statement->execute(array(
-                                               $showOrder,
-                                               $this->showOrder,
-                                               $menuPosition
-                                       ));
-                               }
-                               else if ($showOrder > $this->showOrder) {
-                                       $sql = "UPDATE  wcf".WCF_N."_page_menu_item
-                                               SET     showOrder = showOrder - 1
-                                               WHERE   showOrder <= ?
-                                                       AND showOrder > ?
-                                                       AND menuPosition = ?";
-                                       $statement = WCF::getDB()->prepareStatement($sql);
-                                       $statement->execute(array(
-                                               $showOrder,
-                                               $this->showOrder,
-                                               $menuPosition
-                                       ));
-                               }
-                       }
-               }
-               else {
-                       $sql = "UPDATE  wcf".WCF_N."_page_menu_item
-                               SET     showOrder = showOrder - 1
-                               WHERE   showOrder >= ?
-                                       AND menuPosition = ?";
-                       $statement = WCF::getDB()->prepareStatement($sql);
-                       $statement->execute(array(
-                               $this->showOrder,
-                               $this->menuPosition
-                       ));
-                               
-                       $sql = "UPDATE  wcf".WCF_N."_page_menu_item
-                               SET     showOrder = showOrder + 1
-                               WHERE   showOrder >= ?
-                                       AND menuPosition = ?";
-                       $statement = WCF::getDB()->prepareStatement($sql);
-                       $statement->execute(array(
-                               $showOrder,
-                               $menuPosition
-                       ));
-               }
-       }
-       
        /**
         * Returns show order for a new menu item.
         * 
@@ -178,14 +115,18 @@ class PageMenuItemEditor extends DatabaseObjectEditor implements IEditableCached
         * @param       string          $menuPosition
         * @return      integer
         */
-       protected static function getShowOrder($showOrder, $menuPosition) {
+       protected static function getShowOrder($showOrder, $menuPosition, $parentMenuItem = '') {
                if ($showOrder == 0) {
                        // get next number in row
                        $sql = "SELECT  MAX(showOrder) AS showOrder
                                FROM    wcf".WCF_N."_page_menu_item
-                               WHERE   menuPosition = ?";
+                               WHERE   parentMenuItem = ?
+                                       AND menuPosition = ?";
                        $statement = WCF::getDB()->prepareStatement($sql);
-                       $statement->execute(array($menuPosition));
+                       $statement->execute(array(
+                               $parentMenuItem,
+                               $menuPosition
+                       ));
                        $row = $statement->fetchArray();
                        if (!empty($row)) $showOrder = intval($row['showOrder']) + 1;
                        else $showOrder = 1;
@@ -193,12 +134,14 @@ class PageMenuItemEditor extends DatabaseObjectEditor implements IEditableCached
                else {
                        $sql = "UPDATE  wcf".WCF_N."_page_menu_item
                                SET     showOrder = showOrder + 1
-                               WHERE   showOrder >= ?
-                                       AND menuPosition = ?";
+                               WHERE   parentMenuItem = ?
+                                       AND menuPosition = ?
+                                       AND showOrder >= ?";
                        $statement = WCF::getDB()->prepareStatement($sql);
                        $statement->execute(array(
-                               $showOrder,
-                               $menuPosition
+                               $parentMenuItem,
+                               $menuPosition,
+                               $showOrder
                        ));
                }
                
index f3b9cac00ed78c2235740ec5f18f10b57553ae21..cd1037e858f16dbe94f3dcb255f1f4b8d371b19b 100644 (file)
@@ -47,4 +47,11 @@ class PageMenuPackageInstallationPlugin extends AbstractMenuPackageInstallationP
        protected function cleanup() {
                PageMenuItemEditor::updateLandingPage();
        }
+       
+       /**
+        * @see wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::getShowOrder()
+        */
+       protected function getShowOrder($showOrder, $parentName = null, $columnName = null, $tableNameExtension = '') {
+               return $showOrder;
+       }
 }