ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
4include_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();
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 {
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 "Description" => "text",
160 "SelfEval" => "integer",
161 "OrderNr" => "integer",
162 "Status" => "integer",
163 "TemplateId" => "integer"
164 );
165 }
166 }
167 if ($a_entity == "skl_templ_subtree") {
168 switch ($a_version) {
169 case "5.1.0":
170 return array(
171 "SklTreeId" => "integer",
172 "TopNode" => "integer",
173 "Child" => "integer",
174 "Parent" => "integer",
175 "Depth" => "integer",
176 "Type" => "text",
177 "Title" => "text",
178 "Description" => "text",
179 "SelfEval" => "integer",
180 "OrderNr" => "integer",
181 "Status" => "integer"
182 );
183 }
184 }
185 if ($a_entity == "skl_level") {
186 switch ($a_version) {
187 case "5.1.0":
188 return array(
189 "LevelId" => "integer",
190 "SkillId" => "integer",
191 "Nr" => "integer",
192 "Title" => "text",
193 "Description" => "text"
194 );
195 }
196 }
197 if ($a_entity == "skl_prof") {
198 switch ($a_version) {
199 case "5.1.0":
200 return array(
201 "Id" => "integer",
202 "Title" => "text",
203 "Description" => "text"
204 );
205 }
206 }
207 if ($a_entity == "skl_prof_level") {
208 switch ($a_version) {
209 case "5.1.0":
210 return array(
211 "ProfileId" => "integer",
212 "BaseSkillId" => "integer",
213 "TrefId" => "integer",
214 "LevelId" => "integer"
215 );
216 }
217 }
218 return array();
219 }
220
227 public function readData($a_entity, $a_version, $a_ids, $a_field = "")
228 {
230
231 $this->data = array();
232
233 if (!is_array($a_ids)) {
234 $a_ids = array($a_ids);
235 }
236 if ($a_entity == "skmg") { // dummy node
237 switch ($a_version) {
238 case "5.1.0":
239 if ($this->getMode() == self::MODE_SKILLS) {
240 $this->data[] = array("Mode" => "Skills");
241 } elseif ($this->getMode() == self::MODE_PROFILES) {
242 $this->data[] = array("Mode" => "Profiles");
243 }
244 break;
245
246 }
247 }
248 if ($a_entity == "skl_subtree") { // get subtree for top node
249 switch ($a_version) {
250 case "5.1.0":
251 foreach ($a_ids as $id) {
252 $sub = $this->skill_tree->getSubTree($this->skill_tree->getNodeData($id));
253 foreach ($sub as $s) {
254 $set = $ilDB->query(
255 "SELECT * FROM skl_templ_ref " .
256 " WHERE skl_node_id = " . $ilDB->quote($s["child"], "integer")
257 );
258 $rec = $ilDB->fetchAssoc($set);
259
260 $top_node = ($s["child"] == $id)
261 ? 1
262 : 0;
263 $this->data[] = array(
264 "SklTreeId" => $s["skl_tree_id"],
265 "TopNode" => $top_node,
266 "Child" => $s["child"],
267 "Parent" => $s["parent"],
268 "Depth" => $s["depth"],
269 "Type" => $s["type"],
270 "Title" => $s["title"],
271 "Description" => $s["description"],
272 "SelfEval" => $s["self_eval"],
273 "OrderNr" => $s["order_nr"],
274 "Status" => $s["status"],
275 "TemplateId" => (int) $rec["templ_id"]
276 );
277 }
278 }
279 break;
280
281 }
282 }
283
284 if ($a_entity == "skl_templ_subtree") { // get template subtree for template id
285 switch ($a_version) {
286 case "5.1.0":
287 foreach ($a_ids as $id) {
288 $sub = $this->skill_tree->getSubTree($this->skill_tree->getNodeData($id));
289 foreach ($sub as $s) {
290 $top_node = ($s["child"] == $id)
291 ? 1
292 : 0;
293 $this->data[] = array(
294 "SklTreeId" => $s["skl_tree_id"],
295 "TopNode" => $top_node,
296 "Child" => $s["child"],
297 "Parent" => $s["parent"],
298 "Depth" => $s["depth"],
299 "Type" => $s["type"],
300 "Title" => $s["title"],
301 "Description" => $s["description"],
302 "SelfEval" => $s["self_eval"],
303 "OrderNr" => $s["order_nr"],
304 "Status" => $s["status"]
305 );
306 }
307 }
308 break;
309
310 }
311 }
312
313 if ($a_entity == "skl_level") {
314 switch ($a_version) {
315 case "5.1.0":
316 $this->getDirectDataFromQuery("SELECT id level_id, skill_id, nr, title, description" .
317 " FROM skl_level WHERE " .
318 $ilDB->in("skill_id", $a_ids, false, "integer") . " ORDER BY skill_id ASC, nr ASC");
319 break;
320
321 }
322 }
323
324 if ($a_entity == "skl_prof") {
325 switch ($a_version) {
326 case "5.1.0":
327 $this->getDirectDataFromQuery("SELECT id, title, description" .
328 " FROM skl_profile WHERE " .
329 $ilDB->in("id", $a_ids, false, "integer"));
330 break;
331
332 }
333 }
334
335 if ($a_entity == "skl_prof_level") {
336 switch ($a_version) {
337 case "5.1.0":
338 $this->getDirectDataFromQuery("SELECT profile_id, base_skill_id, tref_id, level_id" .
339 " FROM skl_profile_level WHERE " .
340 $ilDB->in("profile_id", $a_ids, false, "integer"));
341 break;
342
343 }
344 }
345 }
346
350 protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
351 {
353
354 include_once("./Services/Skill/classes/class.ilSkillTreeNode.php");
355
356 switch ($a_entity) {
357 case "skmg":
358
359 if ($this->getMode() == self::MODE_SKILLS) {
360 // determine top nodes of main tree to be exported and all referenced template nodes
361 $sel_nodes = $this->getSelectedNodes();
362 $exp_types = array("skll", "scat", "sctr", "sktr");
363 if (!is_array($sel_nodes)) {
364 $childs = $this->skill_tree->getChildsByTypeFilter($this->skill_tree->readRootId(), $exp_types);
365 $deps = array();
366 $skl_subtree_deps = array();
367 foreach ($childs as $c) {
368 $skl_subtree_deps[] = $c["child"];
369 }
370 } else {
371 foreach ($sel_nodes as $n) {
372 if (in_array(ilSkillTreeNode::_lookupType((int) $n), $exp_types)) {
373 $skl_subtree_deps[] = $n;
374 }
375 }
376 }
377
378 // determine template subtrees
379 $ref_nodes = array();
380 if (is_array($skl_subtree_deps)) {
381 foreach ($skl_subtree_deps as $id) {
382 if (ilSkillTreeNode::_lookupType($id) == "sktr") {
383 $ref_nodes[$id] = $id;
384 } else {
385 $sub = $this->skill_tree->getSubTree($this->skill_tree->getNodeData($id), true, "sktr");
386 foreach ($sub as $s) {
387 $ref_nodes[$s["child"]] = $s["child"];
388 }
389 }
390 }
391 }
392
393 $set = $ilDB->query("SELECT DISTINCT(templ_id) FROM skl_templ_ref " .
394 " WHERE " . $ilDB->in("skl_node_id", $ref_nodes, false, "integer"));
395 while ($rec = $ilDB->fetchAssoc($set)) {
396 $deps["skl_templ_subtree"]["ids"][] = $rec["templ_id"];
397 }
398
399 // export subtree after templates
400 $deps["skl_subtree"]["ids"] = $skl_subtree_deps;
401 } elseif ($this->getMode() == self::MODE_PROFILES) {
402 foreach ($this->getSelectedProfiles() as $p_id) {
403 $deps["skl_prof"]["ids"][] = $p_id;
404 }
405 }
406
407 return $deps;
408
409 case "skl_subtree":
410 case "skl_templ_subtree":
411 $deps = array();
412 if (in_array($a_rec["Type"], array("skll", "sktp"))) {
413 $deps["skl_level"]["ids"][] = $a_rec["Child"];
414 }
415 return $deps;
416
417 case "skl_prof":
418 $deps["skl_prof_level"]["ids"][] = $a_rec["Id"];
419 return $deps;
420 }
421
422 return false;
423 }
424
425
432 public function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
433 {
434 $source_inst_id = $a_mapping->getInstallId();
435 switch ($a_entity) {
436 case "skl_subtree":
437 if ($a_rec["TopNode"] == 1) {
438 $parent = $this->skill_tree_root_id;
440 $order = $a_rec["OrderNr"] + $this->init_top_order_nr;
441 } else {
442 $parent = (int) $a_mapping->getMapping("Services/Skill", "skl_tree", $a_rec["Parent"]);
443 $status = $a_rec["Status"];
444 $order = $a_rec["OrderNr"];
445 }
446 switch ($a_rec["Type"]) {
447 case "scat":
448 include_once("./Services/Skill/classes/class.ilSkillCategory.php");
449 $scat = new ilSkillCategory();
450 $scat->setTitle($a_rec["Title"]);
451 $scat->setDescription($a_rec["Description"]);
452 $scat->setImportId("il_" . $source_inst_id . "_scat_" . $a_rec["Child"]);
453 $scat->setSelfEvaluation($a_rec["SelfEval"]);
454 $scat->setOrderNr($order);
455 $scat->setStatus($status);
456 $scat->create();
457 ilSkillTreeNode::putInTree($scat, $parent);
458 $a_mapping->addMapping("Services/Skill", "skl_tree", $a_rec["Child"], $scat->getId());
459 break;
460
461 case "skll":
462 include_once("./Services/Skill/classes/class.ilBasicSkill.php");
463 $skll = new ilBasicSkill();
464 $skll->setTitle($a_rec["Title"]);
465 $skll->setDescription($a_rec["Description"]);
466 $skll->setImportId("il_" . $source_inst_id . "_skll_" . $a_rec["Child"]);
467 $skll->setSelfEvaluation($a_rec["SelfEval"]);
468 $skll->setOrderNr($order);
469 $skll->setStatus($status);
470 $skll->create();
471 ilSkillTreeNode::putInTree($skll, $parent);
472 $a_mapping->addMapping("Services/Skill", "skl_tree", $a_rec["Child"], $skll->getId());
473 break;
474
475 case "sktr":
476 $template_id = (int) $a_mapping->getMapping("Services/Skill", "skl_tree", $a_rec["TemplateId"]);
477 // only create template references, if referenced template is found (template trees are imported first)
478 if ($template_id > 0) {
479 include_once("./Services/Skill/classes/class.ilSkillTemplateReference.php");
480 $sktr = new ilSkillTemplateReference();
481 $sktr->setTitle($a_rec["Title"]);
482 $sktr->setDescription($a_rec["Description"]);
483 $sktr->setImportId("il_" . $source_inst_id . "_sktr_" . $a_rec["Child"]);
484 $sktr->setSelfEvaluation($a_rec["SelfEval"]);
485 $sktr->setOrderNr($order);
486 $sktr->setSkillTemplateId($template_id);
487 $sktr->setStatus($status);
488 $sktr->create();
489 ilSkillTreeNode::putInTree($sktr, $parent);
490 $a_mapping->addMapping("Services/Skill", "skl_tree", $a_rec["Child"], $sktr->getId());
491 }
492 break;
493
494 }
495 break;
496
497 case "skl_templ_subtree":
498 if ($a_rec["TopNode"] == 1) {
499 $parent = $this->skill_tree_root_id;
500 $order = $a_rec["OrderNr"] + $this->init_templ_top_order_nr;
501 } else {
502 $parent = (int) $a_mapping->getMapping("Services/Skill", "skl_tree", $a_rec["Parent"]);
503 $order = $a_rec["OrderNr"];
504 }
505 switch ($a_rec["Type"]) {
506 case "sctp":
507 include_once("./Services/Skill/classes/class.ilSkillTemplateCategory.php");
508 $sctp = new ilSkillTemplateCategory();
509 $sctp->setTitle($a_rec["Title"]);
510 $sctp->setDescription($a_rec["Description"]);
511 $sctp->setImportId("il_" . $source_inst_id . "_sctp_" . $a_rec["Child"]);
512 $sctp->setOrderNr($order);
513 $sctp->create();
514 ilSkillTreeNode::putInTree($sctp, $parent);
515 $a_mapping->addMapping("Services/Skill", "skl_tree", $a_rec["Child"], $sctp->getId());
516 break;
517
518 case "sktp":
519 include_once("./Services/Skill/classes/class.ilBasicSkillTemplate.php");
520 $sktp = new ilBasicSkillTemplate();
521 $sktp->setTitle($a_rec["Title"]);
522 $sktp->setDescription($a_rec["Description"]);
523 $sktp->setImportId("il_" . $source_inst_id . "_sktp_" . $a_rec["Child"]);
524 $sktp->setOrderNr($order);
525 $sktp->create();
526 ilSkillTreeNode::putInTree($sktp, $parent);
527 $a_mapping->addMapping("Services/Skill", "skl_tree", $a_rec["Child"], $sktp->getId());
528 break;
529 }
530 break;
531
532 case "skl_level":
533 $skill_id = (int) $a_mapping->getMapping("Services/Skill", "skl_tree", $a_rec["SkillId"]);
535 if (in_array($type, array("skll", "sktp"))) {
536 if ($type == "skll") {
537 $skill = new ilBasicSkill($skill_id);
538 } else {
539 $skill = new ilBasicSkillTemplate($skill_id);
540 }
541 $skill->addLevel($a_rec["Title"], $a_rec["Description"], "il_" . $source_inst_id . "_sklv_" . $a_rec["LevelId"]);
542 $skill->update();
543 }
544 break;
545
546 case "skl_prof":
547 include_once("./Services/Skill/classes/class.ilSkillProfile.php");
548 $prof = new ilSkillProfile();
549 $prof->setTitle($a_rec["Title"]);
550 $prof->setDescription($a_rec["Description"]);
551 $prof->create();
552 $a_mapping->addMapping("Services/Skill", "skl_prof", $a_rec["Id"], $prof->getId());
553 break;
554
555 case "skl_prof_level":
556 $profile_id = (int) $a_mapping->getMapping("Services/Skill", "skl_prof", $a_rec["ProfileId"]);
557 if ($profile_id > 0) {
558 include_once("./Services/Skill/classes/class.ilSkillProfile.php");
559 include_once("./Services/Skill/classes/class.ilBasicSkill.php");
560 $prof = new ilSkillProfile($profile_id);
561 $level_id_data = ilBasicSkill::getLevelIdForImportId($this->getCurrentInstallationId(), $a_rec["LevelId"]);
562 $skill_data = ilBasicSkill::getCommonSkillIdForImportId($this->getCurrentInstallationId(), $a_rec["BaseSkillId"], $a_rec["TrefId"]);
563 //var_dump($level_id_data);
564 //var_dump($skill_data);
565 $level_id = $tref_id = $base_skill = 0;
566 foreach ($level_id_data as $l) {
567 reset($skill_data);
568 foreach ($skill_data as $s) {
569 // echo "<br>=".ilBasicSkill::lookupLevelSkillId($l["level_id"])."=".$s["skill_id"]."=";
570
571 if ($level_id == 0 && ilBasicSkill::lookupLevelSkillId($l["level_id"]) == $s["skill_id"]) {
572 $level_id = $l["level_id"];
573 $base_skill = $s["skill_id"];
574 $tref_id = $s["tref_id"];
575 }
576 }
577 }
578 if ($level_id > 0) {
579 $prof->addSkillLevel($base_skill, $tref_id, $level_id);
580 }
581 $prof->update();
582 }
583 break;
584 }
585 }
586}
$n
Definition: RandomTest.php:85
An exception for terminatinating execution or to throw for unit testing.
static getCommonSkillIdForImportId($a_source_inst_id, $a_skill_import_id, $a_tref_import_id=0)
Get common skill ids for import IDs (newest first)
static lookupLevelSkillId($a_id)
Lookup level skill id.
static getLevelIdForImportId($a_source_inst_id, $a_level_import_id)
Get level ids for import IDs (newest first)
A dataset contains in data in a common structure that can be shared and transformed for different pur...
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 ...
getCurrentInstallationId()
Get current installation id.
Skill Data set class.
importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
Import record.
__construct()
Constructor.
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.
setSelectedNodes($a_val)
Set export selected nodes.
setMode($a_val)
Set mode.
getXmlNamespace($a_entity, $a_schema_version)
Get xml namespace.
getSelectedNodes()
Get export selected nodes.
getTypes($a_entity, $a_version)
Get field types for entity.
getSelectedProfiles()
Get selected profiles.
getSupportedVersions()
Get supported versions.
setSelectedProfiles($a_val)
Set selected profiles.
static putInTree($a_obj, $a_parent_id="", $a_target_node_id="")
Put this object into the skill tree.
static _lookupType($a_obj_id)
Lookup Type.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$type
global $ilDB
$DIC
Definition: xapitoken.php:46