076edbf7eac8c1a6ef4668661a7263d0607cbc2b
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / data / article / content / ViewableArticleContent.class.php
1 <?php
2
3 namespace wcf\data\article\content;
4
5 use wcf\data\article\ViewableArticle;
6 use wcf\data\DatabaseObjectDecorator;
7 use wcf\data\media\ViewableMedia;
8
9 /**
10 * Represents a viewable article content.
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 * @package WoltLabSuite\Core\Data\Article\Content
16 * @since 3.0
17 *
18 * @method ArticleContent getDecoratedObject()
19 * @mixin ArticleContent
20 */
21 class ViewableArticleContent extends DatabaseObjectDecorator
22 {
23 /**
24 * @inheritDoc
25 */
26 protected static $baseClass = ArticleContent::class;
27
28 /**
29 * article image
30 * @var ViewableMedia
31 */
32 protected $image;
33
34 /**
35 * article thumbnail image
36 * @var ViewableMedia
37 */
38 protected $teaserImage;
39
40 /**
41 * article object
42 * @var ViewableArticle
43 */
44 protected $article;
45
46 /**
47 * Returns article object.
48 *
49 * @return ViewableArticle
50 */
51 public function getArticle()
52 {
53 if ($this->article === null) {
54 $this->article = new ViewableArticle($this->getDecoratedObject()->getArticle());
55 }
56
57 return $this->article;
58 }
59
60 /**
61 * Sets the article objects.
62 *
63 * @param ViewableArticle $article
64 */
65 public function setArticle(ViewableArticle $article)
66 {
67 $this->article = $article;
68 }
69
70 /**
71 * Returns the article's image if the active user can access it or `null`.
72 *
73 * @return ViewableMedia|null
74 */
75 public function getImage()
76 {
77 if ($this->image === null) {
78 if ($this->imageID) {
79 $this->image = ViewableMedia::getMedia($this->imageID);
80 }
81 }
82
83 if ($this->image === null || !$this->image->isAccessible()) {
84 return;
85 }
86
87 return $this->image;
88 }
89
90 /**
91 * Sets the article's image.
92 *
93 * @param ViewableMedia $image
94 */
95 public function setImage(ViewableMedia $image)
96 {
97 $this->image = $image;
98 }
99
100 /**
101 * Returns the article's teaser image if the active user can access it or `null`.
102 *
103 * @return ViewableMedia|null
104 */
105 public function getTeaserImage()
106 {
107 if (!$this->teaserImageID) {
108 return $this->getImage();
109 }
110
111 if ($this->teaserImage === null) {
112 $this->teaserImage = ViewableMedia::getMedia($this->teaserImageID);
113 }
114
115 if ($this->teaserImage === null || !$this->teaserImage->isAccessible()) {
116 return;
117 }
118
119 return $this->teaserImage;
120 }
121
122 /**
123 * Sets the article's teaser image.
124 *
125 * @param ViewableMedia $image
126 */
127 public function setTeaserImage(ViewableMedia $image)
128 {
129 $this->teaserImage = $image;
130 }
131
132 /**
133 * Returns a specific article content decorated as viewable article content.
134 *
135 * @param int $articleContentID
136 * @return ViewableArticleContent
137 */
138 public static function getArticleContent($articleContentID)
139 {
140 $list = new ViewableArticleContentList();
141 $list->setObjectIDs([$articleContentID]);
142 $list->readObjects();
143
144 return $list->search($articleContentID);
145 }
146 }