ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.SkillTreeManager.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Skill\Tree;
22
26
32{
33 protected \ilCtrl $ctrl;
34 protected \ilErrorHandling $error;
35 protected \ilLanguage $lng;
36 protected int $skmg_ref_id = 0;
37 protected \ilTree $repository_tree;
42 protected int $requested_ref_id = 0;
43
44 public function __construct(
45 int $skmg_ref_id,
48 ) {
49 global $DIC;
50
51 $this->ctrl = $DIC->ctrl();
52 $this->error = $DIC["ilErr"];
53 $this->lng = $DIC->language();
54 $this->skmg_ref_id = $skmg_ref_id;
55 $this->repository_tree = $repository_tree;
56 $this->tree_factory = $tree_factory;
57 $this->admin_gui_request = $DIC->skills()->internal()->gui()->admin_request();
58
59 // TODO: Find a different way for the ref_id, because this is no GUI class
60 $this->requested_ref_id = $this->admin_gui_request->getRefId();
61
62 $this->tree_access_manager = $DIC->skills()->internal()->manager()->getTreeAccessManager($this->requested_ref_id);
63 $this->management_access_manager = $DIC->skills()->internal()->manager()->getManagementAccessManager($this->requested_ref_id);
64 }
65
66 public function createTree(string $title, string $description): void
67 {
68 if (!$this->management_access_manager->hasCreateTreePermission()) {
69 $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
70 }
71 $tree_obj = new \ilObjSkillTree();
72 $tree_obj->setTitle($title);
73 $tree_obj->setDescription($description);
74 $tree_obj->create();
75 $tree_obj->createReference();
76 $tree_obj->putInTree($this->skmg_ref_id);
77 $tree_obj->setPermissions($this->skmg_ref_id);
78
79 $tree = $this->tree_factory->getTreeById($tree_obj->getId());
80 $root_node = new \ilSkillRoot();
81 $root_node->setTitle("Skill Tree Root Node");
82 $root_node->create();
83 $tree->addTree($tree_obj->getId(), $root_node->getId());
84 $this->ctrl->setParameterByClass("ilobjskilltreegui", "ref_id", $tree_obj->getRefId());
85 $this->ctrl->setParameterByClass("ilobjskilltreegui", "node_id", $tree->readRootId());
86 }
87
88 public function updateTree(\ilObjSkillTree $tree_obj, string $title, string $description): void
89 {
90 if (!$this->tree_access_manager->hasEditTreeSettingsPermission()) {
91 $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
92 }
93 $tree_obj->setTitle($title);
94 $tree_obj->setDescription($description);
95 $tree_obj->update();
96 }
97
98 public function deleteTree(\ilObjSkillTree $tree_obj): void
99 {
100 if (!$this->management_access_manager->hasCreateTreePermission()) {
101 $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
102 }
103 $tree_obj->delete();
104 }
105
106 public function getTrees(): \Generator
107 {
108 foreach ($this->repository_tree->getChilds($this->skmg_ref_id) as $c) {
109 if ($c["type"] == "skee") {
110 yield new \ilObjSkillTree((int) $c["child"]);
111 }
112 }
113 }
114
115 public function getTree(int $tree_id): \ilObjSkillTree
116 {
117 $ref_id = (int) current(\ilObject::_getAllReferences($tree_id));
118 return new \ilObjSkillTree($ref_id);
119 }
120
124 public function getSkillManagementRefId(): int
125 {
126 return $this->skmg_ref_id;
127 }
128}
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)
Skill tree object in skill management (repository object class)
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 $description)
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
$c
Definition: deliver.php:25
$ref_id
Definition: ltiauth.php:66
global $DIC
Definition: shib_login.php:26