ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilSkillLevelTableGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
29 {
31  protected int $skill_id = 0;
32  protected ilBasicSkill $skill;
33  protected int $tref_id = 0;
34  protected bool $in_use = false;
35  protected bool $manage_perm = false;
36  protected \ILIAS\UI\Factory $ui_fac;
37  protected \ILIAS\UI\Renderer $ui_ren;
38  protected \ILIAS\Skill\Resource\SkillResourcesManager $resource_manager;
39 
40  public function __construct(
41  int $a_skill_id,
42  $a_parent_obj,
43  string $a_parent_cmd,
44  int $a_tref_id = 0,
45  bool $a_in_use = false,
46  bool $a_manage_perm = false
47  ) {
48  global $DIC;
49 
50  $this->ctrl = $DIC->ctrl();
51  $this->lng = $DIC->language();
52  $this->access = $DIC->access();
53  $ilCtrl = $DIC->ctrl();
54  $lng = $DIC->language();
55  $this->ui_fac = $DIC->ui()->factory();
56  $this->ui_ren = $DIC->ui()->renderer();
57  $this->resource_manager = $DIC->skills()->internal()->manager()->getResourceManager();
58 
59  $this->skill_id = $a_skill_id;
60  $this->skill = new ilBasicSkill($a_skill_id);
61  $this->tref_id = $a_tref_id;
62  $this->in_use = $a_in_use;
63  $this->manage_perm = $a_manage_perm;
64 
65  parent::__construct($a_parent_obj, $a_parent_cmd);
66  $this->setLimit(9999);
67  $this->setData($this->getSkillLevelData());
68  $this->setTitle($lng->txt("skmg_skill_levels"));
69  if ($this->tref_id == 0) {
70  $this->setDescription($lng->txt("skmg_from_lower_to_higher_levels"));
71  }
72 
73  if ($this->tref_id == 0 && !$this->in_use) {
74  if ($this->manage_perm) {
75  $this->addColumn("", "", "1", true);
76  }
77  $this->addColumn($this->lng->txt("skmg_nr"));
78  }
79  $this->addColumn($this->lng->txt("title"));
80  $this->addColumn($this->lng->txt("description"));
81  $this->addColumn($this->lng->txt("skmg_suggested"));
82  $this->addColumn($this->lng->txt("skmg_lp_triggers_level"));
83  if ($this->manage_perm) {
84  $this->addColumn($this->lng->txt("actions"));
85  }
86  $this->setDefaultOrderField("nr");
87  $this->setDefaultOrderDirection("asc");
88 
89  $this->setEnableHeader(true);
90  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
91  $this->setRowTemplate("tpl.skill_level_row.html", "Services/Skill");
92  $this->setEnableTitle(true);
93 
94  if ($this->tref_id == 0 && !$this->in_use && $this->manage_perm) {
95  $this->addMultiCommand("confirmLevelDeletion", $lng->txt("delete"));
96  if (count($this->getData()) > 0) {
97  $this->addCommandButton("updateLevelOrder", $lng->txt("skmg_update_order"));
98  }
99  }
100  }
101 
105  public function numericOrdering(string $a_field): bool
106  {
107  if ($a_field == "nr") {
108  return true;
109  }
110  return false;
111  }
112 
113  public function getSkillLevelData(): array
114  {
115  $levels = $this->skill->getLevelData();
116 
117  // add ressource data
118  $res = [];
119  foreach ($this->resource_manager->getResources($this->skill_id, $this->tref_id) as $level_id => $item) {
120  $res[$level_id] = $item;
121  }
122 
123  foreach ($levels as $idx => $item) {
124  if (isset($res[$item["id"]])) {
125  $levels[$idx]["ressources"] = $res[$item["id"]];
126  }
127  }
128 
129  return $levels;
130  }
131 
132  protected function fillRow(array $a_set): void
133  {
134  $lng = $this->lng;
135  $ilCtrl = $this->ctrl;
136 
137  if ($this->tref_id == 0 && !$this->in_use) {
138  if ($this->manage_perm) {
139  $this->tpl->setCurrentBlock("cb");
140  $this->tpl->setVariable("CB_ID", $a_set["id"]);
141  $this->tpl->parseCurrentBlock();
142  }
143 
144  $this->tpl->setCurrentBlock("nr");
145  $this->tpl->setVariable("ORD_ID", $a_set["id"]);
146  $this->tpl->setVariable("VAL_NR", ((int) $a_set["nr"]) * 10);
147  if (!$this->manage_perm) {
148  $this->tpl->touchBlock("disabled");
149  }
150  $this->tpl->parseCurrentBlock();
151  }
152 
153  $this->tpl->setCurrentBlock("cmd");
154  if ($this->manage_perm) {
155  $this->tpl->setVariable("TXT_CMD", $lng->txt("edit"));
156  }
157  $ilCtrl->setParameter($this->parent_obj, "level_id", $a_set["id"]);
158  if ($this->tref_id == 0) {
159  $this->tpl->setVariable(
160  "HREF_CMD",
161  $ilCtrl->getLinkTarget($this->parent_obj, "editLevel")
162  );
163  } else {
164  $this->tpl->setVariable(
165  "HREF_CMD",
166  $ilCtrl->getLinkTarget($this->parent_obj, "showLevelResources")
167  );
168  }
169  $this->tpl->parseCurrentBlock();
170 
171  $this->tpl->setVariable("TXT_TITLE", $a_set["title"]);
172  $this->tpl->setVariable("TXT_DESCRIPTION", $a_set["description"]);
173  if (isset($a_set["ressources"]) && is_array($a_set["ressources"])) {
174  foreach ($a_set["ressources"] as $ressource) {
175  $robj_id = ilObject::_lookupObjId($ressource->getRepoRefId());
176  $robj_type = ilObject::_lookupType($robj_id);
177  $robj_icon = $this->ui_fac->symbol()->icon()->standard(
178  $robj_type,
179  $this->lng->txt("icon") . " " . $this->lng->txt($robj_type),
180  "medium"
181  );
182  $robj_title = ilObject::_lookupTitle($robj_id);
183  $robj_link = ilLink::_getStaticLink($ressource->getRepoRefId());
184 
185  if ($ressource->getImparting()) {
186  $this->tpl->setCurrentBlock("ressource_sugg");
187  $this->tpl->setVariable("RSRC_IMG", $this->ui_ren->render($robj_icon));
188  $this->tpl->setVariable("RSRC_TITLE", $robj_title);
189  $this->tpl->setVariable("RSRC_URL", $robj_link);
190  $this->tpl->parseCurrentBlock();
191  }
192 
193  if ($ressource->getTrigger()) {
194  $this->tpl->setCurrentBlock("ressource_trigg");
195  $this->tpl->setVariable("RSRC_IMG", $this->ui_ren->render($robj_icon));
196  $this->tpl->setVariable("RSRC_TITLE", $robj_title);
197  $this->tpl->setVariable("RSRC_URL", $robj_link);
198  $this->tpl->parseCurrentBlock();
199  }
200  }
201  }
202  }
203 }
setData(array $a_data)
$res
Definition: ltiservices.php:69
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
setFormAction(string $a_form_action, bool $a_multipart=false)
setEnableTitle(bool $a_enabletitle)
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
setDescription(string $a_val)
ilLanguage $lng
__construct(int $a_skill_id, $a_parent_obj, string $a_parent_cmd, int $a_tref_id=0, bool $a_in_use=false, bool $a_manage_perm=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupObjId(int $ref_id)
global $DIC
Definition: feed.php:28
__construct(VocabulariesInterface $vocabularies)
static _lookupTitle(int $obj_id)
setDefaultOrderField(string $a_defaultorderfield)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setDefaultOrderDirection(string $a_defaultorderdirection)
ILIAS Skill Resource SkillResourcesManager $resource_manager
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
setLimit(int $a_limit=0, int $a_default_limit=0)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
setParameter(object $a_gui_obj, string $a_parameter, $a_value)
static _lookupType(int $id, bool $reference=false)
Basic Skill.
addMultiCommand(string $a_cmd, string $a_text)
setEnableHeader(bool $a_enableheader)