From: Marcel Werk Date: Thu, 30 Jun 2016 18:19:02 +0000 (+0200) Subject: Added method to assign pages to boxes during package installation X-Git-Tag: 3.0.0_Beta_1~1300 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=e114c20b4cd9dd953fcbb80b9ecb588c3b689d47;p=GitHub%2FWoltLab%2FWCF.git Added method to assign pages to boxes during package installation --- diff --git a/wcfsetup/install/files/lib/system/box/BoxHandler.class.php b/wcfsetup/install/files/lib/system/box/BoxHandler.class.php index d198196fff..f477a6c0dd 100644 --- a/wcfsetup/install/files/lib/system/box/BoxHandler.class.php +++ b/wcfsetup/install/files/lib/system/box/BoxHandler.class.php @@ -3,6 +3,7 @@ namespace wcf\system\box; use wcf\data\box\Box; use wcf\data\box\BoxList; use wcf\data\condition\ConditionAction; +use wcf\data\page\Page; use wcf\system\exception\SystemException; use wcf\system\request\RequestHandler; use wcf\system\SingletonFactory; @@ -146,4 +147,49 @@ class BoxHandler extends SingletonFactory { return null; } + + /** + * Assigns pages to a certain box. + * + * Note: The primary use of this method is to be used during package installation. + * + * @param string $boxIdentifier + * @param string[] $pageIdentifiers + * @param boolean $visible + * @throws \InvalidArgumentException + */ + public function addBoxToPageAssignments($boxIdentifier, array $pageIdentifiers, $visible = true) { + $box = Box::getBoxByIdentifier($boxIdentifier); + if ($box === null) { + throw new \InvalidArgumentException("Unknown box with identifier '{$boxIdentifier}'"); + } + + $pages = []; + foreach ($pageIdentifiers as $pageIdentifier) { + $page = Page::getPageByIdentifier($pageIdentifier); + if ($page === null) { + throw new \InvalidArgumentException("Unknown page with identifier '{$pageIdentifier}'"); + } + $pages[] = $page; + } + + if (($visible && $box->visibleEverywhere) || (!$visible && !$box->visibleEverywhere)) { + $sql = "DELETE FROM wcf".WCF_N."_box_to_page + WHERE boxID = ? + AND pageID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + foreach ($pages as $page) { + $statement->execute([$box->boxID, $page->pageID]); + } + } + else { + $sql = "REPLACE INTO wcf".WCF_N."_box_to_page + (boxID, pageID, visible) + VALUES (?, ?, ?)"; + $statement = WCF::getDB()->prepareStatement($sql); + foreach ($pages as $page) { + $statement->execute([$box->boxID, $page->pageID, ($visible ? 1 : 0)]); + } + } + } }