ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
5 require_once("./Services/COPage/classes/class.ilPCBlog.php");
6 require_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  {
68  $tpl = $this->tpl;
69 
70  $this->displayValidationError();
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  {
85  $tpl = $this->tpl;
86 
87  $this->displayValidationError();
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  {
105  $lng = $this->lng;
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  include_once "Modules/Blog/classes/class.ilBlogPosting.php";
118  $blogs_ids = ilBlogPosting::searchBlogsByAuthor($ilUser->getId());
119  if ($blogs_ids) {
120  foreach ($blogs_ids as $blog_id) {
121  $options[$blog_id] = ilObject::_lookupTitle($blog_id);
122  }
123  asort($options);
124  }
125  $obj = new ilSelectInputGUI($this->lng->txt("cont_pc_blog"), "blog");
126  $obj->setRequired(true);
127  $obj->setOptions($options);
128  $form->addItem($obj);
129 
130  if ($a_insert) {
131  $form->addCommandButton("create_blog", $this->lng->txt("select"));
132  $form->addCommandButton("cancelCreate", $this->lng->txt("cancel"));
133  } else {
134  $obj->setValue($this->content_obj->getBlogId());
135  $form->addCommandButton("update", $this->lng->txt("select"));
136  $form->addCommandButton("cancelUpdate", $this->lng->txt("cancel"));
137  }
138 
139  return $form;
140  }
141 
145  public function create()
146  {
147  if (!$_POST["blog_id"]) {
148  $form = $this->initForm(true);
149  if ($form->checkInput()) {
150  return $this->insertPosting($_POST["blog"]);
151  }
152 
153  $form->setValuesByPost();
154  return $this->insert($form);
155  } else {
156  $form = $this->initPostingForm($_POST["blog_id"], true);
157  if ($form->checkInput()) {
158  $this->content_obj = new ilPCBlog($this->getPage());
159  $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
160  $this->content_obj->setData($form->getInput("blog_id"), $form->getInput("posting"));
161  $this->updated = $this->pg_obj->update();
162  if ($this->updated === true) {
163  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
164  }
165  }
166 
167  $form->setValuesByPost();
168  return $this->insertPosting($_POST["blog_id"], $form);
169  }
170  }
171 
175  public function update()
176  {
177  if (!$_POST["blog_id"]) {
178  $form = $this->initForm();
179  if ($form->checkInput()) {
180  return $this->editPosting($_POST["blog"]);
181  }
182 
183  $this->pg_obj->addHierIDs();
184  $form->setValuesByPost();
185  return $this->edit($form);
186  } else {
187  $form = $this->initPostingForm($_POST["blog_id"]);
188  if ($form->checkInput()) {
189  $this->content_obj->setData($form->getInput("blog_id"), $form->getInput("posting"));
190  $this->updated = $this->pg_obj->update();
191  if ($this->updated === true) {
192  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
193  }
194  }
195 
196  $this->pg_obj->addHierIDs();
197  $form->setValuesByPost();
198  return $this->editPosting($_POST["blog_id"], $form);
199  }
200  }
201 
202 
209  public function insertPosting($a_blog_id, ilPropertyFormGUI $a_form = null)
210  {
211  $tpl = $this->tpl;
212 
213  $this->displayValidationError();
214 
215  if (!$a_form) {
216  $a_form = $this->initPostingForm($a_blog_id, true);
217  }
218  $tpl->setContent($a_form->getHTML());
219  }
220 
227  public function editPosting($a_blog_id, ilPropertyFormGUI $a_form = null)
228  {
229  $tpl = $this->tpl;
230 
231  $this->displayValidationError();
232 
233  if (!$a_form) {
234  $a_form = $this->initPostingForm($a_blog_id);
235  }
236  $tpl->setContent($a_form->getHTML());
237  }
238 
246  protected function initPostingForm($a_blog_id, $a_insert = false)
247  {
250 
251  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
252  $form = new ilPropertyFormGUI();
253  $form->setFormAction($ilCtrl->getFormAction($this));
254  if ($a_insert) {
255  $form->setTitle($this->lng->txt("cont_insert_blog"));
256  } else {
257  $form->setTitle($this->lng->txt("cont_update_blog"));
258  }
259 
260  $options = array();
261  include_once "Modules/Blog/classes/class.ilBlogPosting.php";
262  $postings = ilBlogPosting::getAllPostings($a_blog_id);
263  if ($postings) {
264  foreach ($postings as $post) {
265  // could be posting from someone else
266  if ($post["author"] == $ilUser->getId()) {
267  $date = new ilDateTime($post["date"], IL_CAL_DATETIME);
268  $title = $post["title"] . " - " .
270 
271  $cbox = new ilCheckboxInputGUI($title, "posting");
272  $cbox->setValue($post["id"]);
273 
274  $options[] = $cbox;
275  }
276  }
277  }
278  asort($options);
279  $obj = new ilCheckboxGroupInputGUI($this->lng->txt("cont_pc_blog_posting"), "posting");
280  $obj->setRequired(true);
281  $obj->setOptions($options);
282  $form->addItem($obj);
283 
284  $blog_id = new ilHiddenInputGUI("blog_id");
285  $blog_id->setValue($a_blog_id);
286  $form->addItem($blog_id);
287 
288  if ($a_insert) {
289  $form->addCommandButton("create_blog", $this->lng->txt("save"));
290  $form->addCommandButton("cancelCreate", $this->lng->txt("cancel"));
291  } else {
292  $obj->setValue($this->content_obj->getPostings());
293  $form->addCommandButton("update", $this->lng->txt("save"));
294  $form->addCommandButton("cancelUpdate", $this->lng->txt("cancel"));
295  }
296 
297  return $form;
298  }
299 }
editPosting($a_blog_id, ilPropertyFormGUI $a_form=null)
Edit blog posting form.
const IL_CAL_DATETIME
This class represents a selection list property in a property form.
This class represents a property form user interface.
global $DIC
Definition: saml.php:7
This class represents a checkbox property in a property form.
initPostingForm($a_blog_id, $a_insert=false)
Init blog posting form.
static _lookupTitle($a_id)
lookup object title
edit(ilPropertyFormGUI $a_form=null)
Edit blog form.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
initForm($a_insert=false)
Init blog form.
user()
Definition: user.php:4
global $ilCtrl
Definition: ilias.php:18
Class ilPCBlog.
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 hidden form property in a property form.
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
executeCommand()
execute command
Class ilPCBlogGUI.
if(isset($_POST['submit'])) $form
insert(ilPropertyFormGUI $a_form=null)
Insert blog form.
__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id="")
Constructor public.
displayValidationError()
display validation errors
$post
Definition: post.php:34
create()
Create new blog.
Date and time handling
$ilUser
Definition: imgupload.php:18
This class represents a property in a property form.
insertPosting($a_blog_id, ilPropertyFormGUI $a_form=null)
Insert new blog posting form.
$ret
Definition: parser.php:6
$_POST["username"]
setRequired($a_required)
Set Required.
update()
Update blog.