ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilPCBlogGUI.php
Go to the documentation of this file.
1<?php
2
20
28{
30 protected int $requested_blog;
31 protected int $requested_blog_id;
32 protected ilObjUser $user;
33
34 public function __construct(
35 ilPageObject $a_pg_obj,
36 ?ilPageContent $a_content_obj,
37 string $a_hier_id,
38 string $a_pc_id = ""
39 ) {
40 global $DIC;
41
42 $this->tpl = $DIC["tpl"];
43 $this->ctrl = $DIC->ctrl();
44 $this->user = $DIC->user();
45 $this->lng = $DIC->language();
46 parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
47
48 // ... not sure why different ids are used for this...
49 $this->requested_blog_id = $this->request->getInt("blog_id");
50 $this->requested_blog = $this->request->getInt("blog");
51 $this->posting_manger = $DIC->blog()->internal()->domain()->posting();
52 }
53
57 public function executeCommand(): string
58 {
59 // get next class that processes or forwards current command
60 $next_class = $this->ctrl->getNextClass($this);
61
62 // get current command
63 $cmd = $this->ctrl->getCmd();
64
65 switch ($next_class) {
66 default:
67 $ret = $this->$cmd();
68 break;
69 }
70
71 return (string) $ret;
72 }
73
74 public function insert(?ilPropertyFormGUI $a_form = null): void
75 {
77
79
80 if (!$a_form) {
81 $a_form = $this->initForm(true);
82 }
83 $tpl->setContent($a_form->getHTML());
84 }
85
86 public function edit(?ilPropertyFormGUI $a_form = null): void
87 {
89
91
92 if (!$a_form) {
93 $a_form = $this->initForm();
94 }
95 $tpl->setContent($a_form->getHTML());
96 }
97
98 protected function initForm(bool $a_insert = false): ilPropertyFormGUI
99 {
100 $ilCtrl = $this->ctrl;
101 $ilUser = $this->user;
102
103 $form = new ilPropertyFormGUI();
104 $form->setFormAction($ilCtrl->getFormAction($this));
105 if ($a_insert) {
106 $form->setTitle($this->lng->txt("cont_insert_blog"));
107 } else {
108 $form->setTitle($this->lng->txt("cont_update_blog"));
109 }
110
111 $options = array();
112 $blogs_ids = $this->posting_manger->searchBlogsByAuthor($ilUser->getId());
113
114 if ($blogs_ids) {
115 foreach ($blogs_ids as $blog_id) {
116 $options[$blog_id] = ilObject::_lookupTitle($blog_id);
117 }
118 asort($options);
119 }
120 $obj = new ilSelectInputGUI($this->lng->txt("cont_pc_blog"), "blog");
121 $obj->setRequired(true);
122 $obj->setOptions($options);
123 $form->addItem($obj);
124
125 if ($a_insert) {
126 $form->addCommandButton("create", $this->lng->txt("select"));
127 $form->addCommandButton("cancelCreate", $this->lng->txt("cancel"));
128 } else {
129 $obj->setValue($this->content_obj->getBlogId());
130 $form->addCommandButton("update", $this->lng->txt("select"));
131 $form->addCommandButton("cancelUpdate", $this->lng->txt("cancel"));
132 }
133
134 return $form;
135 }
136
140 public function create(): void
141 {
142 if ($this->requested_blog_id == 0) {
143 $form = $this->initForm(true);
144 if ($form->checkInput()) {
145 $this->insertPosting($this->requested_blog);
146 return;
147 }
148
149 $form->setValuesByPost();
150 $this->insert($form);
151 } else {
152 $form = $this->initPostingForm($this->requested_blog_id, true);
153 if ($form->checkInput()) {
154 $this->content_obj = new ilPCBlog($this->getPage());
155 $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
156 $this->content_obj->setData($form->getInput("blog_id"), $form->getInput("posting"));
157 $this->updated = $this->pg_obj->update();
158 if ($this->updated === true) {
159 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
160 }
161 }
162
163 $form->setValuesByPost();
164 $this->insertPosting($this->requested_blog_id, $form);
165 }
166 }
167
171 public function update(): void
172 {
173 if ($this->requested_blog_id == 0) {
174 $form = $this->initForm();
175 if ($form->checkInput()) {
176 $this->editPosting($this->requested_blog);
177 return;
178 }
179
180 $this->pg_obj->addHierIDs();
181 $form->setValuesByPost();
182 $this->edit($form);
183 } else {
184 $form = $this->initPostingForm($this->requested_blog_id);
185 if ($form->checkInput()) {
186 $this->content_obj->setData($form->getInput("blog_id"), $form->getInput("posting"));
187 $this->updated = $this->pg_obj->update();
188 if ($this->updated === true) {
189 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
190 }
191 }
192
193 $this->pg_obj->addHierIDs();
194 $form->setValuesByPost();
195 $this->editPosting($this->requested_blog_id, $form);
196 }
197 }
198
199
203 public function insertPosting(
204 int $a_blog_id,
205 ?ilPropertyFormGUI $a_form = null
206 ): void {
207 $tpl = $this->tpl;
208
209 $this->displayValidationError();
210
211 if (!$a_form) {
212 $a_form = $this->initPostingForm($a_blog_id, true);
213 }
214 $tpl->setContent($a_form->getHTML());
215 }
216
220 public function editPosting(
221 int $a_blog_id,
222 ?ilPropertyFormGUI $a_form = null
223 ): void {
224 $tpl = $this->tpl;
225
226 $this->displayValidationError();
227
228 if (!$a_form) {
229 $a_form = $this->initPostingForm($a_blog_id);
230 }
231 $tpl->setContent($a_form->getHTML());
232 }
233
237 protected function initPostingForm(
238 int $a_blog_id,
239 bool $a_insert = false
241 $ilCtrl = $this->ctrl;
242 $ilUser = $this->user;
243
244 $form = new ilPropertyFormGUI();
245 $form->setFormAction($ilCtrl->getFormAction($this));
246 if ($a_insert) {
247 $form->setTitle($this->lng->txt("cont_insert_blog"));
248 } else {
249 $form->setTitle($this->lng->txt("cont_update_blog"));
250 }
251
252 $options = array();
253 $postings = ilBlogPosting::getAllPostings($a_blog_id);
254 if ($postings) {
255 foreach ($postings as $post) {
256 // could be posting from someone else
257 if ($post["author"] == $ilUser->getId()) {
258 $date = new ilDateTime($post["date"], IL_CAL_DATETIME);
259 $title = $post["title"] . " - " .
261
262 $cbox = new ilCheckboxInputGUI($title, "posting");
263 $cbox->setValue($post["id"]);
264
265 $options[] = $cbox;
266 }
267 }
268 }
269 asort($options);
270 $obj = new ilCheckboxGroupInputGUI($this->lng->txt("cont_pc_blog_posting"), "posting");
271 $obj->setRequired(true);
272 $obj->setOptions($options);
273 $form->addItem($obj);
274
275 $blog_id = new ilHiddenInputGUI("blog_id");
276 $blog_id->setValue($a_blog_id);
277 $form->addItem($blog_id);
278
279 if ($a_insert) {
280 $form->addCommandButton("create", $this->lng->txt("save"));
281 $form->addCommandButton("cancelCreate", $this->lng->txt("cancel"));
282 } else {
283 $obj->setValue($this->content_obj->getPostings());
284 $form->addCommandButton("update", $this->lng->txt("save"));
285 $form->addCommandButton("cancelUpdate", $this->lng->txt("cancel"));
286 }
287
288 return $form;
289 }
290}
const IL_CAL_DATETIME
static getAllPostings(int $a_blog_id, int $a_limit=1000, int $a_offset=0)
Get all postings of blog.
This class represents a property in a property form.
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, ?ilObjUser $user=null,)
@classDescription Date and time handling
This class represents a hidden form property in a property form.
User class.
static _lookupTitle(int $obj_id)
Class ilPCBlogGUI Handles user commands on blog data.
edit(?ilPropertyFormGUI $a_form=null)
update()
Update blog.
insert(?ilPropertyFormGUI $a_form=null)
create()
Create new blog.
PostingManager $posting_manger
executeCommand()
execute command
insertPosting(int $a_blog_id, ?ilPropertyFormGUI $a_form=null)
Insert new blog posting form.
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.
Class ilPCBlog Blog content object (see ILIAS DTD)
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
ilGlobalTemplateInterface $tpl
Content object of ilPageObject (see ILIAS DTD).
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.
setContent(string $a_html)
Sets content for standard template.
$post
Definition: ltitoken.php:46
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26