Restored page/menu/item/*.php
authorAlexander Ebert <ebert@woltlab.com>
Tue, 28 Aug 2012 15:49:02 +0000 (17:49 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 28 Aug 2012 15:49:02 +0000 (17:49 +0200)
wcfsetup/install/files/lib/data/page/menu/item/PageMenuItem.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/data/page/menu/item/PageMenuItemAction.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/data/page/menu/item/PageMenuItemEditor.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/data/page/menu/item/PageMenuItemList.class.php [new file with mode: 0644]

diff --git a/wcfsetup/install/files/lib/data/page/menu/item/PageMenuItem.class.php b/wcfsetup/install/files/lib/data/page/menu/item/PageMenuItem.class.php
new file mode 100644 (file)
index 0000000..da0cfff
--- /dev/null
@@ -0,0 +1,59 @@
+<?php
+namespace wcf\data\page\menu\item;
+use wcf\data\ProcessibleDatabaseObject;
+use wcf\system\application\ApplicationHandler;
+use wcf\system\menu\page\DefaultPageMenuItemProvider;
+use wcf\system\menu\ITreeMenuItem;
+use wcf\system\request\LinkHandler;
+
+/**
+ * Represents an page menu item.
+ * 
+ * @author     Alexander Ebert
+ * @copyright  2001-2011 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf
+ * @subpackage data.page.menu.item
+ * @category   Community Framework
+ */
+class PageMenuItem extends ProcessibleDatabaseObject implements ITreeMenuItem {
+       /**
+        * @see wcf\data\DatabaseObject::$databaseTableName
+        */
+       protected static $databaseTableName = 'page_menu_item';
+       
+       /**
+        * @see wcf\data\DatabaseObject::$databaseTableIndexName
+        */
+       protected static $databaseTableIndexName = 'menuItemID';
+       
+       /**
+        * @see wcf\data\ProcessibleDatabaseObject::$processorInterface
+        */
+       protected static $processorInterface = 'wcf\system\menu\page\IPageMenuItemProvider';
+       
+       /**
+        * @see wcf\data\ProcessibleDatabaseObject::getProcessor()
+        */
+       public function getProcessor() {
+               if (parent::getProcessor() === null) {
+                       $this->processor = new DefaultPageMenuItemProvider($this);
+               }
+               
+               return $this->processor;
+       }
+       
+       /**
+        * @see wcf\system\menu\ITreeMenuItem::getLink()
+        */
+       public function getLink() {
+               $abbreviation = ApplicationHandler::getInstance()->getAbbreviation($this->packageID);
+               
+               $parameters = array();
+               if ($abbreviation) {
+                       $parameters['application'] = $abbreviation;
+               }
+               
+               return LinkHandler::getInstance()->getLink(null, $parameters, $this->menuItemLink);
+       }
+}
diff --git a/wcfsetup/install/files/lib/data/page/menu/item/PageMenuItemAction.class.php b/wcfsetup/install/files/lib/data/page/menu/item/PageMenuItemAction.class.php
new file mode 100644 (file)
index 0000000..6cdf31d
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+namespace wcf\data\page\menu\item;
+use wcf\data\AbstractDatabaseObjectAction;
+
+/**
+ * Executes page menu item-related actions.
+ * 
+ * @author     Alexander Ebert
+ * @copyright  2001-2011 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf
+ * @subpackage data.page.menu.item
+ * @category   Community Framework
+ */
+class PageMenuItemAction extends AbstractDatabaseObjectAction {
+       /**
+        * @see wcf\data\AbstractDatabaseObjectAction::$className
+        */
+       protected $className = 'wcf\data\page\menu\item\PageMenuItemEditor';
+}
diff --git a/wcfsetup/install/files/lib/data/page/menu/item/PageMenuItemEditor.class.php b/wcfsetup/install/files/lib/data/page/menu/item/PageMenuItemEditor.class.php
new file mode 100644 (file)
index 0000000..298bdb7
--- /dev/null
@@ -0,0 +1,188 @@
+<?php
+namespace wcf\data\page\menu\item;
+use wcf\data\DatabaseObjectEditor;
+use wcf\data\IEditableCachedObject;
+use wcf\system\cache\CacheHandler;
+use wcf\system\WCF;
+
+/**
+ * Provides functions to edit page menu items.
+ * 
+ * @author     Alexander Ebert
+ * @copyright  2001-2011 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf
+ * @subpackage data.page.menu.item
+ * @category   Community Framework
+ */
+class PageMenuItemEditor extends DatabaseObjectEditor implements IEditableCachedObject {
+       /**
+        * @see wcf\data\DatabaseObjectDecorator::$baseClass
+        */
+       protected static $baseClass = 'wcf\data\page\menu\item\PageMenuItem';
+       
+       /**
+        * @see wcf\data\IEditableObject::create()
+        * 
+        * @todo Handle language id and create related language item
+        */
+       public static function create(array $parameters = array()) {
+               // calculate show order
+               $parameters['showOrder'] = self::getShowOrder($parameters['showOrder'], $parameters['menuPosition']);
+               
+               return parent::create($parameters);
+       }
+       
+       /**
+        * @see wcf\data\IEditableObject::update()
+        * 
+        * @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);
+       }
+       
+       /**
+        * @see wcf\data\IEditableObject::delete()
+        */
+       public function delete() {
+               // update show order
+               $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
+               ));
+               
+               parent::delete();
+       }
+       
+       /**
+        * Updates the positions of a page menu item directly.
+        *
+        * @param       integer         $menuItemID
+        * @param       string          $menuPosition
+        * @param       integer         $showOrder
+        */
+       public static function setShowOrder($menuItemID, $menuPosition = 'header', $showOrder = 1) {
+               // Update
+               $sql = "UPDATE  wcf".WCF_N."_page_menu_item
+                       SET     showOrder = ?,
+                               menuPosition = ?
+                       WHERE   menuItemID = ?";
+               $statement = WCF::getDB()->prepareStatement($sql);
+               $statement->execute(array(
+                       $showOrder,
+                       $menuPosition,
+                       $menuItemID
+               ));
+       }
+       
+       /**
+        * 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.
+        * 
+        * @param       integer         $showOrder
+        * @param       string          $menuPosition
+        * @return      integer
+        */
+       protected static function getShowOrder($showOrder, $menuPosition) {
+               if ($showOrder == 0) {
+                       // get next number in row
+                       $sql = "SELECT  MAX(showOrder) AS showOrder
+                               FROM    wcf".WCF_N."_page_menu_item
+                               WHERE   menuPosition = ?";
+                       $statement = WCF::getDB()->prepareStatement($sql);
+                       $statement->execute(array($menuPosition));
+                       $row = $statement->fetchArray();
+                       if (!empty($row)) $showOrder = intval($row['showOrder']) + 1;
+                       else $showOrder = 1;
+               }
+               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(
+                               $showOrder,
+                               $menuPosition
+                       ));
+               }
+               
+               return $showOrder;
+       }
+       
+       /**
+        * @see wcf\data\IEditableCachedObject::resetCache()
+        */
+       public static function resetCache() {
+               CacheHandler::getInstance()->clear(WCF_DIR.'cache', 'cache.pageMenu-*.php');
+       }
+}
diff --git a/wcfsetup/install/files/lib/data/page/menu/item/PageMenuItemList.class.php b/wcfsetup/install/files/lib/data/page/menu/item/PageMenuItemList.class.php
new file mode 100644 (file)
index 0000000..b4c11f7
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+namespace wcf\data\page\menu\item;
+use wcf\data\DatabaseObjectList;
+
+/**
+ * Represents a list of page menu items.
+ * 
+ * @author     Alexander Ebert
+ * @copyright  2001-2011 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf
+ * @subpackage data.page.menu.item
+ * @category   Community Framework
+ */
+class PageMenuItemList extends DatabaseObjectList {
+       /**
+        * @see wcf\data\DatabaseObjectList::$className
+        */
+       public $className = 'wcf\data\page\menu\item\PageMenuItem';
+}