ILIAS  trunk Revision v13.0_alpha-52-g21c366bbdd4
class.ilBlogPosting.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23
30{
31 protected \ILIAS\Blog\Posting\Service\GUIService $posting_gui;
32 protected string $title = "";
33 protected ?ilDateTime $created = null;
34 protected int $blog_node_id = 0;
35 protected bool $blog_node_is_wsp = false;
36 protected int $author = 0;
37 protected bool $approved = false;
38 protected ?ilDateTime $withdrawn = null;
41 protected \ILIAS\Blog\InternalDomainService $blog_domain;
42
43 public function afterConstructor(): void
44 {
45 global $DIC;
46 $this->internal_data = $DIC->blog()->internal()->data();
47 $this->posting_manager = $DIC->blog()->internal()->domain()->posting();
48 $this->blog_domain = $DIC->blog()->internal()->domain();
49 $this->posting_gui = $DIC->blog()->internal()->gui()->posting();
50
51 }
52
53 public function getParentType(): string
54 {
55 return "blp";
56 }
57
58 public function setTitle(string $a_title): void
59 {
60 $this->title = $a_title;
61 }
62
63 public function getTitle(): string
64 {
65 return $this->title;
66 }
67
68 public function setBlogId(int $a_id): void
69 {
70 $this->setParentId($a_id);
71 }
72
73 public function getBlogId(): int
74 {
75 return $this->getParentId();
76 }
77
78 public function setCreated(ilDateTime $a_date): void
79 {
80 $this->created = $a_date;
81 }
82
83 public function getCreated(): ilDateTime
84 {
85 return $this->created;
86 }
87
88 public function setAuthor(int $a_id): void
89 {
90 $this->author = $a_id;
91 }
92
93 public function getAuthor(): int
94 {
95 return $this->author;
96 }
97
98 public function setApproved(bool $a_status): void
99 {
100 $this->approved = $a_status;
101 }
102
103 public function isApproved(): bool
104 {
105 return $this->approved;
106 }
107
111 public function setWithdrawn(
112 ilDateTime $a_date
113 ): void {
114 $this->withdrawn = $a_date;
115 }
116
120 public function getWithdrawn(): ?ilDateTime
121 {
122 return $this->withdrawn;
123 }
124
128 public function create(
129 bool $a_import = false
130 ): void {
131 $data = $this->internal_data;
132
133 if (!$a_import) {
134 $created = ilUtil::now();
135 } else {
136 $created = $this->getCreated()->get(IL_CAL_DATETIME);
137 }
138
139 $post = $data->posting(
140 0,
141 $this->getBlogId(),
142 $this->getTitle(),
143 new ilDateTime($created, IL_CAL_DATETIME),
144 $this->getAuthor(),
145 $this->isApproved(),
146 $this->getWithdrawn()
147 );
148 $id = $this->posting_manager->create($post);
149 $this->setId($id);
150
151 if (!$a_import) {
152 parent::create($a_import);
153 }
154 }
155
156 public function update(
157 bool $a_validate = true,
158 bool $a_no_history = false,
159 bool $a_notify = true,
160 string $a_notify_action = "update"
161 ): array|bool {
162 $data = $this->internal_data;
163 $post = $data->posting(
164 $this->getId(),
165 $this->getBlogId(),
166 $this->getTitle(),
167 $this->getCreated(),
168 $this->getAuthor(),
169 $this->isApproved(),
170 $this->getWithdrawn()
171 );
172 $this->posting_manager->update($post);
173
174 $ret = parent::update($a_validate, $a_no_history);
175
176 if ($a_notify && $this->getActive()) {
177 $this->blog_domain->notification()->sendNotification(
178 $a_notify_action,
179 $this->blog_node_is_wsp,
180 $this->blog_node_id,
181 $this->getId()
182 );
183 }
184
185 return $ret;
186 }
187
191 public function read(): void
192 {
193 $ilDB = $this->db;
194
195 $query = "SELECT * FROM il_blog_posting" .
196 " WHERE id = " . $ilDB->quote($this->getId(), "integer");
197 $set = $ilDB->query($query);
198 $rec = $ilDB->fetchAssoc($set);
199
200 $this->setTitle($rec["title"]);
201 $this->setBlogId($rec["blog_id"]);
202 $this->setCreated(new ilDateTime($rec["created"], IL_CAL_DATETIME));
203 $this->setAuthor($rec["author"]);
204 if ($rec["approved"]) {
205 $this->setApproved(true);
206 }
207 $this->setWithdrawn(new ilDateTime($rec["last_withdrawn"], IL_CAL_DATETIME));
208
209 // when posting is deactivated it should loose the approval
210 $this->addUpdateListener($this, "checkApproval");
211
212 parent::read();
213 }
214
215 public function checkApproval(): void
216 {
217 if (!$this->getActive() && $this->isApproved()) {
218 $this->approved = false;
219 $this->update();
220 }
221 }
222
226 public function delete(): void
227 {
228 $ilDB = $this->db;
229
231 $this->getBlogId(),
232 "blog",
233 $this->getId(),
234 $this->getParentType()
235 );
236
237 $this->posting_manager->delete($this->getId());
238
239 parent::delete();
240 }
241
245 public function unpublish(): void
246 {
247 $this->setApproved(false);
248 $this->setActive(false);
249 $this->setWithdrawn(new ilDateTime(ilUtil::now(), IL_CAL_DATETIME));
250 $this->update(true, false, false);
251
253 $this->getBlogId(),
254 "blog",
255 $this->getId(),
256 $this->getParentType()
257 );
258 }
259
263 public function setBlogNodeId(
264 int $a_id,
265 bool $a_is_in_workspace = false
266 ): void {
267 $this->blog_node_id = $a_id;
268 $this->blog_node_is_wsp = $a_is_in_workspace;
269 }
270
271 public function getNotificationAbstract(): string
272 {
273 $snippet = $this->posting_gui->getSnippet($this->getId(), true);
274
275 // making things more readable
276 $snippet = str_replace(array('<br/>', '<br />', '</p>', '</div>'), "\n", $snippet);
277
278 return trim(strip_tags($snippet));
279 }
280
281 // keywords
282 public function updateKeywords(
283 array $keywords
284 ): void {
285 $this->lom_services->manipulate($this->getBlogId(), $this->getId(), "blp")
286 ->prepareDelete($this->lom_services->paths()->keywords())
287 ->prepareCreateOrUpdate($this->lom_services->paths()->keywords(), ...$keywords)
288 ->execute();
289 }
290}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
const IL_CAL_DATETIME
Class ilBlogPosting.
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)
updateKeywords(array $keywords)
ILIAS Blog InternalDomainService $blog_domain
PostingManager $posting_manager
InternalDataService $internal_data
setCreated(ilDateTime $a_date)
ILIAS Blog Posting Service GUIService $posting_gui
setWithdrawn(ilDateTime $a_date)
Set last withdrawal date.
setTitle(string $a_title)
getWithdrawn()
Get last withdrawal date.
read()
Read blog posting.
@classDescription Date and time handling
get(int $a_format, string $a_format_str='', string $a_tz='')
get formatted date
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.
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.
global $DIC
Definition: shib_login.php:26
$data
Definition: storeScorm.php:45