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.
*
$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();
}
}
}
<?php
namespace wcf\data\box;
+use wcf\data\box\content\BoxContentList;
use wcf\data\DatabaseObjectList;
+use wcf\system\WCF;
/**
* Represents a list of boxes.
* @inheritDoc
*/
public $className = Box::class;
+
+ /**
+ * enables/disables the loading of box content objects
+ * @var boolean
+ */
+ protected $contentLoading = false;
+
+ /**
+ * @inheritDoc
+ */
+ public function readObjects() {
+ parent::readObjects();
+
+ // get box content
+ if ($this->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;
+ }
}
<?php
namespace wcf\data\box\content;
use wcf\data\DatabaseObject;
+use wcf\data\media\ViewableMedia;
use wcf\system\WCF;
/**
*/
protected static $databaseTableIndexName = 'boxContentID';
+ /**
+ * image media object
+ * @var ViewableMedia
+ */
+ protected $image;
+
/**
* Returns a certain box content.
*
return null;
}
+
+ /**
+ * Returns the image of this box content.
+ *
+ * @return ViewableMedia|null
+ */
+ public function getImage() {
+ if ($this->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;
+ }
}
<?php
namespace wcf\data\box\content;
use wcf\data\DatabaseObjectList;
+use wcf\data\media\ViewableMediaList;
/**
* Represents a list of box content.
* @inheritDoc
*/
public $className = BoxContent::class;
+
+ /**
+ * enables/disables the loading of box content images
+ * @var boolean
+ */
+ protected $imageLoading = false;
+
+ /**
+ * @inheritDoc
+ */
+ public function readObjects() {
+ parent::readObjects();
+
+ if ($this->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;
+ }
}
// 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';