| 1 | <?php |
| 2 | |
| 3 | namespace wcf\data\box; |
| 4 | |
| 5 | use wcf\data\box\content\BoxContentList; |
| 6 | use wcf\data\DatabaseObjectList; |
| 7 | use wcf\system\WCF; |
| 8 | |
| 9 | /** |
| 10 | * Represents a list of boxes. |
| 11 | * |
| 12 | * @author Marcel Werk |
| 13 | * @copyright 2001-2019 WoltLab GmbH |
| 14 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> |
| 15 | * @since 3.0 |
| 16 | * |
| 17 | * @method Box current() |
| 18 | * @method Box[] getObjects() |
| 19 | * @method Box|null getSingleObject() |
| 20 | * @method Box|null search($objectID) |
| 21 | * @property Box[] $objects |
| 22 | */ |
| 23 | class BoxList extends DatabaseObjectList |
| 24 | { |
| 25 | /** |
| 26 | * @inheritDoc |
| 27 | */ |
| 28 | public $className = Box::class; |
| 29 | |
| 30 | /** |
| 31 | * enables/disables the loading of box content objects |
| 32 | * @var bool |
| 33 | */ |
| 34 | protected $contentLoading = false; |
| 35 | |
| 36 | /** |
| 37 | * @inheritDoc |
| 38 | */ |
| 39 | public function readObjects() |
| 40 | { |
| 41 | parent::readObjects(); |
| 42 | |
| 43 | // get box content |
| 44 | if ($this->contentLoading) { |
| 45 | if (!empty($this->objectIDs)) { |
| 46 | $contentList = new BoxContentList(); |
| 47 | $contentList->enableImageLoading(); |
| 48 | $contentList->enableEmbeddedObjectLoading(); |
| 49 | $contentList->getConditionBuilder()->add('box_content.boxID IN (?)', [$this->objectIDs]); |
| 50 | $contentList->getConditionBuilder()->add( |
| 51 | '(box_content.languageID IS NULL OR box_content.languageID = ?)', |
| 52 | [WCF::getLanguage()->languageID] |
| 53 | ); |
| 54 | $contentList->readObjects(); |
| 55 | foreach ($contentList as $boxContent) { |
| 56 | $this->objects[$boxContent->boxID]->setBoxContents([$boxContent->languageID ?: 0 => $boxContent]); |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Enables/disables the loading of box content objects. |
| 64 | * |
| 65 | * @param bool $enable |
| 66 | */ |
| 67 | public function enableContentLoading($enable = true) |
| 68 | { |
| 69 | $this->contentLoading = $enable; |
| 70 | } |
| 71 | } |