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