ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilPCBlog.php
Go to the documentation of this file.
1 <?php
2 
25 class ilPCBlog extends ilPageContent
26 {
28  protected ilObjUser $user;
29 
30  public function init(): void
31  {
32  global $DIC;
33 
34  $this->user = $DIC->user();
35  $this->setType("blog");
36  }
37 
38  public function setNode(php4DOMElement $a_node): void
39  {
40  parent::setNode($a_node); // this is the PageContent node
41  $this->blog_node = $a_node->first_child(); // this is the blog node
42  }
43 
44  public function create(
45  ilPageObject $a_pg_obj,
46  string $a_hier_id,
47  string $a_pc_id = ""
48  ): void {
49  $this->node = $this->createPageContentNode();
50  $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
51  $this->blog_node = $this->dom->create_element("Blog");
52  $this->blog_node = $this->node->append_child($this->blog_node);
53  }
54 
58  public function setData(
59  int $a_blog_id,
60  array $a_posting_ids = null
61  ): void {
63 
64  $this->blog_node->set_attribute("Id", $a_blog_id);
65  $this->blog_node->set_attribute("User", $ilUser->getId());
66 
67  // remove all children first
68  $children = $this->blog_node->child_nodes();
69  if ($children) {
70  foreach ($children as $child) {
71  $this->blog_node->remove_child($child);
72  }
73  }
74 
75  if (count($a_posting_ids)) {
76  foreach ($a_posting_ids as $posting_id) {
77  $post_node = $this->dom->create_element("BlogPosting");
78  $post_node = $this->blog_node->append_child($post_node);
79  $post_node->set_attribute("Id", $posting_id);
80  }
81  }
82  }
83 
84  public function getBlogId(): int
85  {
86  if (is_object($this->blog_node)) {
87  return (int) $this->blog_node->get_attribute("Id");
88  }
89  return 0;
90  }
91 
95  public function getPostings(): array
96  {
97  $res = array();
98  if (is_object($this->blog_node)) {
99  $children = $this->blog_node->child_nodes();
100  if ($children) {
101  foreach ($children as $child) {
102  $res[] = (int) $child->get_attribute("Id");
103  }
104  }
105  }
106  return $res;
107  }
108 }
setType(string $a_type)
Set Type.
$res
Definition: ltiservices.php:69
php4DOMElement $blog_node
ilObjUser $user
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
create(ilPageObject $a_pg_obj, string $a_hier_id, string $a_pc_id="")
php4DomElement
insertContent(ilPageContent $a_cont_obj, string $a_pos, int $a_mode=IL_INSERT_AFTER, string $a_pcid="", bool $remove_placeholder=true)
insert a content node before/after a sibling or as first child of a parent
setNode(php4DOMElement $a_node)
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
const IL_INSERT_AFTER
createPageContentNode(bool $a_set_this_node=true)
Create page content node (always use this method first when adding a new element) ...
getPostings()
Get blog postings.
$ilUser
Definition: imgupload.php:34
setData(int $a_blog_id, array $a_posting_ids=null)
Set blog settings.