ILIAS  trunk Revision v11.0_alpha-1713-gd8962da2f67
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilPCSkills.php
Go to the documentation of this file.
1 <?php
2 
25 {
26  protected ilObjUser $user;
27 
28  public function init(): void
29  {
30  global $DIC;
31 
32  $this->user = $DIC->user();
33  $this->setType("skills");
34  }
35 
36  public function create(
37  ilPageObject $a_pg_obj,
38  string $a_hier_id,
39  string $a_pc_id = ""
40  ): void {
41  $this->createInitialChildNode($a_hier_id, $a_pc_id, "Skills");
42  }
43 
44  public function setData(string $a_skill_id): void
45  {
46  $ilUser = $this->user;
47  $this->getChildNode()->setAttribute("Id", $a_skill_id);
48  $this->getChildNode()->setAttribute("User", $ilUser->getId());
49  }
50 
51  public function getSkillId(): string
52  {
53  if (is_object($this->getChildNode())) {
54  return $this->getChildNode()->getAttribute("Id");
55  }
56  return "";
57  }
58 
62  public static function afterPageUpdate(
63  ilPageObject $a_page,
64  DOMDocument $a_domdoc,
65  string $a_xml,
66  bool $a_creation
67  ): void {
68  // pc skill
69  self::saveSkillUsage($a_page, $a_domdoc);
70  }
71 
75  public static function beforePageDelete(
76  ilPageObject $a_page
77  ): void {
79  "skmg",
80  $a_page->getParentType() . ":pg",
81  $a_page->getId(),
82  0,
83  $a_page->getLanguage()
84  );
85  }
86 
90  public static function afterPageHistoryEntry(
91  ilPageObject $a_page,
92  DOMDocument $a_old_domdoc,
93  string $a_old_xml,
94  int $a_old_nr
95  ): void {
96  self::saveSkillUsage($a_page, $a_old_domdoc, $a_old_nr);
97  }
98 
99  public static function saveSkillUsage(
100  ilPageObject $a_page,
101  DOMDocument $a_domdoc,
102  int $a_old_nr = 0
103  ): void {
104  $skl_ids = self::collectSkills($a_page, $a_domdoc);
106  "skmg",
107  $a_page->getParentType() . ":pg",
108  $a_page->getId(),
109  $a_old_nr,
110  $a_page->getLanguage()
111  );
112  foreach ($skl_ids as $skl_id) {
113  if ((int) $skl_id["inst_id"] <= 0) {
115  "skmg",
116  $skl_id["id"],
117  $a_page->getParentType() . ":pg",
118  $a_page->getId(),
119  $a_old_nr,
120  $a_page->getLanguage()
121  );
122  }
123  }
124  }
125 
126  public static function collectSkills(
127  ilPageObject $a_page,
128  DOMDocument $a_domdoc
129  ): array {
130  $xpath = new DOMXPath($a_domdoc);
131  $nodes = $xpath->query('//Skills');
132 
133  $skl_ids = array();
134  foreach ($nodes as $node) {
135  $user = $node->getAttribute("User");
136  $id = $node->getAttribute("Id");
137  $inst_id = $node->getAttribute("InstId");
138  $skl_ids[$user . ":" . $id . ":" . $inst_id] = array(
139  "user" => $user, "id" => $id, "inst_id" => $inst_id);
140  }
141 
142  return $skl_ids;
143  }
144 
145  public static function deleteHistoryLowerEqualThan(
146  string $parent_type,
147  int $page_id,
148  string $lang,
149  int $delete_lower_than_nr
150  ): void {
151  global $DIC;
152 
153  $usage_repo = $DIC->copage()
154  ->internal()
155  ->repo()
156  ->usage();
157 
158  $usage_repo->deleteHistoryUsagesLowerEqualThan(
159  "skmg",
160  $parent_type . ":pg",
161  $page_id,
162  $delete_lower_than_nr,
163  $lang
164  );
165  }
166 }
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="-")
Content object of ilPageObject (see ILIAS DTD).
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...
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
global $DIC
Definition: shib_login.php:22
static deleteHistoryLowerEqualThan(string $parent_type, int $page_id, string $lang, int $delete_lower_than_nr)
setData(string $a_skill_id)
$lang
Definition: xapiexit.php:25
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="")
$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)
createInitialChildNode(string $hier_id, string $pc_id, string $child, array $child_attributes=[])