ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPCBlogGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 require_once("./Services/COPage/classes/class.ilPCBlog.php");
25 require_once("./Services/COPage/classes/class.ilPageContentGUI.php");
26 
38 {
39 
44  function ilPCBlogGUI(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id = "")
45  {
46  parent::ilPageContentGUI($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
47  }
48 
52  function &executeCommand()
53  {
54  // get next class that processes or forwards current command
55  $next_class = $this->ctrl->getNextClass($this);
56 
57  // get current command
58  $cmd = $this->ctrl->getCmd();
59 
60  switch($next_class)
61  {
62  default:
63  $ret =& $this->$cmd();
64  break;
65  }
66 
67  return $ret;
68  }
69 
75  function insert(ilPropertyFormGUI $a_form = null)
76  {
77  global $tpl;
78 
79  $this->displayValidationError();
80 
81  if(!$a_form)
82  {
83  $a_form = $this->initForm(true);
84  }
85  $tpl->setContent($a_form->getHTML());
86  }
87 
93  function edit(ilPropertyFormGUI $a_form = null)
94  {
95  global $tpl;
96 
97  $this->displayValidationError();
98 
99  if(!$a_form)
100  {
101  $a_form = $this->initForm();
102  }
103  $tpl->setContent($a_form->getHTML());
104  }
105 
112  protected function initForm($a_insert = false)
113  {
114  global $ilCtrl, $ilUser, $lng;
115 
116  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
117  $form = new ilPropertyFormGUI();
118  $form->setFormAction($ilCtrl->getFormAction($this));
119  if ($a_insert)
120  {
121  $form->setTitle($this->lng->txt("cont_insert_blog"));
122  }
123  else
124  {
125  $form->setTitle($this->lng->txt("cont_update_blog"));
126  }
127 
128  $options = array();
129  include_once "Modules/Blog/classes/class.ilBlogPosting.php";
130  $blogs_ids = ilBlogPosting::searchBlogsByAuthor($ilUser->getId());
131  if($blogs_ids)
132  {
133  foreach ($blogs_ids as $blog_id)
134  {
135  $options[$blog_id] = ilObject::_lookupTitle($blog_id);
136  }
137  asort($options);
138  }
139  $obj = new ilSelectInputGUI($this->lng->txt("cont_pc_blog"), "blog");
140  $obj->setRequired(true);
141  $obj->setOptions($options);
142  $form->addItem($obj);
143 
144  if ($a_insert)
145  {
146  $form->addCommandButton("create_blog", $this->lng->txt("select"));
147  $form->addCommandButton("cancelCreate", $this->lng->txt("cancel"));
148  }
149  else
150  {
151  $obj->setValue($this->content_obj->getBlogId());
152  $form->addCommandButton("update", $this->lng->txt("select"));
153  $form->addCommandButton("cancelUpdate", $this->lng->txt("cancel"));
154  }
155 
156  return $form;
157  }
158 
162  function create()
163  {
164  if(!$_POST["blog_id"])
165  {
166  $form = $this->initForm(true);
167  if($form->checkInput())
168  {
169  return $this->insertPosting($_POST["blog"]);
170  }
171 
172  $form->setValuesByPost();
173  return $this->insert($form);
174  }
175  else
176  {
177  $form = $this->initPostingForm($_POST["blog_id"], true);
178  if($form->checkInput())
179  {
180  $this->content_obj = new ilPCBlog($this->dom);
181  $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
182  $this->content_obj->setData($form->getInput("blog_id"), $form->getInput("posting"));
183  $this->updated = $this->pg_obj->update();
184  if ($this->updated === true)
185  {
186  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
187  }
188  }
189 
190  $form->setValuesByPost();
191  return $this->insertPosting($_POST["blog_id"], $form);
192  }
193  }
194 
198  function update()
199  {
200  if(!$_POST["blog_id"])
201  {
202  $form = $this->initForm();
203  if($form->checkInput())
204  {
205  return $this->editPosting($_POST["blog"]);
206  }
207 
208  $this->pg_obj->addHierIDs();
209  $form->setValuesByPost();
210  return $this->edit($form);
211  }
212  else
213  {
214  $form = $this->initPostingForm($_POST["blog_id"]);
215  if($form->checkInput())
216  {
217  $this->content_obj->setData($form->getInput("blog_id"), $form->getInput("posting"));
218  $this->updated = $this->pg_obj->update();
219  if ($this->updated === true)
220  {
221  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
222  }
223  }
224 
225  $this->pg_obj->addHierIDs();
226  $form->setValuesByPost();
227  return $this->editPosting($_POST["blog_id"], $form);
228  }
229  }
230 
231 
238  function insertPosting($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, true);
247  }
248  $tpl->setContent($a_form->getHTML());
249  }
250 
257  function editPosting($a_blog_id, ilPropertyFormGUI $a_form = null)
258  {
259  global $tpl;
260 
261  $this->displayValidationError();
262 
263  if(!$a_form)
264  {
265  $a_form = $this->initPostingForm($a_blog_id);
266  }
267  $tpl->setContent($a_form->getHTML());
268  }
269 
277  protected function initPostingForm($a_blog_id, $a_insert = false)
278  {
279  global $ilCtrl, $ilUser;
280 
281  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
282  $form = new ilPropertyFormGUI();
283  $form->setFormAction($ilCtrl->getFormAction($this));
284  if ($a_insert)
285  {
286  $form->setTitle($this->lng->txt("cont_insert_blog"));
287  }
288  else
289  {
290  $form->setTitle($this->lng->txt("cont_update_blog"));
291  }
292 
293  $options = array();
294  include_once "Modules/Blog/classes/class.ilBlogPosting.php";
295  $postings = ilBlogPosting::getAllPostings($a_blog_id);
296  if($postings)
297  {
298  foreach($postings as $post)
299  {
300  // could be posting from someone else
301  if($post["author"] == $ilUser->getId())
302  {
303  $date = new ilDateTime($post["date"], IL_CAL_DATETIME);
304  $title = $post["title"]." - ".
306 
307  $cbox = new ilCheckboxInputGUI($title, "posting");
308  $cbox->setValue($post["id"]);
309 
310  $options[] = $cbox;
311  }
312  }
313  }
314  asort($options);
315  $obj = new ilCheckboxGroupInputGUI($this->lng->txt("cont_pc_blog_posting"), "posting");
316  $obj->setRequired(true);
317  $obj->setOptions($options);
318  $form->addItem($obj);
319 
320  $blog_id = new ilHiddenInputGUI("blog_id");
321  $blog_id->setValue($a_blog_id);
322  $form->addItem($blog_id);
323 
324  if ($a_insert)
325  {
326  $form->addCommandButton("create_blog", $this->lng->txt("save"));
327  $form->addCommandButton("cancelCreate", $this->lng->txt("cancel"));
328  }
329  else
330  {
331  $obj->setValue($this->content_obj->getPostings());
332  $form->addCommandButton("update", $this->lng->txt("save"));
333  $form->addCommandButton("cancelUpdate", $this->lng->txt("cancel"));
334  }
335 
336  return $form;
337  }
338 }
339 
340 ?>