ILIAS  trunk Revision v12.0_alpha-399-g579a087ced2
NewsItem.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\News\Data;
22
23use DateTimeImmutable;
24
29{
30 public function __construct(
31 protected int $id,
32 protected string $title,
33 protected string $content,
34 protected int $context_obj_id,
35 protected string $context_obj_type,
36 protected int $context_sub_obj_id,
37 protected ?string $context_sub_obj_type,
38 protected string $content_type,
39 protected \DateTimeImmutable $creation_date,
40 protected \DateTimeImmutable $update_date,
41 protected int $user_id,
42 protected int $update_user_id,
43 protected string $visibility,
44 protected string $content_long,
45 protected int $priority,
46 protected bool $content_is_lang_var,
47 protected bool $content_text_is_lang_var,
48 protected int $mob_id,
49 protected string $playtime,
50 protected int $mob_cnt_play,
51 protected int $mob_cnt_download,
52 protected bool $content_html,
53 protected int $context_ref_id = 0
54 ) {
55 }
56
57 public function getId(): int
58 {
59 return $this->id;
60 }
61
62 public function isContentTextIsLangVar(): bool
63 {
64 return $this->content_text_is_lang_var;
65 }
66
67 public function getTitle(): string
68 {
69 return $this->title;
70 }
71
72 public function getContent(): string
73 {
74 return $this->content;
75 }
76
77 public function getContextObjId(): int
78 {
79 return $this->context_obj_id;
80 }
81
82 public function getContextRefId(): int
83 {
84 return $this->context_ref_id;
85 }
86
87 public function getContextObjType(): string
88 {
89 return $this->context_obj_type;
90 }
91
92 public function getContextSubObjId(): int
93 {
94 return $this->context_sub_obj_id;
95 }
96
97 public function getContextSubObjType(): ?string
98 {
99 return $this->context_sub_obj_type;
100 }
101
102 public function getContentType(): string
103 {
104 return $this->content_type;
105 }
106
107 public function getCreationDate(): DateTimeImmutable
108 {
109 return $this->creation_date;
110 }
111
112 public function getUpdateDate(): DateTimeImmutable
113 {
114 return $this->update_date;
115 }
116
117 public function getUserId(): int
118 {
119 return $this->user_id;
120 }
121
122 public function getUpdateUserId(): int
123 {
124 return $this->update_user_id;
125 }
126
127 public function getVisibility(): string
128 {
129 return $this->visibility;
130 }
131
132 public function getContentLong(): string
133 {
134 return $this->content_long;
135 }
136
137 public function getPriority(): int
138 {
139 return $this->priority;
140 }
141
142 public function isContentIsLangVar(): bool
143 {
144 return $this->content_is_lang_var;
145 }
146
147 public function getMobId(): int
148 {
149 return $this->mob_id;
150 }
151
152 public function getPlaytime(): string
153 {
154 return $this->playtime;
155 }
156
157 public function getMobCntPlay(): int
158 {
159 return $this->mob_cnt_play;
160 }
161
162 public function getMobCntDownload(): int
163 {
164 return $this->mob_cnt_download;
165 }
166
167 public function isContentHtml(): bool
168 {
169 return $this->content_html;
170 }
171
172
173 public function withContextRefId(int $context_ref_id): NewsItem
174 {
175 $clone = clone $this;
176 $clone->context_ref_id = $context_ref_id;
177 return $clone;
178 }
179
180 public function withContent(string $content): NewsItem
181 {
182 $clone = clone $this;
183 $clone->content = $content;
184 return $clone;
185 }
186
187 public function withContentLong(string $content_long): NewsItem
188 {
189 $clone = clone $this;
190 $clone->content_long = $content_long;
191 return $clone;
192 }
193
194
195 public function toArray(): array
196 {
197 return [
198 'id' => $this->id,
199 'title' => $this->title,
200 'content' => $this->content,
201 'context_obj_id' => $this->context_obj_id,
202 'context_obj_type' => $this->context_obj_type,
203 'context_sub_obj_id' => $this->context_sub_obj_id,
204 'context_sub_obj_type' => $this->context_sub_obj_type,
205 'content_type' => $this->content_type,
206 'creation_date' => $this->creation_date->format('Y-m-d H:i:s'),
207 'update_date' => $this->update_date->format('Y-m-d H:i:s'),
208 'user_id' => $this->user_id,
209 'update_user_id' => $this->update_user_id,
210 'visibility' => $this->visibility,
211 'content_long' => $this->content_long,
212 'priority' => $this->priority,
213 'content_is_lang_var' => $this->content_is_lang_var,
214 'content_text_is_lang_var' => $this->content_text_is_lang_var,
215 'mob_id' => $this->mob_id,
216 'playtime' => $this->playtime,
217 'mob_cnt_play' => $this->mob_cnt_play,
218 'mob_cnt_download' => $this->mob_cnt_download,
219 'content_html' => $this->content_html
220 ];
221 }
222
223 public function toLegacy(): \ilNewsItem
224 {
225 $item = new \ilNewsItem(0); //prevent database loading
226 $item->setId($this->id);
227 $item->setTitle($this->title);
228 $item->setContent($this->content);
229 $item->setContextObjId($this->context_obj_id);
230 $item->setContextObjType($this->context_obj_type);
231 $item->setContextSubObjId($this->context_sub_obj_id);
232 $item->setContextSubObjType($this->context_sub_obj_type);
233 $item->setContentType($this->content_type);
234 $item->setCreationDate($this->creation_date->format('Y-m-d H:i:s'));
235 $item->setUpdateDate($this->update_date->format('Y-m-d H:i:s'));
236 $item->setUserId($this->user_id);
237 $item->setUpdateUserId($this->update_user_id);
238 $item->setVisibility($this->visibility);
239 $item->setContentLong($this->content_long);
240 $item->setPriority($this->priority);
241 $item->setContentIsLangVar($this->content_is_lang_var);
242 $item->setContentTextIsLangVar($this->content_text_is_lang_var);
243 $item->setMobId($this->mob_id);
244 $item->setPlaytime($this->playtime);
245 $item->setMobPlayCounter($this->mob_cnt_play);
246 $item->setMobDownloadCounter($this->mob_cnt_download);
247 $item->setContentHtml($this->content_html);
248 return $item;
249 }
250}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
News Item DTO for transfer of news items.
Definition: NewsItem.php:29
__construct(protected int $id, protected string $title, protected string $content, protected int $context_obj_id, protected string $context_obj_type, protected int $context_sub_obj_id, protected ?string $context_sub_obj_type, protected string $content_type, protected \DateTimeImmutable $creation_date, protected \DateTimeImmutable $update_date, protected int $user_id, protected int $update_user_id, protected string $visibility, protected string $content_long, protected int $priority, protected bool $content_is_lang_var, protected bool $content_text_is_lang_var, protected int $mob_id, protected string $playtime, protected int $mob_cnt_play, protected int $mob_cnt_download, protected bool $content_html, protected int $context_ref_id=0)
Definition: NewsItem.php:30
withContent(string $content)
Definition: NewsItem.php:180
withContextRefId(int $context_ref_id)
Definition: NewsItem.php:173
withContentLong(string $content_long)
Definition: NewsItem.php:187
A news item can be created by different sources.