3 namespace wcf\data\article\content
;
5 use wcf\data\article\ViewableArticle
;
6 use wcf\data\DatabaseObjectDecorator
;
7 use wcf\data\media\ViewableMedia
;
10 * Represents a viewable article content.
13 * @copyright 2001-2019 WoltLab GmbH
14 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15 * @package WoltLabSuite\Core\Data\Article\Content
18 * @method ArticleContent getDecoratedObject()
19 * @mixin ArticleContent
21 class ViewableArticleContent
extends DatabaseObjectDecorator
26 protected static $baseClass = ArticleContent
::class;
35 * article thumbnail image
38 protected $teaserImage;
42 * @var ViewableArticle
47 * Returns article object.
49 * @return ViewableArticle
51 public function getArticle()
53 if ($this->article
=== null) {
54 $this->article
= new ViewableArticle($this->getDecoratedObject()->getArticle());
57 return $this->article
;
61 * Sets the article objects.
63 * @param ViewableArticle $article
65 public function setArticle(ViewableArticle
$article)
67 $this->article
= $article;
71 * Returns the article's image if the active user can access it or `null`.
73 * @return ViewableMedia|null
75 public function getImage()
77 if ($this->image
=== null) {
79 $this->image
= ViewableMedia
::getMedia($this->imageID
);
83 if ($this->image
=== null ||
!$this->image
->isAccessible()) {
91 * Sets the article's image.
93 * @param ViewableMedia $image
95 public function setImage(ViewableMedia
$image)
97 $this->image
= $image;
101 * Returns the article's teaser image if the active user can access it or `null`.
103 * @return ViewableMedia|null
105 public function getTeaserImage()
107 if (!$this->teaserImageID
) {
108 return $this->getImage();
111 if ($this->teaserImage
=== null) {
112 $this->teaserImage
= ViewableMedia
::getMedia($this->teaserImageID
);
115 if ($this->teaserImage
=== null ||
!$this->teaserImage
->isAccessible()) {
119 return $this->teaserImage
;
123 * Sets the article's teaser image.
125 * @param ViewableMedia $image
127 public function setTeaserImage(ViewableMedia
$image)
129 $this->teaserImage
= $image;
133 * Returns a specific article content decorated as viewable article content.
135 * @param int $articleContentID
136 * @return ViewableArticleContent
138 public static function getArticleContent($articleContentID)
140 $list = new ViewableArticleContentList();
141 $list->setObjectIDs([$articleContentID]);
142 $list->readObjects();
144 return $list->search($articleContentID);