ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 {
23  protected $user;
24 
25  public $dom;
26 
30  public function init()
31  {
32  global $DIC;
33 
34  $this->user = $DIC->user();
35  $this->setType("skills");
36  }
37 
41  public function setNode($a_node)
42  {
43  parent::setNode($a_node); // this is the PageContent node
44  $this->skill_node = $a_node->first_child(); // this is the skill node
45  }
46 
53  public function create(&$a_pg_obj, $a_hier_id, $a_pc_id = "")
54  {
55  $this->node = $this->createPageContentNode();
56  $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
57  $this->skill_node = $this->dom->create_element("Skills");
58  $this->skill_node = $this->node->append_child($this->skill_node);
59  }
60 
66  public function setData($a_skill_id)
67  {
69 
70  $this->skill_node->set_attribute("Id", $a_skill_id);
71  $this->skill_node->set_attribute("User", $ilUser->getId());
72  }
73 
79  public function getSkillId()
80  {
81  if (is_object($this->skill_node)) {
82  return $this->skill_node->get_attribute("Id");
83  }
84  }
85 
94  public static function afterPageUpdate($a_page, DOMDocument $a_domdoc, $a_xml, $a_creation)
95  {
96  // pc skill
97  self::saveSkillUsage($a_page, $a_domdoc);
98  }
99 
105  public static function beforePageDelete($a_page)
106  {
107  require_once('Services/COPage/classes/class.ilPageContentUsage.php'); // Mantis #18636
109  "skmg",
110  $a_page->getParentType() . ":pg",
111  $a_page->getId(),
112  false,
113  $a_page->getLanguage()
114  );
115  }
116 
125  public static function afterPageHistoryEntry($a_page, DOMDocument $a_old_domdoc, $a_old_xml, $a_old_nr)
126  {
127  self::saveSkillUsage($a_page, $a_old_domdoc, $a_old_nr);
128  }
129 
133  public static function saveSkillUsage($a_page, $a_domdoc, $a_old_nr = 0)
134  {
135  include_once("./Services/COPage/classes/class.ilPageContentUsage.php");
136  $skl_ids = self::collectSkills($a_page, $a_domdoc);
138  "skmg",
139  $a_page->getParentType() . ":pg",
140  $a_page->getId(),
141  $a_old_nr,
142  $a_page->getLanguage()
143  );
144  foreach ($skl_ids as $skl_id) {
145  if ((int) $skl_id["inst_id"] <= 0) {
147  "skmg",
148  $skl_id["id"],
149  $a_page->getParentType() . ":pg",
150  $a_page->getId(),
151  $a_old_nr,
152  $a_page->getLanguage()
153  );
154  }
155  }
156  }
157 
161  public static function collectSkills($a_page, $a_domdoc)
162  {
163  $xpath = new DOMXPath($a_domdoc);
164  $nodes = $xpath->query('//Skills');
165 
166  $skl_ids = array();
167  foreach ($nodes as $node) {
168  $user = $node->getAttribute("User");
169  $id = $node->getAttribute("Id");
170  $inst_id = $node->getAttribute("InstId");
171  $skl_ids[$user . ":" . $id . ":" . $inst_id] = array(
172  "user" => $user, "id" => $id, "inst_id" => $inst_id);
173  }
174 
175  return $skl_ids;
176  }
177 }
create(&$a_pg_obj, $a_hier_id, $a_pc_id="")
Create skill node in xml.
static afterPageUpdate($a_page, DOMDocument $a_domdoc, $a_xml, $a_creation)
After page has been updated (or created)
global $DIC
Definition: saml.php:7
static afterPageHistoryEntry($a_page, DOMDocument $a_old_domdoc, $a_old_xml, $a_old_nr)
After page history entry has been created.
if(!array_key_exists('StateId', $_REQUEST)) $id
static collectSkills($a_page, $a_domdoc)
get all content includes that are used within the page
setType($a_type)
Set Type.
user()
Definition: user.php:4
Class ilPageContent.
static beforePageDelete($a_page)
Before page is being deleted.
Class ilPCSkills.
static saveSkillUsage($a_page, $a_domdoc, $a_old_nr=0)
save content include usages
$ilUser
Definition: imgupload.php:18
const IL_INSERT_AFTER
Create styles array
The data for the language used.
static deleteAllUsages($a_pc_type, $a_usage_type, $a_usage_id, $a_usage_hist_nr=0, $a_lang="-")
Delete all usages.
createPageContentNode($a_set_this_node=true)
Create page content node (always use this method first when adding a new element) ...
setData($a_skill_id)
Set skill settings.
init()
Init page content component.
static saveUsage($a_pc_type, $a_pc_id, $a_usage_type, $a_usage_id, $a_usage_hist_nr=0, $a_lang="-")
Save usages.
setNode($a_node)
Set node.
getSkillId()
Get skill mode.