ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.UsagesUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 namespace ILIAS\Skill\Usage;
23 
25 use ILIAS\UI;
26 
30 class UsagesUI
31 {
32  protected \ilLanguage $lng;
33  protected UI\Factory $ui_fac;
34  protected UI\Renderer $ui_ren;
37  protected \ilSkillTreeRepository $tree_repo;
38  protected int $skill_id = 0;
39  protected int $tref_id = 0;
40  protected array $usage = [];
41  protected string $mode = "";
42 
43  public function __construct(
44  string $cskill_id,
45  array $usage,
46  string $mode = ""
47  ) {
48  global $DIC;
49 
50  $this->lng = $DIC->language();
51  $this->ui_fac = $DIC->ui()->factory();
52  $this->ui_ren = $DIC->ui()->renderer();
53  $this->tree_manager = $DIC->skills()->internal()->manager()->getTreeManager();
54  $this->usage_manager = $DIC->skills()->internal()->manager()->getUsageManager();
55  $this->tree_repo = $DIC->skills()->internal()->repo()->getTreeRepo();
56 
57  $id_parts = explode(":", $cskill_id);
58  $this->skill_id = (int) $id_parts[0];
59  $this->tref_id = (int) $id_parts[1];
60  $this->usage = $usage;
61  $this->mode = $mode;
62  }
63 
64  public function render(): string
65  {
66  $tree = $this->tree_repo->getTreeForNodeId($this->skill_id);
67  if ($this->mode === "tree") {
68  $tree_obj = $this->tree_manager->getTree($tree->getTreeId());
69  $title = $tree_obj->getTitle() . " > " . \ilSkillTreeNode::_lookupTitle($this->skill_id, $this->tref_id);
70  } else {
71  $title = \ilSkillTreeNode::_lookupTitle($this->skill_id, $this->tref_id);
72  }
73 
74  //$description = $tree->getSkillTreePathAsString($skill_id, $tref_id);
75 
76  $listing = $this->getUsagesListing();
77 
78  $panel = $this->ui_fac->panel()->standard($title, $listing);
79 
80  return $this->ui_ren->render($panel);
81  }
82 
83  protected function getUsagesListing(): UI\Component\Listing\CharacteristicValue\Text
84  {
85  $types = [];
86  foreach ($this->usage as $type => $type_usages) {
87  $types[$this->usage_manager->getTypeInfoString($type)] = count($type_usages) . " " .
88  $this->usage_manager->getObjTypeString($type);
89  }
90 
91  $listing = $this->ui_fac->listing()->characteristicValue()->text($types);
92 
93  return $listing;
94  }
95 }
SkillUsageManager $usage_manager
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupTitle(int $a_obj_id, int $a_tref_id=0)
Tree SkillTreeManager $tree_manager
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:25
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilSkillTreeRepository $tree_repo
__construct(string $cskill_id, array $usage, string $mode="")