ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilBlogPosting.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23
30{
31 protected string $title = "";
32 protected ?ilDateTime $created = null;
33 protected int $blog_node_id = 0;
34 protected bool $blog_node_is_wsp = false;
35 protected int $author = 0;
36 protected bool $approved = false;
37 protected ?ilDateTime $withdrawn = null;
40
41 public function afterConstructor(): void
42 {
43 global $DIC;
44 $this->internal_data = $DIC->blog()->internal()->data();
45 $this->posting_manager = $DIC->blog()->internal()->domain()->posting();
46 }
47
48 public function getParentType(): string
49 {
50 return "blp";
51 }
52
53 public function setTitle(string $a_title): void
54 {
55 $this->title = $a_title;
56 }
57
58 public function getTitle(): string
59 {
60 return $this->title;
61 }
62
63 public function setBlogId(int $a_id): void
64 {
65 $this->setParentId($a_id);
66 }
67
68 public function getBlogId(): int
69 {
70 return $this->getParentId();
71 }
72
73 public function setCreated(ilDateTime $a_date): void
74 {
75 $this->created = $a_date;
76 }
77
78 public function getCreated(): ilDateTime
79 {
80 return $this->created;
81 }
82
83 public function setAuthor(int $a_id): void
84 {
85 $this->author = $a_id;
86 }
87
88 public function getAuthor(): int
89 {
90 return $this->author;
91 }
92
93 public function setApproved(bool $a_status): void
94 {
95 $this->approved = $a_status;
96 }
97
98 public function isApproved(): bool
99 {
100 return $this->approved;
101 }
102
106 public function setWithdrawn(
107 ilDateTime $a_date
108 ): void {
109 $this->withdrawn = $a_date;
110 }
111
115 public function getWithdrawn(): ?ilDateTime
116 {
117 return $this->withdrawn;
118 }
119
123 public function create(
124 bool $a_import = false
125 ): void {
126 $data = $this->internal_data;
127 $post = $data->posting(
128 0,
129 $this->getBlogId(),
130 $this->getTitle(),
132 $this->getAuthor(),
133 $this->isApproved(),
134 $this->getWithdrawn()
135 );
136 $id = $this->posting_manager->create($post);
137 $this->setId($id);
138
139 if (!$a_import) {
140 parent::create($a_import);
141 }
142 }
143
144 public function update(
145 bool $a_validate = true,
146 bool $a_no_history = false,
147 bool $a_notify = true,
148 string $a_notify_action = "update"
149 ) {
150 $data = $this->internal_data;
151 $post = $data->posting(
152 $this->getId(),
153 $this->getBlogId(),
154 $this->getTitle(),
155 $this->getCreated(),
156 $this->getAuthor(),
157 $this->isApproved(),
158 $this->getWithdrawn()
159 );
160 $this->posting_manager->update($post);
161
162 $ret = parent::update($a_validate, $a_no_history);
163
164 if ($a_notify && $this->getActive()) {
166 $a_notify_action,
167 $this->blog_node_is_wsp,
168 $this->blog_node_id,
169 $this->getId()
170 );
171 }
172
173 return $ret;
174 }
175
179 public function read(): void
180 {
181 $ilDB = $this->db;
182
183 $query = "SELECT * FROM il_blog_posting" .
184 " WHERE id = " . $ilDB->quote($this->getId(), "integer");
185 $set = $ilDB->query($query);
186 $rec = $ilDB->fetchAssoc($set);
187
188 $this->setTitle($rec["title"]);
189 $this->setBlogId($rec["blog_id"]);
190 $this->setCreated(new ilDateTime($rec["created"], IL_CAL_DATETIME));
191 $this->setAuthor($rec["author"]);
192 if ($rec["approved"]) {
193 $this->setApproved(true);
194 }
195 $this->setWithdrawn(new ilDateTime($rec["last_withdrawn"], IL_CAL_DATETIME));
196
197 // when posting is deactivated it should loose the approval
198 $this->addUpdateListener($this, "checkApproval");
199
200 parent::read();
201 }
202
203 public function checkApproval(): void
204 {
205 if (!$this->getActive() && $this->isApproved()) {
206 $this->approved = false;
207 $this->update();
208 }
209 }
210
214 public function delete(): void
215 {
216 $ilDB = $this->db;
217
219 $this->getBlogId(),
220 "blog",
221 $this->getId(),
222 $this->getParentType()
223 );
224
225 $this->posting_manager->delete($this->getId());
226
227 parent::delete();
228 }
229
233 public function unpublish(): void
234 {
235 $this->setApproved(false);
236 $this->setActive(false);
237 $this->setWithdrawn(new ilDateTime(ilUtil::now(), IL_CAL_DATETIME));
238 $this->update(true, false, false);
239
241 $this->getBlogId(),
242 "blog",
243 $this->getId(),
244 $this->getParentType()
245 );
246 }
247
251 public static function deleteAllBlogPostings(
252 int $a_blog_id
253 ): void {
254 global $DIC;
255
256 $lom_services = $DIC->learningObjectMetadata();
257 $mgr = $DIC->blog()->internal()->domain()->posting();
258 foreach ($mgr->getAllByBlog($a_blog_id, 0) as $posting) {
259 $lom_services->deleteAll($a_blog_id, $posting->getId(), "blp");
260 $post = new ilBlogPosting($posting->getId());
261 $post->delete();
262 }
263 }
264
265 public static function lookupBlogId(
266 int $a_posting_id
267 ): ?int {
268 global $DIC;
269 return $DIC->blog()->internal()->domain()->posting()->lookupBlogId($a_posting_id);
270 }
271
275 public static function getAllPostings(
276 int $a_blog_id,
277 int $a_limit = 1000,
278 int $a_offset = 0
279 ): array {
280 global $DIC;
281
282 $pages = parent::getAllPages("blp", $a_blog_id);
283 $posts = [];
284 foreach ($DIC->blog()->internal()->domain()->posting()->getAllByBlog(
285 $a_blog_id,
286 $a_limit,
287 $a_offset
288 ) as $posting) {
289 $id = $posting->getId();
290 if (isset($pages[$id])) {
291 $posts[$id] = $pages[$id];
292 $posts[$id]["title"] = $posting->getTitle();
293 $posts[$id]["created"] = $posting->getCreated();
294 $posts[$id]["author"] = $posting->getAuthor();
295 $posts[$id]["approved"] = $posting->isApproved();
296 $posts[$id]["last_withdrawn"] = $posting->getLastWithdrawn();
297
298 foreach (self::getPageContributors("blp", $id) as $editor) {
299 if ($editor["user_id"] != $posting->getAuthor()) {
300 $posts[$id]["editors"][] = $editor["user_id"];
301 }
302 }
303 }
304 }
305
306 return $posts;
307 }
308
312 public static function exists(
313 int $a_blog_id,
314 int $a_posting_id
315 ): bool {
316 global $DIC;
317 return $DIC->blog()->internal()->domain()->posting()->exists(
318 $a_blog_id,
319 $a_posting_id
320 );
321 }
322
326 public static function getLastPost(
327 int $a_blog_id
328 ): int {
329 global $DIC;
330 return $DIC->blog()->internal()->domain()->posting()->getLastPost($a_blog_id);
331 }
332
336 public function setBlogNodeId(
337 int $a_id,
338 bool $a_is_in_workspace = false
339 ): void {
340 $this->blog_node_id = $a_id;
341 $this->blog_node_is_wsp = $a_is_in_workspace;
342 }
343
344 public function getNotificationAbstract(): string
345 {
346 $snippet = ilBlogPostingGUI::getSnippet($this->getId(), true);
347
348 // making things more readable
349 $snippet = str_replace(array('<br/>', '<br />', '</p>', '</div>'), "\n", $snippet);
350
351 return trim(strip_tags($snippet));
352 }
353
354 // keywords
355 public function updateKeywords(
356 array $keywords
357 ): void {
358 $this->lom_services->manipulate($this->getBlogId(), $this->getId(), "blp")
359 ->prepareDelete($this->lom_services->paths()->keywords())
360 ->prepareCreateOrUpdate($this->lom_services->paths()->keywords(), ...$keywords)
361 ->execute();
362 }
363
364 public static function getKeywords(
365 int $a_obj_id,
366 int $a_posting_id
367 ): array {
368 global $DIC;
369
370 $lom_services = $DIC->learningObjectMetadata();
371
372 $result = [];
373 $keywords = $lom_services->read($a_obj_id, $a_posting_id, "blp")
374 ->allData($lom_services->paths()->keywords());
375 foreach ($keywords as $keyword) {
376 if ($keyword->value() !== "") {
377 $result[] = $keyword->value();
378 }
379 }
380
381 return $result;
382 }
383}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
const IL_CAL_DATETIME
static getSnippet(int $a_id, bool $a_truncate=false, int $a_truncate_length=500, string $a_truncate_sign="...", bool $a_include_picture=false, int $a_picture_width=144, int $a_picture_height=144, ?string $a_export_directory=null)
Get first text paragraph of page.
Class ilBlogPosting.
static exists(int $a_blog_id, int $a_posting_id)
Checks whether a posting exists.
update(bool $a_validate=true, bool $a_no_history=false, bool $a_notify=true, string $a_notify_action="update")
create(bool $a_import=false)
Create new blog posting.
setApproved(bool $a_status)
setBlogNodeId(int $a_id, bool $a_is_in_workspace=false)
Set blog node id (needed for notification)
static getAllPostings(int $a_blog_id, int $a_limit=1000, int $a_offset=0)
Get all postings of blog.
updateKeywords(array $keywords)
static lookupBlogId(int $a_posting_id)
static getKeywords(int $a_obj_id, int $a_posting_id)
static getLastPost(int $a_blog_id)
Get newest posting for blog.
PostingManager $posting_manager
InternalDataService $internal_data
setCreated(ilDateTime $a_date)
setWithdrawn(ilDateTime $a_date)
Set last withdrawal date.
static deleteAllBlogPostings(int $a_blog_id)
Delete all postings for blog.
setTitle(string $a_title)
getWithdrawn()
Get last withdrawal date.
read()
Read blog posting.
@classDescription Date and time handling
static deleteNewsOfContext(int $a_context_obj_id, string $a_context_obj_type, int $a_context_sub_obj_id=0, string $a_context_sub_obj_type="")
Delete all news of a context.
static sendNotification(string $a_action, bool $a_in_wsp, int $a_blog_node_id, int $a_posting_id, ?string $a_comment=null)
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
setParentId(int $a_id)
static now()
Return current timestamp in Y-m-d H:i:s format.
$post
Definition: ltitoken.php:46
global $DIC
Definition: shib_login.php:26