ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilPCBlogGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5require_once("./Services/COPage/classes/class.ilPCBlog.php");
6require_once("./Services/COPage/classes/class.ilPageContentGUI.php");
7
19{
23 protected $user;
24
25
30 public function __construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id = "")
31 {
32 global $DIC;
33
34 $this->tpl = $DIC["tpl"];
35 $this->ctrl = $DIC->ctrl();
36 $this->user = $DIC->user();
37 $this->lng = $DIC->language();
38 parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
39 }
40
44 public function executeCommand()
45 {
46 // get next class that processes or forwards current command
47 $next_class = $this->ctrl->getNextClass($this);
48
49 // get current command
50 $cmd = $this->ctrl->getCmd();
51
52 switch ($next_class) {
53 default:
54 $ret = $this->$cmd();
55 break;
56 }
57
58 return $ret;
59 }
60
66 public function insert(ilPropertyFormGUI $a_form = null)
67 {
69
71
72 if (!$a_form) {
73 $a_form = $this->initForm(true);
74 }
75 $tpl->setContent($a_form->getHTML());
76 }
77
83 public function edit(ilPropertyFormGUI $a_form = null)
84 {
86
88
89 if (!$a_form) {
90 $a_form = $this->initForm();
91 }
92 $tpl->setContent($a_form->getHTML());
93 }
94
101 protected function initForm($a_insert = false)
102 {
106
107 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
108 $form = new ilPropertyFormGUI();
109 $form->setFormAction($ilCtrl->getFormAction($this));
110 if ($a_insert) {
111 $form->setTitle($this->lng->txt("cont_insert_blog"));
112 } else {
113 $form->setTitle($this->lng->txt("cont_update_blog"));
114 }
115
116 $options = array();
117 $blogs_ids = ilBlogPosting::searchBlogsByAuthor($ilUser->getId());
118 if ($blogs_ids) {
119 foreach ($blogs_ids as $blog_id) {
120 $options[$blog_id] = ilObject::_lookupTitle($blog_id);
121 }
122 asort($options);
123 }
124 $obj = new ilSelectInputGUI($this->lng->txt("cont_pc_blog"), "blog");
125 $obj->setRequired(true);
126 $obj->setOptions($options);
127 $form->addItem($obj);
128
129 if ($a_insert) {
130 $form->addCommandButton("create_blog", $this->lng->txt("select"));
131 $form->addCommandButton("cancelCreate", $this->lng->txt("cancel"));
132 } else {
133 $obj->setValue($this->content_obj->getBlogId());
134 $form->addCommandButton("update", $this->lng->txt("select"));
135 $form->addCommandButton("cancelUpdate", $this->lng->txt("cancel"));
136 }
137
138 return $form;
139 }
140
144 public function create()
145 {
146 if (!$_POST["blog_id"]) {
147 $form = $this->initForm(true);
148 if ($form->checkInput()) {
149 return $this->insertPosting($_POST["blog"]);
150 }
151
152 $form->setValuesByPost();
153 return $this->insert($form);
154 } else {
155 $form = $this->initPostingForm($_POST["blog_id"], true);
156 if ($form->checkInput()) {
157 $this->content_obj = new ilPCBlog($this->getPage());
158 $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
159 $this->content_obj->setData($form->getInput("blog_id"), $form->getInput("posting"));
160 $this->updated = $this->pg_obj->update();
161 if ($this->updated === true) {
162 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
163 }
164 }
165
166 $form->setValuesByPost();
167 return $this->insertPosting($_POST["blog_id"], $form);
168 }
169 }
170
174 public function update()
175 {
176 if (!$_POST["blog_id"]) {
177 $form = $this->initForm();
178 if ($form->checkInput()) {
179 return $this->editPosting($_POST["blog"]);
180 }
181
182 $this->pg_obj->addHierIDs();
183 $form->setValuesByPost();
184 return $this->edit($form);
185 } else {
186 $form = $this->initPostingForm($_POST["blog_id"]);
187 if ($form->checkInput()) {
188 $this->content_obj->setData($form->getInput("blog_id"), $form->getInput("posting"));
189 $this->updated = $this->pg_obj->update();
190 if ($this->updated === true) {
191 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
192 }
193 }
194
195 $this->pg_obj->addHierIDs();
196 $form->setValuesByPost();
197 return $this->editPosting($_POST["blog_id"], $form);
198 }
199 }
200
201
208 public function insertPosting($a_blog_id, ilPropertyFormGUI $a_form = null)
209 {
211
212 $this->displayValidationError();
213
214 if (!$a_form) {
215 $a_form = $this->initPostingForm($a_blog_id, true);
216 }
217 $tpl->setContent($a_form->getHTML());
218 }
219
226 public function editPosting($a_blog_id, ilPropertyFormGUI $a_form = null)
227 {
229
230 $this->displayValidationError();
231
232 if (!$a_form) {
233 $a_form = $this->initPostingForm($a_blog_id);
234 }
235 $tpl->setContent($a_form->getHTML());
236 }
237
245 protected function initPostingForm($a_blog_id, $a_insert = false)
246 {
249
250 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
251 $form = new ilPropertyFormGUI();
252 $form->setFormAction($ilCtrl->getFormAction($this));
253 if ($a_insert) {
254 $form->setTitle($this->lng->txt("cont_insert_blog"));
255 } else {
256 $form->setTitle($this->lng->txt("cont_update_blog"));
257 }
258
259 $options = array();
260 $postings = ilBlogPosting::getAllPostings($a_blog_id);
261 if ($postings) {
262 foreach ($postings as $post) {
263 // could be posting from someone else
264 if ($post["author"] == $ilUser->getId()) {
265 $date = new ilDateTime($post["date"], IL_CAL_DATETIME);
266 $title = $post["title"] . " - " .
268
269 $cbox = new ilCheckboxInputGUI($title, "posting");
270 $cbox->setValue($post["id"]);
271
272 $options[] = $cbox;
273 }
274 }
275 }
276 asort($options);
277 $obj = new ilCheckboxGroupInputGUI($this->lng->txt("cont_pc_blog_posting"), "posting");
278 $obj->setRequired(true);
279 $obj->setOptions($options);
280 $form->addItem($obj);
281
282 $blog_id = new ilHiddenInputGUI("blog_id");
283 $blog_id->setValue($a_blog_id);
284 $form->addItem($blog_id);
285
286 if ($a_insert) {
287 $form->addCommandButton("create_blog", $this->lng->txt("save"));
288 $form->addCommandButton("cancelCreate", $this->lng->txt("cancel"));
289 } else {
290 $obj->setValue($this->content_obj->getPostings());
291 $form->addCommandButton("update", $this->lng->txt("save"));
292 $form->addCommandButton("cancelUpdate", $this->lng->txt("cancel"));
293 }
294
295 return $form;
296 }
297}
user()
Definition: user.php:4
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATETIME
static getAllPostings($a_blog_id, $a_limit=1000, $a_offset=0)
Get all postings of blog.
static searchBlogsByAuthor($a_user_id)
Get all blogs where user has postings.
This class represents a property in a property form.
This class represents a checkbox property in a property form.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
@classDescription Date and time handling
This class represents a hidden form property in a property form.
static _lookupTitle($a_id)
lookup object title
Class ilPCBlogGUI.
edit(ilPropertyFormGUI $a_form=null)
Edit blog form.
update()
Update blog.
create()
Create new blog.
insert(ilPropertyFormGUI $a_form=null)
Insert blog form.
insertPosting($a_blog_id, ilPropertyFormGUI $a_form=null)
Insert new blog posting form.
executeCommand()
execute command
initForm($a_insert=false)
Init blog form.
initPostingForm($a_blog_id, $a_insert=false)
Init blog posting form.
editPosting($a_blog_id, ilPropertyFormGUI $a_form=null)
Edit blog posting form.
__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id="")
Constructor @access public.
Class ilPCBlog.
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
displayValidationError()
display validation errors
This class represents a property form user interface.
This class represents a selection list property in a property form.
global $ilCtrl
Definition: ilias.php:18
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$ret
Definition: parser.php:6
$ilUser
Definition: imgupload.php:18
$DIC
Definition: xapitoken.php:46