ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  function __construct()
38  {
39  parent::__construct();
40  include_once("./Services/Skill/classes/class.ilSkillTree.php");
41  $this->skill_tree = new ilSkillTree();
42  $this->skill_tree_root_id = $this->skill_tree->readRootId();
43 
44  $this->init_top_order_nr = $this->skill_tree->getMaxOrderNr($this->skill_tree_root_id);
45  $this->init_templ_top_order_nr = $this->skill_tree->getMaxOrderNr($this->skill_tree_root_id, true);
46  }
47 
53  function setMode($a_val)
54  {
55  $this->mode = $a_val;
56  }
57 
63  function getMode()
64  {
65  return $this->mode;
66  }
67 
73  function setSelectedNodes($a_val)
74  {
75  $this->selected_nodes = $a_val;
76  }
77 
83  function getSelectedNodes()
84  {
85  return $this->selected_nodes;
86  }
87 
93  function setSelectedProfiles($a_val)
94  {
95  $this->selected_profiles = $a_val;
96  }
97 
104  {
106  }
107 
113  public function getSupportedVersions()
114  {
115  return array("5.1.0");
116  }
117 
124  function getXmlNamespace($a_entity, $a_schema_version)
125  {
126  return "http://www.ilias.de/xml/Services/Skill/".$a_entity;
127  }
128 
135  protected function getTypes($a_entity, $a_version)
136  {
137  if ($a_entity == "skmg")
138  {
139  switch ($a_version)
140  {
141  case "5.1.0":
142  return array(
143  "Mode" => "text"
144  );
145  }
146  }
147  if ($a_entity == "skl_subtree")
148  {
149  switch ($a_version)
150  {
151  case "5.1.0":
152  return array(
153  "SklTreeId" => "integer",
154  "TopNode" => "integer",
155  "Child" => "integer",
156  "Parent" => "integer",
157  "Depth" => "integer",
158  "Type" => "text",
159  "Title" => "text",
160  "SelfEval" => "integer",
161  "OrderNr" => "integer",
162  "Status" => "integer",
163  "TemplateId" => "integer"
164  );
165  }
166  }
167  if ($a_entity == "skl_templ_subtree")
168  {
169  switch ($a_version)
170  {
171  case "5.1.0":
172  return array(
173  "SklTreeId" => "integer",
174  "TopNode" => "integer",
175  "Child" => "integer",
176  "Parent" => "integer",
177  "Depth" => "integer",
178  "Type" => "text",
179  "Title" => "text",
180  "SelfEval" => "integer",
181  "OrderNr" => "integer",
182  "Status" => "integer"
183  );
184  }
185  }
186  if ($a_entity == "skl_level")
187  {
188  switch ($a_version)
189  {
190  case "5.1.0":
191  return array(
192  "LevelId" => "integer",
193  "SkillId" => "integer",
194  "Nr" => "integer",
195  "Title" => "text",
196  "Description" => "text"
197  );
198  }
199  }
200  if ($a_entity == "skl_prof")
201  {
202  switch ($a_version)
203  {
204  case "5.1.0":
205  return array(
206  "Id" => "integer",
207  "Title" => "text",
208  "Description" => "text"
209  );
210  }
211  }
212  if ($a_entity == "skl_prof_level")
213  {
214  switch ($a_version)
215  {
216  case "5.1.0":
217  return array(
218  "ProfileId" => "integer",
219  "BaseSkillId" => "integer",
220  "TrefId" => "integer",
221  "LevelId" => "integer"
222  );
223  }
224  }
225  return array();
226  }
227 
234  function readData($a_entity, $a_version, $a_ids, $a_field = "")
235  {
236  global $ilDB;
237 
238  $this->data = array();
239 
240  if (!is_array($a_ids))
241  {
242  $a_ids = array($a_ids);
243  }
244  if ($a_entity == "skmg") // dummy node
245  {
246  switch ($a_version)
247  {
248  case "5.1.0":
249  if ($this->getMode() == self::MODE_SKILLS)
250  {
251  $this->data[] = array("Mode" => "Skills");
252  }
253  else if ($this->getMode() == self::MODE_PROFILES)
254  {
255  $this->data[] = array("Mode" => "Profiles");
256  }
257  break;
258 
259  }
260  }
261  if ($a_entity == "skl_subtree") // get subtree for top node
262  {
263  switch ($a_version)
264  {
265  case "5.1.0":
266  foreach ($a_ids as $id)
267  {
268  $sub = $this->skill_tree->getSubTree($this->skill_tree->getNodeData($id));
269  foreach ($sub as $s)
270  {
271  $set = $ilDB->query("SELECT * FROM skl_templ_ref ".
272  " WHERE skl_node_id = ".$ilDB->quote($s["child"], "integer")
273  );
274  $rec = $ilDB->fetchAssoc($set);
275 
276  $top_node = ($s["child"] == $id)
277  ? 1
278  : 0;
279  $this->data[] = array(
280  "SklTreeId" => $s["skl_tree_id"],
281  "TopNode" => $top_node,
282  "Child" => $s["child"],
283  "Parent" => $s["parent"],
284  "Depth" => $s["depth"],
285  "Type" => $s["type"],
286  "Title" => $s["title"],
287  "SelfEval" => $s["self_eval"],
288  "OrderNr" => $s["order_nr"],
289  "Status" => $s["status"],
290  "TemplateId" => (int) $rec["templ_id"]
291  );
292  }
293  }
294  break;
295 
296  }
297  }
298 
299  if ($a_entity == "skl_templ_subtree") // get template subtree for template id
300  {
301  switch ($a_version)
302  {
303  case "5.1.0":
304  foreach ($a_ids as $id)
305  {
306  $sub = $this->skill_tree->getSubTree($this->skill_tree->getNodeData($id));
307  foreach ($sub as $s)
308  {
309  $top_node = ($s["child"] == $id)
310  ? 1
311  : 0;
312  $this->data[] = array(
313  "SklTreeId" => $s["skl_tree_id"],
314  "TopNode" => $top_node,
315  "Child" => $s["child"],
316  "Parent" => $s["parent"],
317  "Depth" => $s["depth"],
318  "Type" => $s["type"],
319  "Title" => $s["title"],
320  "SelfEval" => $s["self_eval"],
321  "OrderNr" => $s["order_nr"],
322  "Status" => $s["status"]
323  );
324  }
325  }
326  break;
327 
328  }
329  }
330 
331  if ($a_entity == "skl_level")
332  {
333  switch ($a_version)
334  {
335  case "5.1.0":
336  $this->getDirectDataFromQuery("SELECT id level_id, skill_id, nr, title, description".
337  " FROM skl_level WHERE ".
338  $ilDB->in("skill_id", $a_ids, false, "integer")." ORDER BY skill_id ASC, nr ASC");
339  break;
340 
341  }
342  }
343 
344  if ($a_entity == "skl_prof")
345  {
346  switch ($a_version)
347  {
348  case "5.1.0":
349  $this->getDirectDataFromQuery("SELECT id, title, description".
350  " FROM skl_profile WHERE ".
351  $ilDB->in("id", $a_ids, false, "integer"));
352  break;
353 
354  }
355  }
356 
357  if ($a_entity == "skl_prof_level")
358  {
359  switch ($a_version)
360  {
361  case "5.1.0":
362  $this->getDirectDataFromQuery("SELECT profile_id, base_skill_id, tref_id, level_id".
363  " FROM skl_profile_level WHERE ".
364  $ilDB->in("profile_id", $a_ids, false, "integer"));
365  break;
366 
367  }
368  }
369 
370  }
371 
375  protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
376  {
377  global $ilDB;
378 
379  include_once("./Services/Skill/classes/class.ilSkillTreeNode.php");
380 
381  switch ($a_entity)
382  {
383  case "skmg":
384 
385  if ($this->getMode() == self::MODE_SKILLS)
386  {
387  // determine top nodes of main tree to be exported and all referenced template nodes
388  $sel_nodes = $this->getSelectedNodes();
389  $exp_types = array("skll", "scat", "sctr", "sktr");
390  if (!is_array($sel_nodes))
391  {
392  $childs = $this->skill_tree->getChildsByTypeFilter($this->skill_tree->readRootId(), $exp_types);
393  $deps = array();
394  $skl_subtree_deps = array();
395  foreach ($childs as $c)
396  {
397  $skl_subtree_deps[] = $c["child"];
398  }
399  } else
400  {
401  foreach ($sel_nodes as $n)
402  {
403  if (in_array(ilSkillTreeNode::_lookupType((int)$n), $exp_types))
404  {
405  $skl_subtree_deps[] = $n;
406  }
407  }
408  }
409 
410  // determine template subtrees
411  $ref_nodes = array();
412  if (is_array($skl_subtree_deps))
413  {
414  foreach ($skl_subtree_deps as $id)
415  {
416  if (ilSkillTreeNode::_lookupType($id) == "sktr")
417  {
418  $ref_nodes[$id] = $id;
419  } else
420  {
421  $sub = $this->skill_tree->getSubTree($this->skill_tree->getNodeData($id), true, "sktr");
422  foreach ($sub as $s)
423  {
424  $ref_nodes[$s["child"]] = $s["child"];
425  }
426  }
427  }
428  }
429 
430  $set = $ilDB->query("SELECT DISTINCT(templ_id) FROM skl_templ_ref " .
431  " WHERE " . $ilDB->in("skl_node_id", $ref_nodes, false, "integer"));
432  while ($rec = $ilDB->fetchAssoc($set))
433  {
434  $deps["skl_templ_subtree"]["ids"][] = $rec["templ_id"];
435  }
436 
437  // export subtree after templates
438  $deps["skl_subtree"]["ids"] = $skl_subtree_deps;
439  }
440  else if ($this->getMode() == self::MODE_PROFILES)
441  {
442  foreach ($this->getSelectedProfiles() as $p_id)
443  {
444  $deps["skl_prof"]["ids"][] = $p_id;
445  }
446  }
447 
448  return $deps;
449 
450  case "skl_subtree":
451  case "skl_templ_subtree":
452  $deps = array();
453  if (in_array($a_rec["Type"], array("skll", "sktp")))
454  {
455  $deps["skl_level"]["ids"][] = $a_rec["Child"];
456  }
457  return $deps;
458 
459  case "skl_prof":
460  $deps["skl_prof_level"]["ids"][] = $a_rec["Id"];
461  return $deps;
462  }
463 
464  return false;
465  }
466 
467 
474  function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
475  {
476  $source_inst_id = $a_mapping->getInstallId();
477  switch ($a_entity)
478  {
479  case "skl_subtree":
480  if ($a_rec["TopNode"] == 1)
481  {
482  $parent = $this->skill_tree_root_id;
484  $order = $a_rec["OrderNr"] + $this->init_top_order_nr;
485  } else
486  {
487  $parent = (int)$a_mapping->getMapping("Services/Skill", "skl_tree", $a_rec["Parent"]);
488  $status = $a_rec["Status"];
489  $order = $a_rec["OrderNr"];
490  }
491  switch ($a_rec["Type"])
492  {
493  case "scat":
494  include_once("./Services/Skill/classes/class.ilSkillCategory.php");
495  $scat = new ilSkillCategory();
496  $scat->setTitle($a_rec["Title"]);
497  $scat->setImportId("il_" . $source_inst_id . "_scat_" . $a_rec["Child"]);
498  $scat->setSelfEvaluation($a_rec["SelfEval"]);
499  $scat->setOrderNr($order);
500  $scat->setStatus($status);
501  $scat->create();
502  ilSkillTreeNode::putInTree($scat, $parent);
503  $a_mapping->addMapping("Services/Skill", "skl_tree", $a_rec["Child"], $scat->getId());
504  break;
505 
506  case "skll":
507  include_once("./Services/Skill/classes/class.ilBasicSkill.php");
508  $skll = new ilBasicSkill();
509  $skll->setTitle($a_rec["Title"]);
510  $skll->setImportId("il_" . $source_inst_id . "_skll_" . $a_rec["Child"]);
511  $skll->setSelfEvaluation($a_rec["SelfEval"]);
512  $skll->setOrderNr($order);
513  $skll->setStatus($status);
514  $skll->create();
515  ilSkillTreeNode::putInTree($skll, $parent);
516  $a_mapping->addMapping("Services/Skill", "skl_tree", $a_rec["Child"], $skll->getId());
517  break;
518 
519  case "sktr":
520  $template_id = (int)$a_mapping->getMapping("Services/Skill", "skl_tree", $a_rec["TemplateId"]);
521  // only create template references, if referenced template is found (template trees are imported first)
522  if ($template_id > 0)
523  {
524  include_once("./Services/Skill/classes/class.ilSkillTemplateReference.php");
525  $sktr = new ilSkillTemplateReference();
526  $sktr->setTitle($a_rec["Title"]);
527  $sktr->setImportId("il_" . $source_inst_id . "_sktr_" . $a_rec["Child"]);
528  $sktr->setSelfEvaluation($a_rec["SelfEval"]);
529  $sktr->setOrderNr($order);
530  $sktr->setSkillTemplateId($template_id);
531  $sktr->setStatus($status);
532  $sktr->create();
533  ilSkillTreeNode::putInTree($sktr, $parent);
534  $a_mapping->addMapping("Services/Skill", "skl_tree", $a_rec["Child"], $sktr->getId());
535  }
536  break;
537 
538  }
539  break;
540 
541  case "skl_templ_subtree":
542  if ($a_rec["TopNode"] == 1)
543  {
544  $parent = $this->skill_tree_root_id;
545  $order = $a_rec["OrderNr"] + $this->init_templ_top_order_nr;
546  } else
547  {
548  $parent = (int)$a_mapping->getMapping("Services/Skill", "skl_tree", $a_rec["Parent"]);
549  $order = $a_rec["OrderNr"];
550  }
551  switch ($a_rec["Type"])
552  {
553  case "sctp":
554  include_once("./Services/Skill/classes/class.ilSkillTemplateCategory.php");
555  $sctp = new ilSkillTemplateCategory();
556  $sctp->setTitle($a_rec["Title"]);
557  $sctp->setImportId("il_" . $source_inst_id . "_sctp_" . $a_rec["Child"]);
558  $sctp->setOrderNr($order);
559  $sctp->create();
560  ilSkillTreeNode::putInTree($sctp, $parent);
561  $a_mapping->addMapping("Services/Skill", "skl_tree", $a_rec["Child"], $sctp->getId());
562  break;
563 
564  case "sktp":
565  include_once("./Services/Skill/classes/class.ilBasicSkillTemplate.php");
566  $sktp = new ilBasicSkillTemplate();
567  $sktp->setTitle($a_rec["Title"]);
568  $sktp->setImportId("il_" . $source_inst_id . "_sktp_" . $a_rec["Child"]);
569  $sktp->setOrderNr($order);
570  $sktp->create();
571  ilSkillTreeNode::putInTree($sktp, $parent);
572  $a_mapping->addMapping("Services/Skill", "skl_tree", $a_rec["Child"], $sktp->getId());
573  break;
574  }
575  break;
576 
577  case "skl_level":
578  $skill_id = (int)$a_mapping->getMapping("Services/Skill", "skl_tree", $a_rec["SkillId"]);
579  $type = ilSkillTreeNode::_lookupType($skill_id);
580  if (in_array($type, array("skll", "sktp")))
581  {
582  if ($type == "skll")
583  {
584  $skill = new ilBasicSkill($skill_id);
585  } else
586  {
587  $skill = new ilBasicSkillTemplate($skill_id);
588  }
589  $skill->addLevel($a_rec["Title"], $a_rec["Description"], "il_" . $source_inst_id . "_sklv_" . $a_rec["LevelId"]);
590  $skill->update();
591  }
592  break;
593 
594  case "skl_prof":
595  include_once("./Services/Skill/classes/class.ilSkillProfile.php");
596  $prof = new ilSkillProfile();
597  $prof->setTitle($a_rec["Title"]);
598  $prof->setDescription($a_rec["Description"]);
599  $prof->create();
600  $a_mapping->addMapping("Services/Skill", "skl_prof", $a_rec["Id"], $prof->getId());
601  break;
602 
603  case "skl_prof_level":
604  $profile_id = (int)$a_mapping->getMapping("Services/Skill", "skl_prof", $a_rec["ProfileId"]);
605  if ($profile_id > 0)
606  {
607  include_once("./Services/Skill/classes/class.ilSkillProfile.php");
608  include_once("./Services/Skill/classes/class.ilBasicSkill.php");
609  $prof = new ilSkillProfile($profile_id);
610  $level_id_data = ilBasicSkill::getLevelIdForImportId($this->getCurrentInstallationId(), $a_rec["LevelId"]);
611  $skill_data = ilBasicSkill::getCommonSkillIdForImportId($this->getCurrentInstallationId(), $a_rec["BaseSkillId"], $a_rec["TrefId"]);
612  //var_dump($level_id_data);
613  //var_dump($skill_data);
614  $level_id = $tref_id = $base_skill = 0;
615  foreach($level_id_data as $l)
616  {
617  reset($skill_data);
618  foreach ($skill_data as $s)
619  {
620  // echo "<br>=".ilBasicSkill::lookupLevelSkillId($l["level_id"])."=".$s["skill_id"]."=";
621 
622  if ($level_id == 0 && ilBasicSkill::lookupLevelSkillId($l["level_id"]) == $s["skill_id"])
623  {
624  $level_id = $l["level_id"];
625  $base_skill = $s["skill_id"];
626  $tref_id = $s["tref_id"];
627  }
628  }
629  }
630  if ($level_id > 0)
631  {
632  $prof->addSkillLevel($base_skill, $tref_id, $level_id);
633  }
634  $prof->update();
635  }
636  break;
637  }
638  }
639 }
640 ?>
getSelectedNodes()
Get export selected nodes.
Add some data
setSelectedNodes($a_val)
Set export selected nodes.
$template_id
Definition: example_062.php:89
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.
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.
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:80
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.
static getCommonSkillIdForImportId($a_source_inst_id, $a_skill_import_id, $a_tref_import_id=0)
Get common skill ids for import IDs (newest first)