2 namespace wcf\data\article\content
;
3 use wcf\data\article\ViewableArticleList
;
4 use wcf\data\media\ViewableMediaList
;
5 use wcf\system\message\embedded\
object\MessageEmbeddedObjectManager
;
8 * Represents a list of viewable article contents.
11 * @copyright 2001-2019 WoltLab GmbH
12 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
13 * @package WoltLabSuite\Core\Data\Article\Content
16 * @method ViewableArticleContent current()
17 * @method ViewableArticleContent[] getObjects()
18 * @method ViewableArticleContent|null search($objectID)
19 * @property ViewableArticleContent[] $objects
21 class ViewableArticleContentList
extends ArticleContentList
{
25 public $decoratorClassName = ViewableArticleContent
::class;
30 public function readObjects() {
31 parent
::readObjects();
33 $imageIDs = $embeddedObjectPostIDs = $articleIDs = [];
34 foreach ($this->getObjects() as $articleContent) {
35 if ($articleContent->imageID
) {
36 $imageIDs[] = $articleContent->imageID
;
38 if ($articleContent->thumbnailImageID
) {
39 $imageIDs[] = $articleContent->thumbnailImageID
;
41 if ($articleContent->hasEmbeddedObjects
) {
42 $embeddedObjectPostIDs[] = $articleContent->articleContentID
;
45 $articleIDs[] = $articleContent->articleID
;
49 if (!empty($imageIDs)) {
50 $mediaList = new ViewableMediaList();
51 $mediaList->setObjectIDs($imageIDs);
52 $mediaList->readObjects();
53 $images = $mediaList->getObjects();
56 // load embedded objects
57 if (!empty($embeddedObjectPostIDs)) {
58 $contentLanguageID = null;
59 if (count($embeddedObjectPostIDs) === 1) $contentLanguageID = reset($this->objects
)->languageID
;
61 MessageEmbeddedObjectManager
::getInstance()->loadObjects('com.woltlab.wcf.article.content', $embeddedObjectPostIDs, $contentLanguageID);
64 if (!empty($articleIDs)) {
65 $articleList = new ViewableArticleList();
66 // to prevent an infinity loop, because the list loads otherwise the article content
67 $articleList->enableContentLoading(false);
68 $articleList->setObjectIDs($articleIDs);
69 $articleList->readObjects();
72 foreach ($this->getObjects() as $articleContent) {
74 if ($articleContent->imageID
&& isset($images[$articleContent->imageID
])) {
75 $articleContent->setImage($images[$articleContent->imageID
]);
78 if ($articleContent->teaserImageID
&& isset($images[$articleContent->teaserImageID
])) {
79 $articleContent->setTeaserImage($images[$articleContent->teaserImageID
]);
83 if (isset($articleList)) {
84 if ($articleList->search($articleContent->articleID
) !== null) {
85 $articleContent->setArticle($articleList->search($articleContent->articleID
));
88 throw new \
LogicException('Unable to find article with id "'. $articleContent->articleID
.'".');