From: Marcel Werk Date: Fri, 8 Apr 2016 14:06:59 +0000 (+0200) Subject: Added box to page assignments X-Git-Tag: 3.0.0_Beta_1~1943 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=53cf1c00a32eaef7a81d2a9b071fec132937aaa8;p=GitHub%2FWoltLab%2FWCF.git Added box to page assignments --- diff --git a/wcfsetup/install/files/acp/templates/boxAdd.tpl b/wcfsetup/install/files/acp/templates/boxAdd.tpl index 75578026fd..e77a9bed1e 100644 --- a/wcfsetup/install/files/acp/templates/boxAdd.tpl +++ b/wcfsetup/install/files/acp/templates/boxAdd.tpl @@ -150,6 +150,17 @@ +
+
+
+ +
+
+ {event name='dataFields'} diff --git a/wcfsetup/install/files/acp/templates/menuAdd.tpl b/wcfsetup/install/files/acp/templates/menuAdd.tpl index 835015a405..c9b28c23e7 100644 --- a/wcfsetup/install/files/acp/templates/menuAdd.tpl +++ b/wcfsetup/install/files/acp/templates/menuAdd.tpl @@ -98,6 +98,17 @@ + +
+
+
+ +
+
{/if} {event name='dataFields'} diff --git a/wcfsetup/install/files/lib/acp/form/BoxAddForm.class.php b/wcfsetup/install/files/lib/acp/form/BoxAddForm.class.php index 807948f0d9..cc867941e6 100644 --- a/wcfsetup/install/files/lib/acp/form/BoxAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/BoxAddForm.class.php @@ -5,7 +5,9 @@ use wcf\data\box\BoxAction; use wcf\data\box\BoxEditor; use wcf\data\media\Media; use wcf\data\media\ViewableMediaList; +use wcf\data\page\PageNodeTree; use wcf\form\AbstractForm; +use wcf\system\database\util\PreparedStatementConditionBuilder; use wcf\system\exception\UserInputException; use wcf\system\language\LanguageFactory; use wcf\system\WCF; @@ -112,6 +114,12 @@ class BoxAddForm extends AbstractForm { */ public $images = []; + /** + * page ids + * @var integer[] + */ + public $pageIDs = []; + /** * @inheritDoc */ @@ -136,6 +144,7 @@ class BoxAddForm extends AbstractForm { if (isset($_POST['cssClassName'])) $this->cssClassName = StringUtil::trim($_POST['cssClassName']); if (isset($_POST['showHeader'])) $this->showHeader = intval($_POST['showHeader']); if (isset($_POST['className'])) $this->className = StringUtil::trim($_POST['className']); + if (isset($_POST['pageIDs']) && is_array($_POST['pageIDs'])) $this->pageIDs = ArrayUtil::toIntegerArray($_POST['pageIDs']); if (isset($_POST['title']) && is_array($_POST['title'])) $this->title = ArrayUtil::trim($_POST['title']); if (isset($_POST['content']) && is_array($_POST['content'])) $this->content = ArrayUtil::trim($_POST['content']); @@ -193,6 +202,21 @@ class BoxAddForm extends AbstractForm { // @todo check class } + // validate page ids + if (!empty($this->pageIDs)) { + $conditionBuilder = new PreparedStatementConditionBuilder(); + $conditionBuilder->add('pageID IN (?)', [$this->pageIDs]); + $sql = "SELECT pageID + FROM wcf".WCF_N."_page + " . $conditionBuilder; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute($conditionBuilder->getParameters()); + $this->pageIDs = []; + while ($row = $statement->fetchArray()) { + $this->pageIDs[] = $row['pageID']; + } + } + // validate images if (WCF::getSession()->getPermission('admin.content.cms.canUseMedia')) { foreach ($this->imageID as $languageID => $imageID) { @@ -251,7 +275,7 @@ class BoxAddForm extends AbstractForm { 'showHeader' => $this->showHeader, 'className' => $this->className, 'identifier' => '' - ]), 'content' => $content]); + ]), 'content' => $content, 'pageIDs' => $this->pageIDs ]); $returnValues = $this->objectAction->executeAction(); // set generic box identifier @@ -294,9 +318,11 @@ class BoxAddForm extends AbstractForm { 'content' => $this->content, 'imageID' => $this->imageID, 'images' => $this->images, + 'pageIDs' => $this->pageIDs, 'availableLanguages' => LanguageFactory::getInstance()->getLanguages(), 'availableBoxTypes' => Box::$availableBoxTypes, - 'availablePositions' => Box::$availablePositions + 'availablePositions' => Box::$availablePositions, + 'pageNodeList' => (new PageNodeTree())->getNodeList() ]); } } diff --git a/wcfsetup/install/files/lib/acp/form/BoxEditForm.class.php b/wcfsetup/install/files/lib/acp/form/BoxEditForm.class.php index dd4a8e9be9..2093691a9b 100644 --- a/wcfsetup/install/files/lib/acp/form/BoxEditForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/BoxEditForm.class.php @@ -97,7 +97,7 @@ class BoxEditForm extends BoxAddForm { 'cssClassName' => $this->cssClassName, 'showHeader' => $this->showHeader, 'className' => $this->className - ]), 'content' => $content]); + ]), 'content' => $content, 'pageIDs' => $this->pageIDs]); $this->objectAction->executeAction(); // call saved event @@ -130,6 +130,8 @@ class BoxEditForm extends BoxAddForm { $this->className = $this->box->className; if ($this->box->showHeader) $this->showHeader = 1; if ($this->box->visibleEverywhere) $this->visibleEverywhere = 1; + else $this->visibleEverywhere = 0; + $this->pageIDs = $this->box->getPageIDs(); foreach ($this->box->getBoxContent() as $languageID => $content) { $this->title[$languageID] = $content['title']; diff --git a/wcfsetup/install/files/lib/acp/form/MenuAddForm.class.php b/wcfsetup/install/files/lib/acp/form/MenuAddForm.class.php index 1f9a181a4c..3d3a07c8e2 100644 --- a/wcfsetup/install/files/lib/acp/form/MenuAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/MenuAddForm.class.php @@ -3,10 +3,13 @@ namespace wcf\acp\form; use wcf\data\box\Box; use wcf\data\menu\MenuAction; use wcf\data\menu\MenuEditor; +use wcf\data\page\PageNodeTree; use wcf\form\AbstractForm; +use wcf\system\database\util\PreparedStatementConditionBuilder; use wcf\system\exception\UserInputException; use wcf\system\language\I18nHandler; use wcf\system\WCF; +use wcf\util\ArrayUtil; use wcf\util\StringUtil; /** @@ -67,6 +70,12 @@ class MenuAddForm extends AbstractForm { */ public $showHeader = 1; + /** + * page ids + * @var integer[] + */ + public $pageIDs = []; + /** * @inheritDoc */ @@ -92,6 +101,7 @@ class MenuAddForm extends AbstractForm { if (isset($_POST['visibleEverywhere'])) $this->visibleEverywhere = intval($_POST['visibleEverywhere']); if (isset($_POST['cssClassName'])) $this->cssClassName = StringUtil::trim($_POST['cssClassName']); if (isset($_POST['showHeader'])) $this->showHeader = intval($_POST['showHeader']); + if (isset($_POST['pageIDs']) && is_array($_POST['pageIDs'])) $this->pageIDs = ArrayUtil::toIntegerArray($_POST['pageIDs']); } /** @@ -112,6 +122,21 @@ class MenuAddForm extends AbstractForm { // validate box position $this->validatePosition(); + + // validate page ids + if (!empty($this->pageIDs)) { + $conditionBuilder = new PreparedStatementConditionBuilder(); + $conditionBuilder->add('pageID IN (?)', [$this->pageIDs]); + $sql = "SELECT pageID + FROM wcf".WCF_N."_page + " . $conditionBuilder; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute($conditionBuilder->getParameters()); + $this->pageIDs = []; + while ($row = $statement->fetchArray()) { + $this->pageIDs[] = $row['pageID']; + } + } } /** @@ -145,7 +170,7 @@ class MenuAddForm extends AbstractForm { 'showOrder' => $this->showOrder, 'cssClassName' => $this->cssClassName, 'packageID' => 1 - ))); + ), 'pageIDs' => $this->pageIDs)); $returnValues = $this->objectAction->executeAction(); // set generic identifier $menuEditor = new MenuEditor($returnValues['returnValues']); @@ -190,7 +215,9 @@ class MenuAddForm extends AbstractForm { 'showOrder' => $this->showOrder, 'visibleEverywhere' => $this->visibleEverywhere, 'showHeader' => $this->showHeader, - 'availablePositions' => Box::$availableMenuPositions + 'pageIDs' => $this->pageIDs, + 'availablePositions' => Box::$availableMenuPositions, + 'pageNodeList' => (new PageNodeTree())->getNodeList() )); } } diff --git a/wcfsetup/install/files/lib/acp/form/MenuEditForm.class.php b/wcfsetup/install/files/lib/acp/form/MenuEditForm.class.php index 93ad21cdbc..11e8e86b47 100644 --- a/wcfsetup/install/files/lib/acp/form/MenuEditForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/MenuEditForm.class.php @@ -88,7 +88,7 @@ class MenuEditForm extends MenuAddForm { 'showHeader' => ($this->showHeader) ? 1 : 0, 'showOrder' => $this->showOrder, 'cssClassName' => $this->cssClassName - )))); + )), 'pageIDs' => $this->pageIDs)); $boxAction->executeAction(); } @@ -114,6 +114,7 @@ class MenuEditForm extends MenuAddForm { $this->cssClassName = $this->menu->getBox()->cssClassName; $this->showOrder = $this->menu->getBox()->showOrder; $this->visibleEverywhere = $this->menu->getBox()->visibleEverywhere; + $this->pageIDs = $this->menu->getBox()->getPageIDs(); $this->showHeader = $this->menu->getBox()->showHeader; } } diff --git a/wcfsetup/install/files/lib/data/box/Box.class.php b/wcfsetup/install/files/lib/data/box/Box.class.php index 84a9c8d725..fd32df450e 100644 --- a/wcfsetup/install/files/lib/data/box/Box.class.php +++ b/wcfsetup/install/files/lib/data/box/Box.class.php @@ -38,13 +38,13 @@ class Box extends DatabaseObject { * box content grouped by language id * @var string[][] */ - protected $boxContent = null; + protected $boxContent; /** * image media object * @var ViewableMedia */ - protected $image = null; + protected $image; /** * @inheritDoc @@ -60,7 +60,7 @@ class Box extends DatabaseObject { * available box types * @var string[] */ - public static $availableBoxTypes = ['text', 'html', 'system']; + public static $availableBoxTypes = ['text', 'html', 'tpl', 'system']; /** * available box positions @@ -80,6 +80,12 @@ class Box extends DatabaseObject { */ protected $menu; + /** + * box to page assignments + * @var integer[] + */ + protected $pageIDs; + /** * Returns true if the active user can delete this box. * @@ -291,6 +297,27 @@ class Box extends DatabaseObject { return false; } + /** + * Returns box to page assignments. + * + * @return integer[] + */ + public function getPageIDs() { + if ($this->pageIDs === null) { + $this->pageIDs = []; + $sql = "SELECT pageID + FROM wcf" . WCF_N . "_box_to_page + WHERE boxID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute([$this->boxID]); + while ($row = $statement->fetchArray()) { + $this->pageIDs[] = $row['pageID']; + } + } + + return $this->pageIDs; + } + /** * Returns the box with the given name. * diff --git a/wcfsetup/install/files/lib/data/box/BoxAction.class.php b/wcfsetup/install/files/lib/data/box/BoxAction.class.php index dc8911b629..389451200b 100644 --- a/wcfsetup/install/files/lib/data/box/BoxAction.class.php +++ b/wcfsetup/install/files/lib/data/box/BoxAction.class.php @@ -65,6 +65,22 @@ class BoxAction extends AbstractDatabaseObjectAction { } } + // save box to page + if (!empty($this->parameters['pageIDs'])) { + $sql = "INSERT INTO wcf".WCF_N."_box_to_page + (boxID, pageID, visible) + VALUES (?, ?, ?)"; + $statement = WCF::getDB()->prepareStatement($sql); + + foreach ($this->parameters['pageIDs'] as $pageID) { + $statement->execute([ + $box->boxID, + $pageID, + ($box->visibleEverywhere ? 0 : 1) + ]); + } + } + return $box; } @@ -99,6 +115,26 @@ class BoxAction extends AbstractDatabaseObjectAction { } } } + + // save box to page + if (isset($this->parameters['pageIDs'])) { + $sql = "DELETE FROM wcf".WCF_N."_box_to_page + WHERE boxID = ?"; + $deleteStatement = WCF::getDB()->prepareStatement($sql); + + $sql = "INSERT INTO wcf".WCF_N."_box_to_page + (boxID, pageID, visible) + VALUES (?, ?, ?)"; + $insertStatement = WCF::getDB()->prepareStatement($sql); + + foreach ($this->objects as $box) { + $deleteStatement->execute([$box->boxID]); + + foreach ($this->parameters['pageIDs'] as $pageID) { + $insertStatement->execute([$box->boxID, $pageID, ($box->visibleEverywhere ? 0 : 1)]); + } + } + } } /** diff --git a/wcfsetup/install/files/lib/data/menu/MenuAction.class.php b/wcfsetup/install/files/lib/data/menu/MenuAction.class.php index 0cb47ce384..e50f5122f4 100644 --- a/wcfsetup/install/files/lib/data/menu/MenuAction.class.php +++ b/wcfsetup/install/files/lib/data/menu/MenuAction.class.php @@ -53,7 +53,7 @@ class MenuAction extends AbstractDatabaseObjectAction { $boxData = $this->parameters['boxData']; $boxData['menuID'] = $menu->menuID; $boxData['identifier'] = ''; - $boxAction = new BoxAction([], 'create', ['data' => $boxData]); + $boxAction = new BoxAction([], 'create', ['data' => $boxData, 'pageIDs' => (isset($this->parameters['pageIDs']) ? $this->parameters['pageIDs'] : [])]); $returnValues = $boxAction->executeAction(); // set generic box identifier diff --git a/wcfsetup/install/files/lib/system/box/BoxHandler.class.php b/wcfsetup/install/files/lib/system/box/BoxHandler.class.php index dce7219d68..934a9954e0 100644 --- a/wcfsetup/install/files/lib/system/box/BoxHandler.class.php +++ b/wcfsetup/install/files/lib/system/box/BoxHandler.class.php @@ -2,6 +2,7 @@ namespace wcf\system\box; use wcf\data\box\Box; use wcf\data\box\BoxList; +use wcf\system\request\RequestHandler; use wcf\system\SingletonFactory; /** @@ -26,8 +27,13 @@ class BoxHandler extends SingletonFactory { * @inheritDoc */ protected function init() { + // get active page id + $pageID = RequestHandler::getInstance()->getActiveRequest()->getPageID(); + // load box layout for active page $boxList = new BoxList(); + if ($pageID) $boxList->getConditionBuilder()->add('(box.visibleEverywhere = ? AND boxID NOT IN (SELECT boxID FROM wcf'.WCF_N.'_box_to_page WHERE pageID = ? AND visible = ?)) OR boxID IN (SELECT boxID FROM wcf'.WCF_N.'_box_to_page WHERE pageID = ? AND visible = ?)', array(1, $pageID, 0, $pageID, 1)); + else $boxList->getConditionBuilder()->add('box.visibleEverywhere = ?', array(1)); $boxList->sqlOrderBy = 'showOrder'; $boxList->readObjects(); foreach ($boxList as $box) { diff --git a/wcfsetup/setup/db/install.sql b/wcfsetup/setup/db/install.sql index b0d106d2d0..d925d0da8e 100644 --- a/wcfsetup/setup/db/install.sql +++ b/wcfsetup/setup/db/install.sql @@ -252,6 +252,16 @@ CREATE TABLE wcf1_box_content ( KEY (boxID, languageID) ); +DROP TABLE IF EXISTS wcf1_box_to_page; +CREATE TABLE wcf1_box_to_page ( + boxID INT(10) NOT NULL, + pageID INT(10) NOT NULL, + visible TINYINT(1) NOT NULL DEFAULT 1, + + UNIQUE KEY (pageID, boxID), + KEY (pageID, visible) +); + DROP TABLE IF EXISTS wcf1_captcha_question; CREATE TABLE wcf1_captcha_question ( questionID INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY, @@ -1650,6 +1660,9 @@ ALTER TABLE wcf1_box_content ADD FOREIGN KEY (boxID) REFERENCES wcf1_box (boxID) ALTER TABLE wcf1_box_content ADD FOREIGN KEY (languageID) REFERENCES wcf1_language (languageID) ON DELETE CASCADE; ALTER TABLE wcf1_box_content ADD FOREIGN KEY (imageID) REFERENCES wcf1_media (mediaID) ON DELETE SET NULL; +ALTER TABLE wcf1_box_to_page ADD FOREIGN KEY (boxID) REFERENCES wcf1_box (boxID) ON DELETE CASCADE; +ALTER TABLE wcf1_box_to_page ADD FOREIGN KEY (pageID) REFERENCES wcf1_page (pageID) ON DELETE CASCADE; + ALTER TABLE wcf1_category ADD FOREIGN KEY (objectTypeID) REFERENCES wcf1_object_type (objectTypeID) ON DELETE CASCADE; ALTER TABLE wcf1_cli_history ADD FOREIGN KEY (userID) REFERENCES wcf1_user (userID) ON DELETE CASCADE;