ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPCSkills.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 
6 require_once("./Services/COPage/classes/class.ilPageContent.php");
7 
19 {
20  var $dom;
21 
25  function init()
26  {
27  $this->setType("skills");
28  }
29 
33  function setNode(&$a_node)
34  {
35  parent::setNode($a_node); // this is the PageContent node
36  $this->skill_node =& $a_node->first_child(); // this is the skill node
37  }
38 
45  function create(&$a_pg_obj, $a_hier_id, $a_pc_id = "")
46  {
47  $this->node = $this->createPageContentNode();
48  $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
49  $this->skill_node = $this->dom->create_element("Skills");
50  $this->skill_node = $this->node->append_child($this->skill_node);
51  }
52 
58  function setData($a_skill_id)
59  {
60  global $ilUser;
61 
62  $this->skill_node->set_attribute("Id", $a_skill_id);
63  $this->skill_node->set_attribute("User", $ilUser->getId());
64  }
65 
71  function getSkillId()
72  {
73  if (is_object($this->skill_node))
74  {
75  return $this->skill_node->get_attribute("Id");
76  }
77  }
78 
87  static function afterPageUpdate($a_page, DOMDocument $a_domdoc, $a_xml, $a_creation)
88  {
89  // pc skill
90  self::saveSkillUsage($a_page, $a_domdoc);
91  }
92 
98  static function beforePageDelete($a_page)
99  {
100  ilPageContentUsage::deleteAllUsages("skmg", $a_page->getParentType().":pg", $a_page->getId(), false,
101  $a_page->getLanguage());
102  }
103 
112  static function afterPageHistoryEntry($a_page, DOMDocument $a_old_domdoc, $a_old_xml, $a_old_nr)
113  {
114  self::saveSkillUsage($a_page, $a_old_domdoc, $a_old_nr);
115  }
116 
120  static function saveSkillUsage($a_page, $a_domdoc, $a_old_nr = 0)
121  {
122  include_once("./Services/COPage/classes/class.ilPageContentUsage.php");
123  $skl_ids = self::collectSkills($a_page, $a_domdoc);
124  ilPageContentUsage::deleteAllUsages("skmg", $a_page->getParentType().":pg", $a_page->getId(), $a_old_nr,
125  $a_page->getLanguage());
126  foreach($skl_ids as $skl_id)
127  {
128  if ((int) $skl_id["inst_id"] <= 0)
129  {
130  ilPageContentUsage::saveUsage("skmg", $skl_id["id"], $a_page->getParentType().":pg", $a_page->getId(), $a_old_nr,
131  $a_page->getLanguage());
132  }
133  }
134  }
135 
139  static function collectSkills($a_page, $a_domdoc)
140  {
141  $xpath = new DOMXPath($a_domdoc);
142  $nodes = $xpath->query('//Skills');
143 
144  $skl_ids = array();
145  foreach($nodes as $node)
146  {
147  $user = $node->getAttribute("User");
148  $id = $node->getAttribute("Id");
149  $inst_id = $node->getAttribute("InstId");
150  $skl_ids[$user.":".$id.":".$inst_id] = array(
151  "user" => $user, "id" => $id, "inst_id" => $inst_id);
152  }
153 
154  return $skl_ids;
155  }
156 
157 
158 }
159 ?>