ILIAS  release_8 Revision v8.23
class.ilPCSkills.php
Go to the documentation of this file.
1 <?php
2 
25 {
27  protected ilObjUser $user;
28 
29  public function init(): void
30  {
31  global $DIC;
32 
33  $this->user = $DIC->user();
34  $this->setType("skills");
35  }
36 
37  public function setNode(php4DOMElement $a_node): void
38  {
39  parent::setNode($a_node); // this is the PageContent node
40  $this->skill_node = $a_node->first_child(); // this is the skill node
41  }
42 
43  public function create(
44  ilPageObject $a_pg_obj,
45  string $a_hier_id,
46  string $a_pc_id = ""
47  ): void {
48  $this->node = $this->createPageContentNode();
49  $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
50  $this->skill_node = $this->dom->create_element("Skills");
51  $this->skill_node = $this->node->append_child($this->skill_node);
52  }
53 
54  public function setData(string $a_skill_id): void
55  {
57 
58  $this->skill_node->set_attribute("Id", $a_skill_id);
59  $this->skill_node->set_attribute("User", $ilUser->getId());
60  }
61 
62  public function getSkillId(): string
63  {
64  if (is_object($this->skill_node)) {
65  return $this->skill_node->get_attribute("Id");
66  }
67  return "";
68  }
69 
73  public static function afterPageUpdate(
74  ilPageObject $a_page,
75  DOMDocument $a_domdoc,
76  string $a_xml,
77  bool $a_creation
78  ): void {
79  // pc skill
80  self::saveSkillUsage($a_page, $a_domdoc);
81  }
82 
86  public static function beforePageDelete(
87  ilPageObject $a_page
88  ): void {
90  "skmg",
91  $a_page->getParentType() . ":pg",
92  $a_page->getId(),
93  0,
94  $a_page->getLanguage()
95  );
96  }
97 
101  public static function afterPageHistoryEntry(
102  ilPageObject $a_page,
103  DOMDocument $a_old_domdoc,
104  string $a_old_xml,
105  int $a_old_nr
106  ): void {
107  self::saveSkillUsage($a_page, $a_old_domdoc, $a_old_nr);
108  }
109 
110  public static function saveSkillUsage(
111  ilPageObject $a_page,
112  DOMDocument $a_domdoc,
113  int $a_old_nr = 0
114  ): void {
115  $skl_ids = self::collectSkills($a_page, $a_domdoc);
117  "skmg",
118  $a_page->getParentType() . ":pg",
119  $a_page->getId(),
120  $a_old_nr,
121  $a_page->getLanguage()
122  );
123  foreach ($skl_ids as $skl_id) {
124  if ((int) $skl_id["inst_id"] <= 0) {
126  "skmg",
127  $skl_id["id"],
128  $a_page->getParentType() . ":pg",
129  $a_page->getId(),
130  $a_old_nr,
131  $a_page->getLanguage()
132  );
133  }
134  }
135  }
136 
137  public static function collectSkills(
138  ilPageObject $a_page,
139  DOMDocument $a_domdoc
140  ): array {
141  $xpath = new DOMXPath($a_domdoc);
142  $nodes = $xpath->query('//Skills');
143 
144  $skl_ids = array();
145  foreach ($nodes as $node) {
146  $user = $node->getAttribute("User");
147  $id = $node->getAttribute("Id");
148  $inst_id = $node->getAttribute("InstId");
149  $skl_ids[$user . ":" . $id . ":" . $inst_id] = array(
150  "user" => $user, "id" => $id, "inst_id" => $inst_id);
151  }
152 
153  return $skl_ids;
154  }
155 
156  public static function deleteHistoryLowerEqualThan(
157  string $parent_type,
158  int $page_id,
159  string $lang,
160  int $delete_lower_than_nr
161  ): void {
162  global $DIC;
163 
164  $usage_repo = $DIC->copage()
165  ->internal()
166  ->repo()
167  ->usage();
168 
169  $usage_repo->deleteHistoryUsagesLowerEqualThan(
170  "skmg",
171  $parent_type . ":pg",
172  $page_id,
173  $delete_lower_than_nr,
174  $lang
175  );
176  }
177 }
setNode(php4DOMElement $a_node)
php4DOMElement $node
setType(string $a_type)
Set Type.
static afterPageUpdate(ilPageObject $a_page, DOMDocument $a_domdoc, string $a_xml, bool $a_creation)
After page has been updated (or created)
ilObjUser $user
static saveUsage(string $a_pc_type, int $a_pc_id, string $a_usage_type, int $a_usage_id, int $a_usage_hist_nr=0, string $a_lang="-")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
php4DomElement
static deleteAllUsages(string $a_pc_type, string $a_usage_type, int $a_usage_id, int $a_usage_hist_nr=0, string $a_lang="-")
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
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
static deleteHistoryLowerEqualThan(string $parent_type, int $page_id, string $lang, int $delete_lower_than_nr)
setData(string $a_skill_id)
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) ...
$lang
Definition: xapiexit.php:26
static beforePageDelete(ilPageObject $a_page)
Before page is being deleted.
static saveSkillUsage(ilPageObject $a_page, DOMDocument $a_domdoc, int $a_old_nr=0)
create(ilPageObject $a_pg_obj, string $a_hier_id, string $a_pc_id="")
$ilUser
Definition: imgupload.php:34
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static afterPageHistoryEntry(ilPageObject $a_page, DOMDocument $a_old_domdoc, string $a_old_xml, int $a_old_nr)
After page history entry has been created.
static collectSkills(ilPageObject $a_page, DOMDocument $a_domdoc)
php4DOMElement $skill_node