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