ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilSkillDataSet.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/DataSet/classes/class.ilDataSet.php");
5 
21 {
22  const MODE_SKILLS = "";
23  const MODE_PROFILES = "prof";
24 
28  protected $skill_tree;
29  protected $init_order_nr;
30  protected $selected_nodes = false;
31  protected $selected_profiles = false;
32  protected $mode = "";
33 
37  public function __construct()
38  {
39  global $DIC;
40 
41  $this->db = $DIC->database();
42  parent::__construct();
43  include_once("./Services/Skill/classes/class.ilSkillTree.php");
44  $this->skill_tree = new ilSkillTree();
45  $this->skill_tree_root_id = $this->skill_tree->readRootId();
46 
47  $this->init_top_order_nr = $this->skill_tree->getMaxOrderNr($this->skill_tree_root_id);
48  $this->init_templ_top_order_nr = $this->skill_tree->getMaxOrderNr($this->skill_tree_root_id, true);
49  }
50 
56  public function setMode($a_val)
57  {
58  $this->mode = $a_val;
59  }
60 
66  public function getMode()
67  {
68  return $this->mode;
69  }
70 
76  public function setSelectedNodes($a_val)
77  {
78  $this->selected_nodes = $a_val;
79  }
80 
86  public function getSelectedNodes()
87  {
88  return $this->selected_nodes;
89  }
90 
96  public function setSelectedProfiles($a_val)
97  {
98  $this->selected_profiles = $a_val;
99  }
100 
106  public function getSelectedProfiles()
107  {
109  }
110 
116  public function getSupportedVersions()
117  {
118  return array("5.1.0");
119  }
120 
127  public function getXmlNamespace($a_entity, $a_schema_version)
128  {
129  return "http://www.ilias.de/xml/Services/Skill/" . $a_entity;
130  }
131 
138  protected function getTypes($a_entity, $a_version)
139  {
140  if ($a_entity == "skmg") {
141  switch ($a_version) {
142  case "5.1.0":
143  return array(
144  "Mode" => "text"
145  );
146  }
147  }
148  if ($a_entity == "skl_subtree") {
149  switch ($a_version) {
150  case "5.1.0":
151  return array(
152  "SklTreeId" => "integer",
153  "TopNode" => "integer",
154  "Child" => "integer",
155  "Parent" => "integer",
156  "Depth" => "integer",
157  "Type" => "text",
158  "Title" => "text",
159  "SelfEval" => "integer",
160  "OrderNr" => "integer",
161  "Status" => "integer",
162  "TemplateId" => "integer"
163  );
164  }
165  }
166  if ($a_entity == "skl_templ_subtree") {
167  switch ($a_version) {
168  case "5.1.0":
169  return array(
170  "SklTreeId" => "integer",
171  "TopNode" => "integer",
172  "Child" => "integer",
173  "Parent" => "integer",
174  "Depth" => "integer",
175  "Type" => "text",
176  "Title" => "text",
177  "SelfEval" => "integer",
178  "OrderNr" => "integer",
179  "Status" => "integer"
180  );
181  }
182  }
183  if ($a_entity == "skl_level") {
184  switch ($a_version) {
185  case "5.1.0":
186  return array(
187  "LevelId" => "integer",
188  "SkillId" => "integer",
189  "Nr" => "integer",
190  "Title" => "text",
191  "Description" => "text"
192  );
193  }
194  }
195  if ($a_entity == "skl_prof") {
196  switch ($a_version) {
197  case "5.1.0":
198  return array(
199  "Id" => "integer",
200  "Title" => "text",
201  "Description" => "text"
202  );
203  }
204  }
205  if ($a_entity == "skl_prof_level") {
206  switch ($a_version) {
207  case "5.1.0":
208  return array(
209  "ProfileId" => "integer",
210  "BaseSkillId" => "integer",
211  "TrefId" => "integer",
212  "LevelId" => "integer"
213  );
214  }
215  }
216  return array();
217  }
218 
225  public function readData($a_entity, $a_version, $a_ids, $a_field = "")
226  {
227  $ilDB = $this->db;
228 
229  $this->data = array();
230 
231  if (!is_array($a_ids)) {
232  $a_ids = array($a_ids);
233  }
234  if ($a_entity == "skmg") { // dummy node
235  switch ($a_version) {
236  case "5.1.0":
237  if ($this->getMode() == self::MODE_SKILLS) {
238  $this->data[] = array("Mode" => "Skills");
239  } elseif ($this->getMode() == self::MODE_PROFILES) {
240  $this->data[] = array("Mode" => "Profiles");
241  }
242  break;
243 
244  }
245  }
246  if ($a_entity == "skl_subtree") { // get subtree for top node
247  switch ($a_version) {
248  case "5.1.0":
249  foreach ($a_ids as $id) {
250  $sub = $this->skill_tree->getSubTree($this->skill_tree->getNodeData($id));
251  foreach ($sub as $s) {
252  $set = $ilDB->query(
253  "SELECT * FROM skl_templ_ref " .
254  " WHERE skl_node_id = " . $ilDB->quote($s["child"], "integer")
255  );
256  $rec = $ilDB->fetchAssoc($set);
257 
258  $top_node = ($s["child"] == $id)
259  ? 1
260  : 0;
261  $this->data[] = array(
262  "SklTreeId" => $s["skl_tree_id"],
263  "TopNode" => $top_node,
264  "Child" => $s["child"],
265  "Parent" => $s["parent"],
266  "Depth" => $s["depth"],
267  "Type" => $s["type"],
268  "Title" => $s["title"],
269  "SelfEval" => $s["self_eval"],
270  "OrderNr" => $s["order_nr"],
271  "Status" => $s["status"],
272  "TemplateId" => (int) $rec["templ_id"]
273  );
274  }
275  }
276  break;
277 
278  }
279  }
280 
281  if ($a_entity == "skl_templ_subtree") { // get template subtree for template id
282  switch ($a_version) {
283  case "5.1.0":
284  foreach ($a_ids as $id) {
285  $sub = $this->skill_tree->getSubTree($this->skill_tree->getNodeData($id));
286  foreach ($sub as $s) {
287  $top_node = ($s["child"] == $id)
288  ? 1
289  : 0;
290  $this->data[] = array(
291  "SklTreeId" => $s["skl_tree_id"],
292  "TopNode" => $top_node,
293  "Child" => $s["child"],
294  "Parent" => $s["parent"],
295  "Depth" => $s["depth"],
296  "Type" => $s["type"],
297  "Title" => $s["title"],
298  "SelfEval" => $s["self_eval"],
299  "OrderNr" => $s["order_nr"],
300  "Status" => $s["status"]
301  );
302  }
303  }
304  break;
305 
306  }
307  }
308 
309  if ($a_entity == "skl_level") {
310  switch ($a_version) {
311  case "5.1.0":
312  $this->getDirectDataFromQuery("SELECT id level_id, skill_id, nr, title, description" .
313  " FROM skl_level WHERE " .
314  $ilDB->in("skill_id", $a_ids, false, "integer") . " ORDER BY skill_id ASC, nr ASC");
315  break;
316 
317  }
318  }
319 
320  if ($a_entity == "skl_prof") {
321  switch ($a_version) {
322  case "5.1.0":
323  $this->getDirectDataFromQuery("SELECT id, title, description" .
324  " FROM skl_profile WHERE " .
325  $ilDB->in("id", $a_ids, false, "integer"));
326  break;
327 
328  }
329  }
330 
331  if ($a_entity == "skl_prof_level") {
332  switch ($a_version) {
333  case "5.1.0":
334  $this->getDirectDataFromQuery("SELECT profile_id, base_skill_id, tref_id, level_id" .
335  " FROM skl_profile_level WHERE " .
336  $ilDB->in("profile_id", $a_ids, false, "integer"));
337  break;
338 
339  }
340  }
341  }
342 
346  protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
347  {
348  $ilDB = $this->db;
349 
350  include_once("./Services/Skill/classes/class.ilSkillTreeNode.php");
351 
352  switch ($a_entity) {
353  case "skmg":
354 
355  if ($this->getMode() == self::MODE_SKILLS) {
356  // determine top nodes of main tree to be exported and all referenced template nodes
357  $sel_nodes = $this->getSelectedNodes();
358  $exp_types = array("skll", "scat", "sctr", "sktr");
359  if (!is_array($sel_nodes)) {
360  $childs = $this->skill_tree->getChildsByTypeFilter($this->skill_tree->readRootId(), $exp_types);
361  $deps = array();
362  $skl_subtree_deps = array();
363  foreach ($childs as $c) {
364  $skl_subtree_deps[] = $c["child"];
365  }
366  } else {
367  foreach ($sel_nodes as $n) {
368  if (in_array(ilSkillTreeNode::_lookupType((int) $n), $exp_types)) {
369  $skl_subtree_deps[] = $n;
370  }
371  }
372  }
373 
374  // determine template subtrees
375  $ref_nodes = array();
376  if (is_array($skl_subtree_deps)) {
377  foreach ($skl_subtree_deps as $id) {
378  if (ilSkillTreeNode::_lookupType($id) == "sktr") {
379  $ref_nodes[$id] = $id;
380  } else {
381  $sub = $this->skill_tree->getSubTree($this->skill_tree->getNodeData($id), true, "sktr");
382  foreach ($sub as $s) {
383  $ref_nodes[$s["child"]] = $s["child"];
384  }
385  }
386  }
387  }
388 
389  $set = $ilDB->query("SELECT DISTINCT(templ_id) FROM skl_templ_ref " .
390  " WHERE " . $ilDB->in("skl_node_id", $ref_nodes, false, "integer"));
391  while ($rec = $ilDB->fetchAssoc($set)) {
392  $deps["skl_templ_subtree"]["ids"][] = $rec["templ_id"];
393  }
394 
395  // export subtree after templates
396  $deps["skl_subtree"]["ids"] = $skl_subtree_deps;
397  } elseif ($this->getMode() == self::MODE_PROFILES) {
398  foreach ($this->getSelectedProfiles() as $p_id) {
399  $deps["skl_prof"]["ids"][] = $p_id;
400  }
401  }
402 
403  return $deps;
404 
405  case "skl_subtree":
406  case "skl_templ_subtree":
407  $deps = array();
408  if (in_array($a_rec["Type"], array("skll", "sktp"))) {
409  $deps["skl_level"]["ids"][] = $a_rec["Child"];
410  }
411  return $deps;
412 
413  case "skl_prof":
414  $deps["skl_prof_level"]["ids"][] = $a_rec["Id"];
415  return $deps;
416  }
417 
418  return false;
419  }
420 
421 
428  public function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
429  {
430  $source_inst_id = $a_mapping->getInstallId();
431  switch ($a_entity) {
432  case "skl_subtree":
433  if ($a_rec["TopNode"] == 1) {
434  $parent = $this->skill_tree_root_id;
436  $order = $a_rec["OrderNr"] + $this->init_top_order_nr;
437  } else {
438  $parent = (int) $a_mapping->getMapping("Services/Skill", "skl_tree", $a_rec["Parent"]);
439  $status = $a_rec["Status"];
440  $order = $a_rec["OrderNr"];
441  }
442  switch ($a_rec["Type"]) {
443  case "scat":
444  include_once("./Services/Skill/classes/class.ilSkillCategory.php");
445  $scat = new ilSkillCategory();
446  $scat->setTitle($a_rec["Title"]);
447  $scat->setImportId("il_" . $source_inst_id . "_scat_" . $a_rec["Child"]);
448  $scat->setSelfEvaluation($a_rec["SelfEval"]);
449  $scat->setOrderNr($order);
450  $scat->setStatus($status);
451  $scat->create();
452  ilSkillTreeNode::putInTree($scat, $parent);
453  $a_mapping->addMapping("Services/Skill", "skl_tree", $a_rec["Child"], $scat->getId());
454  break;
455 
456  case "skll":
457  include_once("./Services/Skill/classes/class.ilBasicSkill.php");
458  $skll = new ilBasicSkill();
459  $skll->setTitle($a_rec["Title"]);
460  $skll->setImportId("il_" . $source_inst_id . "_skll_" . $a_rec["Child"]);
461  $skll->setSelfEvaluation($a_rec["SelfEval"]);
462  $skll->setOrderNr($order);
463  $skll->setStatus($status);
464  $skll->create();
465  ilSkillTreeNode::putInTree($skll, $parent);
466  $a_mapping->addMapping("Services/Skill", "skl_tree", $a_rec["Child"], $skll->getId());
467  break;
468 
469  case "sktr":
470  $template_id = (int) $a_mapping->getMapping("Services/Skill", "skl_tree", $a_rec["TemplateId"]);
471  // only create template references, if referenced template is found (template trees are imported first)
472  if ($template_id > 0) {
473  include_once("./Services/Skill/classes/class.ilSkillTemplateReference.php");
474  $sktr = new ilSkillTemplateReference();
475  $sktr->setTitle($a_rec["Title"]);
476  $sktr->setImportId("il_" . $source_inst_id . "_sktr_" . $a_rec["Child"]);
477  $sktr->setSelfEvaluation($a_rec["SelfEval"]);
478  $sktr->setOrderNr($order);
479  $sktr->setSkillTemplateId($template_id);
480  $sktr->setStatus($status);
481  $sktr->create();
482  ilSkillTreeNode::putInTree($sktr, $parent);
483  $a_mapping->addMapping("Services/Skill", "skl_tree", $a_rec["Child"], $sktr->getId());
484  }
485  break;
486 
487  }
488  break;
489 
490  case "skl_templ_subtree":
491  if ($a_rec["TopNode"] == 1) {
492  $parent = $this->skill_tree_root_id;
493  $order = $a_rec["OrderNr"] + $this->init_templ_top_order_nr;
494  } else {
495  $parent = (int) $a_mapping->getMapping("Services/Skill", "skl_tree", $a_rec["Parent"]);
496  $order = $a_rec["OrderNr"];
497  }
498  switch ($a_rec["Type"]) {
499  case "sctp":
500  include_once("./Services/Skill/classes/class.ilSkillTemplateCategory.php");
501  $sctp = new ilSkillTemplateCategory();
502  $sctp->setTitle($a_rec["Title"]);
503  $sctp->setImportId("il_" . $source_inst_id . "_sctp_" . $a_rec["Child"]);
504  $sctp->setOrderNr($order);
505  $sctp->create();
506  ilSkillTreeNode::putInTree($sctp, $parent);
507  $a_mapping->addMapping("Services/Skill", "skl_tree", $a_rec["Child"], $sctp->getId());
508  break;
509 
510  case "sktp":
511  include_once("./Services/Skill/classes/class.ilBasicSkillTemplate.php");
512  $sktp = new ilBasicSkillTemplate();
513  $sktp->setTitle($a_rec["Title"]);
514  $sktp->setImportId("il_" . $source_inst_id . "_sktp_" . $a_rec["Child"]);
515  $sktp->setOrderNr($order);
516  $sktp->create();
517  ilSkillTreeNode::putInTree($sktp, $parent);
518  $a_mapping->addMapping("Services/Skill", "skl_tree", $a_rec["Child"], $sktp->getId());
519  break;
520  }
521  break;
522 
523  case "skl_level":
524  $skill_id = (int) $a_mapping->getMapping("Services/Skill", "skl_tree", $a_rec["SkillId"]);
525  $type = ilSkillTreeNode::_lookupType($skill_id);
526  if (in_array($type, array("skll", "sktp"))) {
527  if ($type == "skll") {
528  $skill = new ilBasicSkill($skill_id);
529  } else {
530  $skill = new ilBasicSkillTemplate($skill_id);
531  }
532  $skill->addLevel($a_rec["Title"], $a_rec["Description"], "il_" . $source_inst_id . "_sklv_" . $a_rec["LevelId"]);
533  $skill->update();
534  }
535  break;
536 
537  case "skl_prof":
538  include_once("./Services/Skill/classes/class.ilSkillProfile.php");
539  $prof = new ilSkillProfile();
540  $prof->setTitle($a_rec["Title"]);
541  $prof->setDescription($a_rec["Description"]);
542  $prof->create();
543  $a_mapping->addMapping("Services/Skill", "skl_prof", $a_rec["Id"], $prof->getId());
544  break;
545 
546  case "skl_prof_level":
547  $profile_id = (int) $a_mapping->getMapping("Services/Skill", "skl_prof", $a_rec["ProfileId"]);
548  if ($profile_id > 0) {
549  include_once("./Services/Skill/classes/class.ilSkillProfile.php");
550  include_once("./Services/Skill/classes/class.ilBasicSkill.php");
551  $prof = new ilSkillProfile($profile_id);
552  $level_id_data = ilBasicSkill::getLevelIdForImportId($this->getCurrentInstallationId(), $a_rec["LevelId"]);
553  $skill_data = ilBasicSkill::getCommonSkillIdForImportId($this->getCurrentInstallationId(), $a_rec["BaseSkillId"], $a_rec["TrefId"]);
554  //var_dump($level_id_data);
555  //var_dump($skill_data);
556  $level_id = $tref_id = $base_skill = 0;
557  foreach ($level_id_data as $l) {
558  reset($skill_data);
559  foreach ($skill_data as $s) {
560  // echo "<br>=".ilBasicSkill::lookupLevelSkillId($l["level_id"])."=".$s["skill_id"]."=";
561 
562  if ($level_id == 0 && ilBasicSkill::lookupLevelSkillId($l["level_id"]) == $s["skill_id"]) {
563  $level_id = $l["level_id"];
564  $base_skill = $s["skill_id"];
565  $tref_id = $s["tref_id"];
566  }
567  }
568  }
569  if ($level_id > 0) {
570  $prof->addSkillLevel($base_skill, $tref_id, $level_id);
571  }
572  $prof->update();
573  }
574  break;
575  }
576  }
577 }
getSelectedNodes()
Get export selected nodes.
Add some data
setSelectedNodes($a_val)
Set export selected nodes.
Skill Data set class.
getDirectDataFromQuery($a_query, $a_convert_to_leading_upper=true, $a_set=true)
Get data from query.This is a standard procedure, all db field names are directly mapped to abstract ...
__construct()
Constructor.
$type
global $DIC
Definition: saml.php:7
Skill tree.
static getLevelIdForImportId($a_source_inst_id, $a_level_import_id)
Get level ids for import IDs (newest first)
getXmlNamespace($a_entity, $a_schema_version)
Get xml namespace.
static putInTree($a_obj, $a_parent_id="", $a_target_node_id="")
Put this object into the skill tree.
getSupportedVersions()
Get supported versions.
if(!array_key_exists('StateId', $_REQUEST)) $id
$s
Definition: pwgen.php:45
static _lookupType($a_obj_id)
Lookup Type.
getDependencies($a_entity, $a_version, $a_rec, $a_ids)
Determine the dependent sets of data.
readData($a_entity, $a_version, $a_ids, $a_field="")
Read data.
getCurrentInstallationId()
Get current installation id.
$n
Definition: RandomTest.php:85
Create styles array
The data for the language used.
setSelectedProfiles($a_val)
Set selected profiles.
setMode($a_val)
Set mode.
getSelectedProfiles()
Get selected profiles.
global $l
Definition: afr.php:30
global $ilDB
importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
Import record.
static lookupLevelSkillId($a_id)
Lookup level skill id.
A dataset contains in data in a common structure that can be shared and transformed for different pur...
Basic Skill.
getTypes($a_entity, $a_version)
Get field types for entity.
$template_id
static getCommonSkillIdForImportId($a_source_inst_id, $a_skill_import_id, $a_tref_import_id=0)
Get common skill ids for import IDs (newest first)