ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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{
20
25 function ilPCBlogGUI($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id = "")
26 {
27 parent::ilPageContentGUI($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
28 }
29
33 function &executeCommand()
34 {
35 // get next class that processes or forwards current command
36 $next_class = $this->ctrl->getNextClass($this);
37
38 // get current command
39 $cmd = $this->ctrl->getCmd();
40
41 switch($next_class)
42 {
43 default:
44 $ret =& $this->$cmd();
45 break;
46 }
47
48 return $ret;
49 }
50
56 function insert(ilPropertyFormGUI $a_form = null)
57 {
58 global $tpl;
59
61
62 if(!$a_form)
63 {
64 $a_form = $this->initForm(true);
65 }
66 $tpl->setContent($a_form->getHTML());
67 }
68
74 function edit(ilPropertyFormGUI $a_form = null)
75 {
76 global $tpl;
77
79
80 if(!$a_form)
81 {
82 $a_form = $this->initForm();
83 }
84 $tpl->setContent($a_form->getHTML());
85 }
86
93 protected function initForm($a_insert = false)
94 {
95 global $ilCtrl, $ilUser, $lng;
96
97 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
98 $form = new ilPropertyFormGUI();
99 $form->setFormAction($ilCtrl->getFormAction($this));
100 if ($a_insert)
101 {
102 $form->setTitle($this->lng->txt("cont_insert_blog"));
103 }
104 else
105 {
106 $form->setTitle($this->lng->txt("cont_update_blog"));
107 }
108
109 $options = array();
110 include_once "Modules/Blog/classes/class.ilBlogPosting.php";
111 $blogs_ids = ilBlogPosting::searchBlogsByAuthor($ilUser->getId());
112 if($blogs_ids)
113 {
114 foreach ($blogs_ids as $blog_id)
115 {
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 {
127 $form->addCommandButton("create_blog", $this->lng->txt("select"));
128 $form->addCommandButton("cancelCreate", $this->lng->txt("cancel"));
129 }
130 else
131 {
132 $obj->setValue($this->content_obj->getBlogId());
133 $form->addCommandButton("update", $this->lng->txt("select"));
134 $form->addCommandButton("cancelUpdate", $this->lng->txt("cancel"));
135 }
136
137 return $form;
138 }
139
143 function create()
144 {
145 if(!$_POST["blog_id"])
146 {
147 $form = $this->initForm(true);
148 if($form->checkInput())
149 {
150 return $this->insertPosting($_POST["blog"]);
151 }
152
153 $form->setValuesByPost();
154 return $this->insert($form);
155 }
156 else
157 {
158 $form = $this->initPostingForm($_POST["blog_id"], true);
159 if($form->checkInput())
160 {
161 $this->content_obj = new ilPCBlog($this->getPage());
162 $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
163 $this->content_obj->setData($form->getInput("blog_id"), $form->getInput("posting"));
164 $this->updated = $this->pg_obj->update();
165 if ($this->updated === true)
166 {
167 $this->ctrl->returnToParent($this, "jump".$this->hier_id);
168 }
169 }
170
171 $form->setValuesByPost();
172 return $this->insertPosting($_POST["blog_id"], $form);
173 }
174 }
175
179 function update()
180 {
181 if(!$_POST["blog_id"])
182 {
183 $form = $this->initForm();
184 if($form->checkInput())
185 {
186 return $this->editPosting($_POST["blog"]);
187 }
188
189 $this->pg_obj->addHierIDs();
190 $form->setValuesByPost();
191 return $this->edit($form);
192 }
193 else
194 {
195 $form = $this->initPostingForm($_POST["blog_id"]);
196 if($form->checkInput())
197 {
198 $this->content_obj->setData($form->getInput("blog_id"), $form->getInput("posting"));
199 $this->updated = $this->pg_obj->update();
200 if ($this->updated === true)
201 {
202 $this->ctrl->returnToParent($this, "jump".$this->hier_id);
203 }
204 }
205
206 $this->pg_obj->addHierIDs();
207 $form->setValuesByPost();
208 return $this->editPosting($_POST["blog_id"], $form);
209 }
210 }
211
212
219 function insertPosting($a_blog_id, ilPropertyFormGUI $a_form = null)
220 {
221 global $tpl;
222
223 $this->displayValidationError();
224
225 if(!$a_form)
226 {
227 $a_form = $this->initPostingForm($a_blog_id, true);
228 }
229 $tpl->setContent($a_form->getHTML());
230 }
231
238 function editPosting($a_blog_id, ilPropertyFormGUI $a_form = null)
239 {
240 global $tpl;
241
242 $this->displayValidationError();
243
244 if(!$a_form)
245 {
246 $a_form = $this->initPostingForm($a_blog_id);
247 }
248 $tpl->setContent($a_form->getHTML());
249 }
250
258 protected function initPostingForm($a_blog_id, $a_insert = false)
259 {
260 global $ilCtrl, $ilUser;
261
262 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
263 $form = new ilPropertyFormGUI();
264 $form->setFormAction($ilCtrl->getFormAction($this));
265 if ($a_insert)
266 {
267 $form->setTitle($this->lng->txt("cont_insert_blog"));
268 }
269 else
270 {
271 $form->setTitle($this->lng->txt("cont_update_blog"));
272 }
273
274 $options = array();
275 include_once "Modules/Blog/classes/class.ilBlogPosting.php";
276 $postings = ilBlogPosting::getAllPostings($a_blog_id);
277 if($postings)
278 {
279 foreach($postings as $post)
280 {
281 // could be posting from someone else
282 if($post["author"] == $ilUser->getId())
283 {
284 $date = new ilDateTime($post["date"], IL_CAL_DATETIME);
285 $title = $post["title"]." - ".
287
288 $cbox = new ilCheckboxInputGUI($title, "posting");
289 $cbox->setValue($post["id"]);
290
291 $options[] = $cbox;
292 }
293 }
294 }
295 asort($options);
296 $obj = new ilCheckboxGroupInputGUI($this->lng->txt("cont_pc_blog_posting"), "posting");
297 $obj->setRequired(true);
298 $obj->setOptions($options);
299 $form->addItem($obj);
300
301 $blog_id = new ilHiddenInputGUI("blog_id");
302 $blog_id->setValue($a_blog_id);
303 $form->addItem($blog_id);
304
305 if ($a_insert)
306 {
307 $form->addCommandButton("create_blog", $this->lng->txt("save"));
308 $form->addCommandButton("cancelCreate", $this->lng->txt("cancel"));
309 }
310 else
311 {
312 $obj->setValue($this->content_obj->getPostings());
313 $form->addCommandButton("update", $this->lng->txt("save"));
314 $form->addCommandButton("cancelUpdate", $this->lng->txt("cancel"));
315 }
316
317 return $form;
318 }
319}
320
321?>
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)
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.
initForm($a_insert=false)
Init blog form.
initPostingForm($a_blog_id, $a_insert=false)
Init blog posting form.
& executeCommand()
execute command
ilPCBlogGUI($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id="")
Constructor @access public.
editPosting($a_blog_id, ilPropertyFormGUI $a_form=null)
Edit blog posting form.
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.
$_POST['username']
Definition: cron.php:12
global $ilCtrl
Definition: ilias.php:18
$cmd
Definition: sahs_server.php:35
if(!is_array($argv)) $options
global $ilUser
Definition: imgupload.php:15