ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilBadgeTableGUI.php
Go to the documentation of this file.
1 <?php
2 
24 {
25  protected bool $has_write;
26  protected string $parent_type;
27  protected array $filter = [];
28 
29  public function __construct(
30  object $a_parent_obj,
31  string $a_parent_cmd = "",
32  int $a_parent_obj_id = 0,
33  bool $a_has_write = false
34  ) {
35  global $DIC;
36 
37  $this->ctrl = $DIC->ctrl();
38  $this->lng = $DIC->language();
39  $ilCtrl = $DIC->ctrl();
40  $lng = $DIC->language();
41 
42  $this->setId("bdgbdg");
43  $this->has_write = $a_has_write;
44  $this->parent_type = ilObject::_lookupType($a_parent_obj_id);
45 
46  parent::__construct($a_parent_obj, $a_parent_cmd);
47 
48  $this->setLimit(9999);
49 
50  $this->setTitle($lng->txt("obj_bdga"));
51 
52  if ($this->has_write) {
53  $this->addColumn("", "", 1);
54  }
55 
56  $this->addColumn($lng->txt("title"), "title");
57  $this->addColumn($lng->txt("type"), "type");
58  $this->addColumn($lng->txt("active"), "active");
59 
60  if ($this->has_write) {
61  $this->addColumn($lng->txt("action"), "");
62 
63  $lng->loadLanguageModule("content");
64  $this->addMultiCommand("copyBadges", $lng->txt("cont_copy_to_clipboard"));
65  $this->addMultiCommand("activateBadges", $lng->txt("activate"));
66  $this->addMultiCommand("deactivateBadges", $lng->txt("deactivate"));
67  $this->addMultiCommand("confirmDeleteBadges", $lng->txt("delete"));
68  $this->setSelectAllCheckbox("id");
69  }
70 
71  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
72  $this->setRowTemplate("tpl.badge_row.html", "Services/Badge");
73  $this->setDefaultOrderField("title");
74 
75  $this->setFilterCommand("applyBadgeFilter");
76  $this->setResetCommand("resetBadgeFilter");
77 
78  $this->initFilter();
79 
80  $this->getItems($a_parent_obj_id);
81  }
82 
83  public function initFilter(): void
84  {
85  $lng = $this->lng;
86 
87  $title = $this->addFilterItemByMetaType("title", self::FILTER_TEXT, false, $lng->txt("title"));
88  $this->filter["title"] = $title->getValue();
89 
90  $handler = ilBadgeHandler::getInstance();
91  $valid_types = $handler->getAvailableTypesForObjType($this->parent_type);
92  if ($valid_types &&
93  count($valid_types) > 1) {
94  $lng->loadLanguageModule("search");
95 
96  $options = array("" => $lng->txt("search_any"));
97  foreach ($valid_types as $id => $type) {
99  }
100  asort($options);
101 
102  $type = $this->addFilterItemByMetaType("type", self::FILTER_SELECT, false, $lng->txt("type"));
103  $type->setOptions($options);
104  $this->filter["type"] = $type->getValue();
105  }
106  }
107 
108  public function getItems(int $a_parent_obj_id): void
109  {
110  $data = array();
111 
112  foreach (ilBadge::getInstancesByParentId($a_parent_obj_id, $this->filter) as $badge) {
113  $data[] = array(
114  "id" => $badge->getId(),
115  "title" => $badge->getTitle(),
116  "active" => $badge->isActive(),
117  "type" => ($this->parent_type !== "bdga")
118  ? ilBadge::getExtendedTypeCaption($badge->getTypeInstance())
119  : $badge->getTypeInstance()->getCaption(),
120  "manual" => (!$badge->getTypeInstance() instanceof ilBadgeAuto),
121  "renderer" => new ilBadgeRenderer(null, $badge)
122  );
123  }
124 
125  $this->setData($data);
126  }
127 
128  protected function fillRow(array $a_set): void
129  {
130  $lng = $this->lng;
131  $ilCtrl = $this->ctrl;
132 
133  if ($this->has_write) {
134  $this->tpl->setVariable("VAL_ID", $a_set["id"]);
135  }
136 
137  $this->tpl->setVariable("PREVIEW", $a_set["renderer"]->getHTML());
138  $this->tpl->setVariable("TXT_TITLE", $a_set["title"]);
139  $this->tpl->setVariable("TXT_TYPE", $a_set["type"]);
140  $this->tpl->setVariable("TXT_ACTIVE", $a_set["active"]
141  ? $lng->txt("yes")
142  : $lng->txt("no"));
143 
144  if ($this->has_write) {
145  $actions = new ilAdvancedSelectionListGUI();
146  $actions->setListTitle($lng->txt("actions"));
147 
148  if ($a_set["manual"] &&
149  $a_set["active"]) {
150  $ilCtrl->setParameter($this->getParentObject(), "bid", $a_set["id"]);
151  $ilCtrl->setParameter($this->getParentObject(), "tgt", "bdgl");
152  $url = $ilCtrl->getLinkTarget($this->getParentObject(), "awardBadgeUserSelection");
153  $ilCtrl->setParameter($this->getParentObject(), "bid", "");
154  $ilCtrl->setParameter($this->getParentObject(), "tgt", "");
155  $actions->addItem($lng->txt("badge_award_badge"), "", $url);
156  }
157 
158  $ilCtrl->setParameter($this->getParentObject(), "bid", $a_set["id"]);
159  $url = $ilCtrl->getLinkTarget($this->getParentObject(), "editBadge");
160  $ilCtrl->setParameter($this->getParentObject(), "bid", "");
161  $actions->addItem($lng->txt("edit"), "", $url);
162 
163  $this->tpl->setVariable("ACTIONS", $actions->getHTML());
164  }
165  }
166 }
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)
$type
setResetCommand(string $a_val, string $a_caption="")
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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...
getHTML()
Get HTML.
addFilterItemByMetaType(string $id, int $type=self::FILTER_TEXT, bool $a_optional=false, string $caption="")
Add filter by standard type.
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)
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
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)
$url
getItems(int $a_parent_obj_id)
static _lookupType(int $id, bool $reference=false)
addMultiCommand(string $a_cmd, string $a_text)
__construct(object $a_parent_obj, string $a_parent_cmd="", int $a_parent_obj_id=0, bool $a_has_write=false)