ILIAS  release_8 Revision v8.24
class.SkillTreeManager.php
Go to the documentation of this file.
1<?php
2
20namespace ILIAS\Skill\Tree;
21
25
31{
32 protected \ilCtrl $ctrl;
33 protected \ilErrorHandling $error;
34 protected \ilLanguage $lng;
35 protected int $skmg_ref_id = 0;
36 protected \ilTree $repository_tree;
41 protected int $requested_ref_id = 0;
42
43 public function __construct(
44 int $skmg_ref_id,
47 ) {
48 global $DIC;
49
50 $this->ctrl = $DIC->ctrl();
51 $this->error = $DIC["ilErr"];
52 $this->lng = $DIC->language();
53 $this->skmg_ref_id = $skmg_ref_id;
54 $this->repository_tree = $repository_tree;
55 $this->tree_factory = $tree_factory;
56 $this->admin_gui_request = $DIC->skills()->internal()->gui()->admin_request();
57
58 // TODO: Find a different way for the ref_id, because this is no GUI class
59 $this->requested_ref_id = $this->admin_gui_request->getRefId();
60
61 $this->tree_access_manager = $DIC->skills()->internal()->manager()->getTreeAccessManager($this->requested_ref_id);
62 $this->management_access_manager = $DIC->skills()->internal()->manager()->getManagementAccessManager($this->requested_ref_id);
63 }
64
65 public function createTree(string $title, string $description): void
66 {
67 if (!$this->management_access_manager->hasCreateTreePermission()) {
68 $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
69 }
70 $tree_obj = new \ilObjSkillTree();
71 $tree_obj->setTitle($title);
72 $tree_obj->setDescription($description);
73 $tree_obj->create();
74 $tree_obj->createReference();
75 $tree_obj->putInTree($this->skmg_ref_id);
76 $tree_obj->setPermissions($this->skmg_ref_id);
77
78 $tree = $this->tree_factory->getTreeById($tree_obj->getId());
79 $root_node = new \ilSkillRoot();
80 $root_node->setTitle("Skill Tree Root Node");
81 $root_node->create();
82 $tree->addTree($tree_obj->getId(), $root_node->getId());
83 $this->ctrl->setParameterByClass("ilobjskilltreegui", "ref_id", $tree_obj->getRefId());
84 $this->ctrl->setParameterByClass("ilobjskilltreegui", "node_id", $tree->readRootId());
85 }
86
87 public function updateTree(\ilObjSkillTree $tree_obj, string $title, string $description): void
88 {
89 if (!$this->tree_access_manager->hasEditTreeSettingsPermission()) {
90 $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
91 }
92 $tree_obj->setTitle($title);
93 $tree_obj->setDescription($description);
94 $tree_obj->update();
95 }
96
97 public function deleteTree(\ilObjSkillTree $tree_obj): void
98 {
99 if (!$this->management_access_manager->hasCreateTreePermission()) {
100 $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
101 }
102 $tree_obj->delete();
103 }
104
105 public function getTrees(): \Generator
106 {
107 foreach ($this->repository_tree->getChilds($this->skmg_ref_id) as $c) {
108 if ($c["type"] == "skee") {
109 yield new \ilObjSkillTree($c["child"]);
110 }
111 }
112 }
113
114 public function getTree(int $tree_id): \ilObjSkillTree
115 {
116 $ref_id = (int) current(\ilObject::_getAllReferences($tree_id));
117 return new \ilObjSkillTree($ref_id);
118 }
119
123 public function getSkillManagementRefId(): int
124 {
125 return $this->skmg_ref_id;
126 }
127}
Request wrapper for guis in skill administration.
SkillManagementAccess $management_access_manager
__construct(int $skmg_ref_id, \ilTree $repository_tree, SkillTreeFactory $tree_factory)
deleteTree(\ilObjSkillTree $tree_obj)
getSkillManagementRefId()
Get ref id of skill management administration node.
updateTree(\ilObjSkillTree $tree_obj, string $title, string $description)
createTree(string $title, string $description)
error(string $a_errmsg)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
delete()
delete object or referenced object (in the case of a referenced object, object data is only deleted i...
static _getAllReferences(int $id)
get all reference ids for object ID
setTitle(string $title)
setDescription(string $desc)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$c
Definition: cli.php:38
global $DIC
Definition: feed.php:28
$ref_id
Definition: ltiauth.php:67
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...