ILIAS  release_8 Revision v8.24
class.ilPCBlogGUI.php
Go to the documentation of this file.
1<?php
2
26{
27 protected int $requested_blog;
28 protected int $requested_blog_id;
29 protected ilObjUser $user;
30
31 public function __construct(
32 ilPageObject $a_pg_obj,
33 ?ilPageContent $a_content_obj,
34 string $a_hier_id,
35 string $a_pc_id = ""
36 ) {
37 global $DIC;
38
39 $this->tpl = $DIC["tpl"];
40 $this->ctrl = $DIC->ctrl();
41 $this->user = $DIC->user();
42 $this->lng = $DIC->language();
43 parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
44
45 // ... not sure why different ids are used for this...
46 $this->requested_blog_id = $this->request->getInt("blog_id");
47 $this->requested_blog = $this->request->getInt("blog");
48 }
49
53 public function executeCommand(): string
54 {
55 // get next class that processes or forwards current command
56 $next_class = $this->ctrl->getNextClass($this);
57
58 // get current command
59 $cmd = $this->ctrl->getCmd();
60
61 switch ($next_class) {
62 default:
63 $ret = $this->$cmd();
64 break;
65 }
66
67 return (string) $ret;
68 }
69
70 public function insert(ilPropertyFormGUI $a_form = null): void
71 {
73
75
76 if (!$a_form) {
77 $a_form = $this->initForm(true);
78 }
79 $tpl->setContent($a_form->getHTML());
80 }
81
82 public function edit(ilPropertyFormGUI $a_form = null): void
83 {
85
87
88 if (!$a_form) {
89 $a_form = $this->initForm();
90 }
91 $tpl->setContent($a_form->getHTML());
92 }
93
94 protected function initForm(bool $a_insert = false): ilPropertyFormGUI
95 {
96 $ilCtrl = $this->ctrl;
98
99 $form = new ilPropertyFormGUI();
100 $form->setFormAction($ilCtrl->getFormAction($this));
101 if ($a_insert) {
102 $form->setTitle($this->lng->txt("cont_insert_blog"));
103 } else {
104 $form->setTitle($this->lng->txt("cont_update_blog"));
105 }
106
107 $options = array();
108 $blogs_ids = ilBlogPosting::searchBlogsByAuthor($ilUser->getId());
109 if ($blogs_ids) {
110 foreach ($blogs_ids as $blog_id) {
111 $options[$blog_id] = ilObject::_lookupTitle($blog_id);
112 }
113 asort($options);
114 }
115 $obj = new ilSelectInputGUI($this->lng->txt("cont_pc_blog"), "blog");
116 $obj->setRequired(true);
117 $obj->setOptions($options);
118 $form->addItem($obj);
119
120 if ($a_insert) {
121 $form->addCommandButton("create_blog", $this->lng->txt("select"));
122 $form->addCommandButton("cancelCreate", $this->lng->txt("cancel"));
123 } else {
124 $obj->setValue($this->content_obj->getBlogId());
125 $form->addCommandButton("update", $this->lng->txt("select"));
126 $form->addCommandButton("cancelUpdate", $this->lng->txt("cancel"));
127 }
128
129 return $form;
130 }
131
135 public function create(): void
136 {
137 if ($this->requested_blog_id == 0) {
138 $form = $this->initForm(true);
139 if ($form->checkInput()) {
140 $this->insertPosting($this->requested_blog);
141 return;
142 }
143
144 $form->setValuesByPost();
145 $this->insert($form);
146 } else {
147 $form = $this->initPostingForm($this->requested_blog_id, true);
148 if ($form->checkInput()) {
149 $this->content_obj = new ilPCBlog($this->getPage());
150 $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
151 $this->content_obj->setData($form->getInput("blog_id"), $form->getInput("posting"));
152 $this->updated = $this->pg_obj->update();
153 if ($this->updated === true) {
154 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
155 }
156 }
157
158 $form->setValuesByPost();
159 $this->insertPosting($this->requested_blog_id, $form);
160 }
161 }
162
166 public function update(): void
167 {
168 if ($this->requested_blog_id == 0) {
169 $form = $this->initForm();
170 if ($form->checkInput()) {
171 $this->editPosting($this->requested_blog);
172 return;
173 }
174
175 $this->pg_obj->addHierIDs();
176 $form->setValuesByPost();
177 $this->edit($form);
178 } else {
179 $form = $this->initPostingForm($this->requested_blog_id);
180 if ($form->checkInput()) {
181 $this->content_obj->setData($form->getInput("blog_id"), $form->getInput("posting"));
182 $this->updated = $this->pg_obj->update();
183 if ($this->updated === true) {
184 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
185 }
186 }
187
188 $this->pg_obj->addHierIDs();
189 $form->setValuesByPost();
190 $this->editPosting($this->requested_blog_id, $form);
191 }
192 }
193
194
198 public function insertPosting(
199 int $a_blog_id,
200 ilPropertyFormGUI $a_form = null
201 ): void {
202 $tpl = $this->tpl;
203
204 $this->displayValidationError();
205
206 if (!$a_form) {
207 $a_form = $this->initPostingForm($a_blog_id, true);
208 }
209 $tpl->setContent($a_form->getHTML());
210 }
211
215 public function editPosting(
216 int $a_blog_id,
217 ilPropertyFormGUI $a_form = null
218 ): void {
219 $tpl = $this->tpl;
220
221 $this->displayValidationError();
222
223 if (!$a_form) {
224 $a_form = $this->initPostingForm($a_blog_id);
225 }
226 $tpl->setContent($a_form->getHTML());
227 }
228
232 protected function initPostingForm(
233 int $a_blog_id,
234 bool $a_insert = false
236 $ilCtrl = $this->ctrl;
237 $ilUser = $this->user;
238
239 $form = new ilPropertyFormGUI();
240 $form->setFormAction($ilCtrl->getFormAction($this));
241 if ($a_insert) {
242 $form->setTitle($this->lng->txt("cont_insert_blog"));
243 } else {
244 $form->setTitle($this->lng->txt("cont_update_blog"));
245 }
246
247 $options = array();
248 $postings = ilBlogPosting::getAllPostings($a_blog_id);
249 if ($postings) {
250 foreach ($postings as $post) {
251 // could be posting from someone else
252 if ($post["author"] == $ilUser->getId()) {
253 $date = new ilDateTime($post["date"], IL_CAL_DATETIME);
254 $title = $post["title"] . " - " .
256
257 $cbox = new ilCheckboxInputGUI($title, "posting");
258 $cbox->setValue($post["id"]);
259
260 $options[] = $cbox;
261 }
262 }
263 }
264 asort($options);
265 $obj = new ilCheckboxGroupInputGUI($this->lng->txt("cont_pc_blog_posting"), "posting");
266 $obj->setRequired(true);
267 $obj->setOptions($options);
268 $form->addItem($obj);
269
270 $blog_id = new ilHiddenInputGUI("blog_id");
271 $blog_id->setValue($a_blog_id);
272 $form->addItem($blog_id);
273
274 if ($a_insert) {
275 $form->addCommandButton("create_blog", $this->lng->txt("save"));
276 $form->addCommandButton("cancelCreate", $this->lng->txt("cancel"));
277 } else {
278 $obj->setValue($this->content_obj->getPostings());
279 $form->addCommandButton("update", $this->lng->txt("save"));
280 $form->addCommandButton("cancelUpdate", $this->lng->txt("cancel"));
281 }
282
283 return $form;
284 }
285}
const IL_CAL_DATETIME
static searchBlogsByAuthor(int $a_user_id)
Get all blogs where user has postings.
static getAllPostings(int $a_blog_id, int $a_limit=1000, int $a_offset=0)
Get all postings of blog.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a checkbox property in a property form.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
@classDescription Date and time handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
User class.
static _lookupTitle(int $obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
edit(ilPropertyFormGUI $a_form=null)
update()
Update blog.
create()
Create new blog.
insert(ilPropertyFormGUI $a_form=null)
insertPosting(int $a_blog_id, ilPropertyFormGUI $a_form=null)
Insert new blog posting form.
executeCommand()
execute command
initPostingForm(int $a_blog_id, bool $a_insert=false)
Init blog posting form.
initForm(bool $a_insert=false)
__construct(ilPageObject $a_pg_obj, ?ilPageContent $a_content_obj, string $a_hier_id, string $a_pc_id="")
editPosting(int $a_blog_id, ilPropertyFormGUI $a_form=null)
Edit blog posting form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
ilGlobalTemplateInterface $tpl
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
This class represents a property form user interface.
This class represents a selection list property in a property form.
global $DIC
Definition: feed.php:28
$ilUser
Definition: imgupload.php:34
setContent(string $a_html)
Sets content for standard template.
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
$post
Definition: ltitoken.php:49
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc