From: Marcel Werk Date: Tue, 26 Jul 2016 15:37:05 +0000 (+0200) Subject: Improved box handler X-Git-Tag: 3.0.0_Beta_1~965 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=77e06c6ca2489aa3d3f6ca45b139b03ed54baaae;p=GitHub%2FWoltLab%2FWCF.git Improved box handler --- diff --git a/wcfsetup/install/files/lib/data/box/Box.class.php b/wcfsetup/install/files/lib/data/box/Box.class.php index c5cfb68811..14d7aaf660 100644 --- a/wcfsetup/install/files/lib/data/box/Box.class.php +++ b/wcfsetup/install/files/lib/data/box/Box.class.php @@ -178,6 +178,15 @@ class Box extends DatabaseObject { return $this->boxContents; } + /** + * Sets the box's content. + * + * @param BoxContent[] $boxContents + */ + public function setBoxContents($boxContents) { + $this->boxContents = $boxContents; + } + /** * Returns the title of the box as set in the box content database table. * @@ -334,11 +343,11 @@ class Box extends DatabaseObject { $this->getBoxContents(); if ($this->isMultilingual) { if (isset($this->boxContents[WCF::getLanguage()->languageID]) && $this->boxContents[WCF::getLanguage()->languageID]->imageID) { - $this->image = ViewableMedia::getMedia($this->boxContents[WCF::getLanguage()->languageID]->imageID); + $this->image = $this->boxContents[WCF::getLanguage()->languageID]->getImage(); } } else if (isset($this->boxContents[0]) && $this->boxContents[0]->imageID) { - $this->image = ViewableMedia::getMedia($this->boxContents[0]->imageID); + $this->image = $this->boxContents[0]->getImage(); } } } diff --git a/wcfsetup/install/files/lib/data/box/BoxList.class.php b/wcfsetup/install/files/lib/data/box/BoxList.class.php index cfec8e3c62..61dba7100f 100644 --- a/wcfsetup/install/files/lib/data/box/BoxList.class.php +++ b/wcfsetup/install/files/lib/data/box/BoxList.class.php @@ -1,6 +1,8 @@ contentLoading) { + $boxIDs = []; + foreach ($this->getObjects() as $box) { + if ($box->boxType != 'system' && $box->boxType != 'menu') { + $boxIDs[] = $box->boxID; + } + } + + if (!empty($boxIDs)) { + $contentList = new BoxContentList(); + $contentList->enableImageLoading(); + $contentList->getConditionBuilder()->add('box_content.boxID IN (?)', [$this->objectIDs]); + $contentList->getConditionBuilder()->add('(box_content.languageID IS NULL OR box_content.languageID = ?)', [WCF::getLanguage()->languageID]); + $contentList->readObjects(); + foreach ($contentList as $boxContent) { + $this->objects[$boxContent->boxID]->setBoxContents([($boxContent->languageID ?: 0) => $boxContent]); + } + } + } + } + + /** + * Enables/disables the loading of box content objects. + * + * @param boolean $enable + */ + public function enableContentLoading($enable = true) { + $this->contentLoading = $enable; + } } diff --git a/wcfsetup/install/files/lib/data/box/content/BoxContent.class.php b/wcfsetup/install/files/lib/data/box/content/BoxContent.class.php index 3685c5716f..73a514a43d 100644 --- a/wcfsetup/install/files/lib/data/box/content/BoxContent.class.php +++ b/wcfsetup/install/files/lib/data/box/content/BoxContent.class.php @@ -1,6 +1,7 @@ image === null) { + if ($this->imageID) { + $this->image = ViewableMedia::getMedia($this->imageID); + } + } + + return $this->image; + } + + /** + * Sets the image of this box content. + * + * @param ViewableMedia $image + */ + public function setImage(ViewableMedia $image) { + $this->image = $image; + } } diff --git a/wcfsetup/install/files/lib/data/box/content/BoxContentList.class.php b/wcfsetup/install/files/lib/data/box/content/BoxContentList.class.php index abdbafbba0..d56cd8195b 100644 --- a/wcfsetup/install/files/lib/data/box/content/BoxContentList.class.php +++ b/wcfsetup/install/files/lib/data/box/content/BoxContentList.class.php @@ -1,6 +1,7 @@ imageLoading) { + $imageIDs = []; + foreach ($this->getObjects() as $boxContent) { + if ($boxContent->imageID) { + $imageIDs[] = $boxContent->imageID; + } + } + + // cache images + if (!empty($imageIDs)) { + $mediaList = new ViewableMediaList(); + $mediaList->setObjectIDs($imageIDs); + $mediaList->readObjects(); + $images = $mediaList->getObjects(); + + foreach ($this->getObjects() as $boxContent) { + if ($boxContent->imageID && isset($images[$boxContent->imageID])) { + $boxContent->setImage($images[$boxContent->imageID]); + } + } + } + } + } + + + /** + * Enables/disables the loading of box content images. + * + * @param boolean $enable + */ + public function enableImageLoading($enable = true) { + $this->imageLoading = $enable; + } } diff --git a/wcfsetup/install/files/lib/system/box/BoxHandler.class.php b/wcfsetup/install/files/lib/system/box/BoxHandler.class.php index 02743d1008..83a0cff86b 100644 --- a/wcfsetup/install/files/lib/system/box/BoxHandler.class.php +++ b/wcfsetup/install/files/lib/system/box/BoxHandler.class.php @@ -48,6 +48,7 @@ class BoxHandler extends SingletonFactory { // load box layout for active page $boxList = new BoxList(); + $boxList->enableContentLoading(); 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 = ?)', [1, $pageID, 0, $pageID, 1]); else $boxList->getConditionBuilder()->add('box.visibleEverywhere = ?', [1]); $boxList->sqlOrderBy = 'showOrder';