ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilBadgeTableGUI.php
Go to the documentation of this file.
1 <?php
2 
21 
27 {
28  protected string $parent_type;
29  protected array $filter = [];
30  private readonly Tile $tile;
31  private readonly UIServices $ui;
32 
33  public function __construct(
34  object $a_parent_obj,
35  string $a_parent_cmd = "",
36  int $a_parent_obj_id = 0,
37  protected bool $has_write = false
38  ) {
39  global $DIC;
40 
41  $this->ctrl = $DIC->ctrl();
42  $this->lng = $DIC->language();
43  $this->ui = $DIC->ui();
44  $this->tile = new Tile($DIC);
45  $ilCtrl = $DIC->ctrl();
46  $lng = $DIC->language();
47 
48  $this->setId("bdgbdg");
49  $this->parent_type = ilObject::_lookupType($a_parent_obj_id);
50 
51  parent::__construct($a_parent_obj, $a_parent_cmd);
52 
53  $this->setLimit(9999);
54 
55  $this->setTitle($lng->txt("obj_bdga"));
56 
57  if ($this->has_write) {
58  $this->addColumn("", "", 1);
59  }
60 
61  $this->addColumn($lng->txt("title"), "title");
62  $this->addColumn($lng->txt("type"), "type");
63  $this->addColumn($lng->txt("active"), "active");
64 
65  if ($this->has_write) {
66  $this->addColumn($lng->txt("action"), "");
67 
68  $lng->loadLanguageModule("content");
69  $this->addMultiCommand("copyBadges", $lng->txt("cont_copy_to_clipboard"));
70  $this->addMultiCommand("activateBadges", $lng->txt("activate"));
71  $this->addMultiCommand("deactivateBadges", $lng->txt("deactivate"));
72  $this->addMultiCommand("confirmDeleteBadges", $lng->txt("delete"));
73  $this->setSelectAllCheckbox("id");
74  }
75 
76  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
77  $this->setRowTemplate("tpl.badge_row.html", "Services/Badge");
78  $this->setDefaultOrderField("title");
79 
80  $this->setFilterCommand("applyBadgeFilter");
81  $this->setResetCommand("resetBadgeFilter");
82 
83  $this->initFilter();
84 
85  $this->getItems($a_parent_obj_id);
86  }
87 
88  public function initFilter(): void
89  {
90  $lng = $this->lng;
91 
92  $title = $this->addFilterItemByMetaType("title", self::FILTER_TEXT, false, $lng->txt("title"));
93  $this->filter["title"] = $title->getValue();
94 
96  $valid_types = $handler->getAvailableTypesForObjType($this->parent_type);
97  if ($valid_types &&
98  count($valid_types) > 1) {
99  $lng->loadLanguageModule("search");
100 
101  $options = array("" => $lng->txt("search_any"));
102  foreach ($valid_types as $id => $type) {
103  $options[$id] = ilBadge::getExtendedTypeCaption($type);
104  }
105  asort($options);
106 
107  $type = $this->addFilterItemByMetaType("type", self::FILTER_SELECT, false, $lng->txt("type"));
108  $type->setOptions($options);
109  $this->filter["type"] = $type->getValue();
110  }
111  }
112 
113  public function getItems(int $a_parent_obj_id): void
114  {
115  $data = array();
116 
117  foreach (ilBadge::getInstancesByParentId($a_parent_obj_id, $this->filter) as $badge) {
118  $data[] = array(
119  "id" => $badge->getId(),
120  "title" => $badge->getTitle(),
121  "active" => $badge->isActive(),
122  "type" => ($this->parent_type !== "bdga")
123  ? ilBadge::getExtendedTypeCaption($badge->getTypeInstance())
124  : $badge->getTypeInstance()->getCaption(),
125  "manual" => (!$badge->getTypeInstance() instanceof ilBadgeAuto),
126  "renderer" => fn() => $this->tile->asTitle($this->tile->modalContent($badge)),
127  );
128  }
129 
130  $this->setData($data);
131  }
132 
133  protected function fillRow(array $a_set): void
134  {
135  $lng = $this->lng;
136  $ilCtrl = $this->ctrl;
137 
138  if ($this->has_write) {
139  $this->tpl->setVariable("VAL_ID", $a_set["id"]);
140  }
141 
142  $this->tpl->setVariable("PREVIEW", $this->ui->renderer()->render($a_set["renderer"]()));
143  $this->tpl->setVariable("TXT_TYPE", $a_set["type"]);
144  $this->tpl->setVariable("TXT_ACTIVE", $a_set["active"]
145  ? $lng->txt("yes")
146  : $lng->txt("no"));
147 
148  if ($this->has_write) {
149  $buttons = [];
150 
151  if ($a_set["manual"] && $a_set["active"]) {
152  $ilCtrl->setParameter($this->getParentObject(), "bid", $a_set["id"]);
153  $ilCtrl->setParameter($this->getParentObject(), "tgt", "bdgl");
154  $url = $ilCtrl->getLinkTarget($this->getParentObject(), "awardBadgeUserSelection");
155  $ilCtrl->setParameter($this->getParentObject(), "bid", "");
156  $ilCtrl->setParameter($this->getParentObject(), "tgt", "");
157 
158  $buttons[] = $this->ui->factory()->button()->shy($lng->txt("badge_award_badge"), $url);
159  }
160 
161  $ilCtrl->setParameter($this->getParentObject(), "bid", $a_set["id"]);
162  $url = $ilCtrl->getLinkTarget($this->getParentObject(), "editBadge");
163  $ilCtrl->setParameter($this->getParentObject(), "bid", "");
164 
165  $buttons[] = $this->ui->factory()->button()->shy($lng->txt("edit"), $url);
166  $actions = $this->ui->factory()->dropdown()->standard($buttons)->withLabel($lng->txt("actions"));
167 
168  $this->tpl->setVariable("ACTIONS", $this->ui->renderer()->render($actions));
169  }
170  }
171 }
setData(array $a_data)
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)
setResetCommand(string $a_val, string $a_caption="")
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
loadLanguageModule(string $a_module)
Load language module.
ilLanguage $lng
setId(string $a_val)
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Provides fluid interface to RBAC services.
Definition: UIServices.php:23
addFilterItemByMetaType(string $id, int $type=self::FILTER_TEXT, bool $a_optional=false, string $caption="")
Add filter by standard type.
__construct(VocabulariesInterface $vocabularies)
static getExtendedTypeCaption(ilBadgeType $a_type)
setDefaultOrderField(string $a_defaultorderfield)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setFilterCommand(string $a_val, string $a_caption="")
static getInstancesByParentId(int $a_parent_id, array $a_filter=null)
readonly UIServices $ui
$url
Definition: ltiregstart.php:35
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
TableGUI class for badge listing.
setLimit(int $a_limit=0, int $a_default_limit=0)
__construct(object $a_parent_obj, string $a_parent_cmd="", int $a_parent_obj_id=0, protected bool $has_write=false)
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)
getItems(int $a_parent_obj_id)
filter(string $filter_id, $class_path, string $cmd, bool $activated=true, bool $expanded=true)
static _lookupType(int $id, bool $reference=false)
addMultiCommand(string $a_cmd, string $a_text)
$handler
Definition: index.php:18