ILIAS  release_8 Revision v8.24
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 {
56 $ilUser = $this->user;
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 {
89 ilPageContentUsage::deleteAllUsages(
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}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
const IL_INSERT_AFTER
User class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static deleteHistoryLowerEqualThan(string $parent_type, int $page_id, string $lang, int $delete_lower_than_nr)
Overwrite in derived classes, if old history entries are being deleted.
static saveSkillUsage(ilPageObject $a_page, DOMDocument $a_domdoc, int $a_old_nr=0)
init()
Init object.
php4DOMElement $skill_node
setData(string $a_skill_id)
create(ilPageObject $a_pg_obj, string $a_hier_id, string $a_pc_id="")
ilObjUser $user
static collectSkills(ilPageObject $a_page, DOMDocument $a_domdoc)
setNode(php4DOMElement $a_node)
Set xml node of page content.
static afterPageUpdate(ilPageObject $a_page, DOMDocument $a_domdoc, string $a_xml, bool $a_creation)
After page has been updated (or created)
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 beforePageDelete(ilPageObject $a_page)
Before page is being deleted.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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="-")
static deleteAllUsages(string $a_pc_type, 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...
createPageContentNode(bool $a_set_this_node=true)
Create page content node (always use this method first when adding a new element)
setType(string $a_type)
Set Type.
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
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
global $DIC
Definition: feed.php:28
$ilUser
Definition: imgupload.php:34
$lang
Definition: xapiexit.php:26