ILIAS  Release_4_2_x_branch Revision 61807
 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 "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
130  $tree = new ilWorkspaceTree($ilUser->getId());
131  $root = $tree->getRootId();
132  if($root)
133  {
134  $root = $tree->getNodeData($root);
135  foreach ($tree->getSubTree($root) as $node)
136  {
137  if ($node["type"] == "blog")
138  {
139  $options[$node["obj_id"]] = $node["title"];
140  }
141  }
142  asort($options);
143  }
144  $obj = new ilSelectInputGUI($this->lng->txt("cont_pc_blog"), "blog");
145  $obj->setRequired(true);
146  $obj->setOptions($options);
147  $form->addItem($obj);
148 
149  if ($a_insert)
150  {
151  $form->addCommandButton("create_blog", $this->lng->txt("select"));
152  $form->addCommandButton("cancelCreate", $this->lng->txt("cancel"));
153  }
154  else
155  {
156  $obj->setValue($this->content_obj->getBlogId());
157  $form->addCommandButton("update", $this->lng->txt("select"));
158  $form->addCommandButton("cancelUpdate", $this->lng->txt("cancel"));
159  }
160 
161  return $form;
162  }
163 
167  function create()
168  {
169  if(!$_POST["blog_id"])
170  {
171  $form = $this->initForm(true);
172  if($form->checkInput())
173  {
174  return $this->insertPosting($_POST["blog"]);
175  }
176 
177  $form->setValuesByPost();
178  return $this->insert($form);
179  }
180  else
181  {
182  $form = $this->initPostingForm($_POST["blog_id"], true);
183  if($form->checkInput())
184  {
185  $this->content_obj = new ilPCBlog($this->dom);
186  $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
187  $this->content_obj->setData($form->getInput("blog_id"), $form->getInput("posting"));
188  $this->updated = $this->pg_obj->update();
189  if ($this->updated === true)
190  {
191  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
192  }
193  }
194 
195  $form->setValuesByPost();
196  return $this->insertPosting($_POST["blog_id"], $form);
197  }
198  }
199 
203  function update()
204  {
205  if(!$_POST["blog_id"])
206  {
207  $form = $this->initForm();
208  if($form->checkInput())
209  {
210  return $this->editPosting($_POST["blog"]);
211  }
212 
213  $this->pg_obj->addHierIDs();
214  $form->setValuesByPost();
215  return $this->edit($form);
216  }
217  else
218  {
219  $form = $this->initPostingForm($_POST["blog_id"]);
220  if($form->checkInput())
221  {
222  $this->content_obj->setData($form->getInput("blog_id"), $form->getInput("posting"));
223  $this->updated = $this->pg_obj->update();
224  if ($this->updated === true)
225  {
226  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
227  }
228  }
229 
230  $this->pg_obj->addHierIDs();
231  $form->setValuesByPost();
232  return $this->editPosting($_POST["blog_id"], $form);
233  }
234  }
235 
236 
243  function insertPosting($a_blog_id, ilPropertyFormGUI $a_form = null)
244  {
245  global $tpl;
246 
247  $this->displayValidationError();
248 
249  if(!$a_form)
250  {
251  $a_form = $this->initPostingForm($a_blog_id, true);
252  }
253  $tpl->setContent($a_form->getHTML());
254  }
255 
262  function editPosting($a_blog_id, ilPropertyFormGUI $a_form = null)
263  {
264  global $tpl;
265 
266  $this->displayValidationError();
267 
268  if(!$a_form)
269  {
270  $a_form = $this->initPostingForm($a_blog_id);
271  }
272  $tpl->setContent($a_form->getHTML());
273  }
274 
282  protected function initPostingForm($a_blog_id, $a_insert = false)
283  {
284  global $ilCtrl, $ilUser, $lng;
285 
286  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
287  $form = new ilPropertyFormGUI();
288  $form->setFormAction($ilCtrl->getFormAction($this));
289  if ($a_insert)
290  {
291  $form->setTitle($this->lng->txt("cont_insert_blog"));
292  }
293  else
294  {
295  $form->setTitle($this->lng->txt("cont_update_blog"));
296  }
297 
298  $options = array();
299  include_once "Modules/Blog/classes/class.ilBlogPosting.php";
300  $postings = ilBlogPosting::getAllPostings($a_blog_id);
301  if($postings)
302  {
303  foreach($postings as $post)
304  {
305  $date = new ilDateTime($post["date"], IL_CAL_DATETIME);
306  $title = $post["title"]." - ".
308 
309  $cbox = new ilCheckboxInputGUI($title, "posting");
310  $cbox->setValue($post["id"]);
311 
312  $options[] = $cbox;
313  }
314  }
315  asort($options);
316  $obj = new ilCheckboxGroupInputGUI($this->lng->txt("cont_pc_blog_posting"), "posting");
317  $obj->setRequired(true);
318  $obj->setOptions($options);
319  $form->addItem($obj);
320 
321  $blog_id = new ilHiddenInputGUI("blog_id");
322  $blog_id->setValue($a_blog_id);
323  $form->addItem($blog_id);
324 
325  if ($a_insert)
326  {
327  $form->addCommandButton("create_blog", $this->lng->txt("save"));
328  $form->addCommandButton("cancelCreate", $this->lng->txt("cancel"));
329  }
330  else
331  {
332  $obj->setValue($this->content_obj->getPostings());
333  $form->addCommandButton("update", $this->lng->txt("save"));
334  $form->addCommandButton("cancelUpdate", $this->lng->txt("cancel"));
335  }
336 
337  return $form;
338  }
339 }
340 
341 ?>