Commit | Line | Data |
---|---|---|
11fd4618 | 1 | <?php |
a9229942 | 2 | |
11fd4618 | 3 | namespace wcf\data\box; |
a9229942 | 4 | |
77e06c6c | 5 | use wcf\data\box\content\BoxContentList; |
11fd4618 | 6 | use wcf\data\DatabaseObjectList; |
77e06c6c | 7 | use wcf\system\WCF; |
11fd4618 MW |
8 | |
9 | /** | |
10 | * Represents a list of boxes. | |
e82bf444 | 11 | * |
a9229942 TD |
12 | * @author Marcel Werk |
13 | * @copyright 2001-2019 WoltLab GmbH | |
14 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> | |
a9229942 TD |
15 | * @since 3.0 |
16 | * | |
17 | * @method Box current() | |
18 | * @method Box[] getObjects() | |
62d64fe4 | 19 | * @method Box|null getSingleObject() |
74a327b0 | 20 | * @method Box|null search($objectID) |
a9229942 | 21 | * @property Box[] $objects |
11fd4618 | 22 | */ |
a9229942 TD |
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) { | |
b25fd274 | 45 | if (!empty($this->objectIDs)) { |
a9229942 TD |
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 | } | |
11fd4618 | 71 | } |