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